• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 
12 #include <Eigen/CXX11/Tensor>
13 
14 
test_float_rounding()15 static void test_float_rounding()
16 {
17   Tensor<float, 2> ftensor(20,30);
18   ftensor = ftensor.random() * 100.f;
19 
20   Tensor<float, 2> result = ftensor.round();
21 
22   for (int i = 0; i < 20; ++i) {
23     for (int j = 0; j < 30; ++j) {
24       VERIFY_IS_EQUAL(result(i,j), numext::round(ftensor(i,j)));
25     }
26   }
27 }
28 
test_float_flooring()29 static void test_float_flooring()
30 {
31   Tensor<float, 2> ftensor(20,30);
32   ftensor = ftensor.random() * 100.f;
33 
34   Tensor<float, 2> result = ftensor.floor();
35 
36   for (int i = 0; i < 20; ++i) {
37     for (int j = 0; j < 30; ++j) {
38       VERIFY_IS_EQUAL(result(i,j), numext::floor(ftensor(i,j)));
39     }
40   }
41 }
42 
test_float_ceiling()43 static void test_float_ceiling()
44 {
45   Tensor<float, 2> ftensor(20,30);
46   ftensor = ftensor.random() * 100.f;
47 
48   Tensor<float, 2> result = ftensor.ceil();
49 
50   for (int i = 0; i < 20; ++i) {
51     for (int j = 0; j < 30; ++j) {
52       VERIFY_IS_EQUAL(result(i,j), numext::ceil(ftensor(i,j)));
53     }
54   }
55 }
56 
test_cxx11_tensor_roundings()57 void test_cxx11_tensor_roundings()
58 {
59    CALL_SUBTEST(test_float_rounding());
60    CALL_SUBTEST(test_float_ceiling());
61    CALL_SUBTEST(test_float_flooring());
62 }
63