cxx11_tensor_math.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) 2015 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 using Eigen::Tensor;
15 using Eigen::RowMajor;
16 
17 static void test_tanh()
18 {
20  vec1.setRandom();
21 
22  Tensor<float, 1> vec2 = vec1.tanh();
23 
24  for (int i = 0; i < 6; ++i) {
25  VERIFY_IS_APPROX(vec2(i), tanhf(vec1(i)));
26  }
27 }
28 
29 static void test_sigmoid()
30 {
32  vec1.setRandom();
33 
34  Tensor<float, 1> vec2 = vec1.sigmoid();
35 
36  for (int i = 0; i < 6; ++i) {
37  VERIFY_IS_APPROX(vec2(i), 1.0f / (1.0f + std::exp(-vec1(i))));
38  }
39 }
40 
41 
42 EIGEN_DECLARE_TEST(cxx11_tensor_math)
43 {
46 }
EIGEN_DECLARE_TEST(cxx11_tensor_math)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:996
static void test_tanh()
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
#define VERIFY_IS_APPROX(a, b)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RowVectorXd vec1(3)
#define CALL_SUBTEST(FUNC)
Definition: main.h:399
static void test_sigmoid()
The tensor class.
Definition: Tensor.h:63


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