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::Tensor
The tensor class.
Definition: Tensor.h:63
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_math)
Definition: cxx11_tensor_math.cpp:42
test_sigmoid
static void test_sigmoid()
Definition: cxx11_tensor_math.cpp:29
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
test_tanh
static void test_tanh()
Definition: cxx11_tensor_math.cpp:17
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
main.h
vec1
RowVectorXd vec1(3)
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition: main.h:399


gtsam
Author(s):
autogenerated on Mon Jul 1 2024 03:01:07