cxx11_tensor_roundings.cpp
Go to the documentation of this file.
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 
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 
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 
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 
57 EIGEN_DECLARE_TEST(cxx11_tensor_roundings)
58 {
62 }
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
test_float_ceiling
static void test_float_ceiling()
Definition: cxx11_tensor_roundings.cpp:43
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
test_float_rounding
static void test_float_rounding()
Definition: cxx11_tensor_roundings.cpp:15
test_float_flooring
static void test_float_flooring()
Definition: cxx11_tensor_roundings.cpp:29
result
Values result
Definition: OdometryOptimize.cpp:8
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
round
double round(double x)
Definition: round.c:38
main.h
ceil
const EIGEN_DEVICE_FUNC CeilReturnType ceil() const
Definition: ArrayCwiseUnaryOps.h:495
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_roundings)
Definition: cxx11_tensor_roundings.cpp:57
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition: main.h:399


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:09