Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
gtsam
3rdparty
Eigen
unsupported
test
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
{
19
Tensor<float, 1>
vec1
(6);
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
{
31
Tensor<float, 1>
vec1
(6);
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.0
f
/ (1.0
f
+
std::exp
(-
vec1
(
i
))));
38
}
39
}
40
41
42
void
test_cxx11_tensor_math
()
43
{
44
CALL_SUBTEST
(
test_tanh
());
45
CALL_SUBTEST
(
test_sigmoid
());
46
}
exp
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Definition:
ArrayCwiseUnaryOps.h:88
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setRandom
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition:
TensorBase.h:850
test_tanh
static void test_tanh()
Definition:
cxx11_tensor_math.cpp:17
main.h
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition:
testExpression.cpp:211
vec1
RowVectorXd vec1(3)
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:342
Eigen::RowMajor
Definition:
Constants.h:322
test_cxx11_tensor_math
void test_cxx11_tensor_math()
Definition:
cxx11_tensor_math.cpp:42
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
test_sigmoid
static void test_sigmoid()
Definition:
cxx11_tensor_math.cpp:29
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:55