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_DEVICE_FUNC const FloorReturnType floor() const
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
static void test_float_flooring()
Values result
static void test_float_rounding()
EIGEN_DECLARE_TEST(cxx11_tensor_roundings)
#define CALL_SUBTEST(FUNC)
Definition: main.h:399
static void test_float_ceiling()
EIGEN_DEVICE_FUNC const CeilReturnType ceil() const
std::ptrdiff_t j
The tensor class.
Definition: Tensor.h:63
EIGEN_DEVICE_FUNC const RoundReturnType round() const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:08