gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_sugar.cpp
Go to the documentation of this file.
1
#include "
main.h
"
2
3
#include <Eigen/CXX11/Tensor>
4
5
using
Eigen::Tensor
;
6
using
Eigen::RowMajor
;
7
8
static
void
test_comparison_sugar
() {
9
// we already trust comparisons between tensors, we're simply checking that
10
// the sugared versions are doing the same thing
11
Tensor<int, 3>
t
(6, 7, 5);
12
13
t.
setRandom
();
14
// make sure we have at least one value == 0
15
t
(0,0,0) = 0;
16
17
Tensor<bool,0>
b
;
18
19
#define TEST_TENSOR_EQUAL(e1, e2) \
20
b = ((e1) == (e2)).all(); \
21
VERIFY(b())
22
23
#define TEST_OP(op) TEST_TENSOR_EQUAL(t op 0, t op t.constant(0))
24
25
TEST_OP
(==);
26
TEST_OP
(!=);
27
TEST_OP
(<=);
28
TEST_OP
(>=);
29
TEST_OP
(<);
30
TEST_OP
(>);
31
#undef TEST_OP
32
#undef TEST_TENSOR_EQUAL
33
}
34
35
36
static
void
test_scalar_sugar_add_mul
() {
37
Tensor<float, 3>
A
(6, 7, 5);
38
Tensor<float, 3>
B
(6, 7, 5);
39
A.
setRandom
();
40
B.
setRandom
();
41
42
const
float
alpha
= 0.43f;
43
const
float
beta = 0.21f;
44
const
float
gamma = 0.14f;
45
46
Tensor<float, 3>
R
= A.constant(gamma) + A * A.constant(alpha) + B * B.constant(beta);
47
Tensor<float, 3>
S
= A * alpha + B * beta + gamma;
48
Tensor<float, 3>
T
= gamma + alpha * A + beta *
B
;
49
50
for
(
int
i
= 0;
i
< 6*7*5; ++
i
) {
51
VERIFY_IS_APPROX
(
R
(
i
),
S
(
i
));
52
VERIFY_IS_APPROX
(
R
(
i
),
T
(
i
));
53
}
54
}
55
56
static
void
test_scalar_sugar_sub_div
() {
57
Tensor<float, 3>
A
(6, 7, 5);
58
Tensor<float, 3>
B
(6, 7, 5);
59
A.
setRandom
();
60
B.
setRandom
();
61
62
const
float
alpha
= 0.43f;
63
const
float
beta = 0.21f;
64
const
float
gamma = 0.14f;
65
const
float
delta
= 0.32f;
66
67
Tensor<float, 3>
R
= A.constant(gamma) - A / A.constant(alpha)
68
- B.constant(beta) / B - A.constant(delta);
69
Tensor<float, 3>
S
= gamma - A / alpha - beta / B -
delta
;
70
71
for
(
int
i
= 0;
i
< 6*7*5; ++
i
) {
72
VERIFY_IS_APPROX
(
R
(
i
),
S
(
i
));
73
}
74
}
75
76
EIGEN_DECLARE_TEST
(cxx11_tensor_sugar)
77
{
78
CALL_SUBTEST
(
test_comparison_sugar
());
79
CALL_SUBTEST
(
test_scalar_sugar_add_mul
());
80
CALL_SUBTEST
(
test_scalar_sugar_sub_div
());
81
}
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition:
bench_gemm.cpp:49
b
Scalar * b
Definition:
benchVecAdd.cpp:17
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_sugar)
Definition:
cxx11_tensor_sugar.cpp:76
R
Rot2 R(Rot2::fromAngle(0.1))
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setRandom
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition:
TensorBase.h:996
test_scalar_sugar_add_mul
static void test_scalar_sugar_add_mul()
Definition:
cxx11_tensor_sugar.cpp:36
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition:
bench_gemm.cpp:48
S
DiscreteKey S(1, 2)
main.h
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition:
PlanarManipulatorExample.py:45
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
test_comparison_sugar
static void test_comparison_sugar()
Definition:
cxx11_tensor_sugar.cpp:8
test_scalar_sugar_sub_div
static void test_scalar_sugar_sub_div()
Definition:
cxx11_tensor_sugar.cpp:56
T
Eigen::Triplet< double > T
Definition:
Tutorial_sparse_example.cpp:6
alpha
RealScalar alpha
Definition:
level1_cplx_impl.h:147
Eigen::Triplet< double >
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
Eigen::RowMajor
Definition:
Constants.h:321
TEST_OP
#define TEST_OP(op)
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
align_3::t
Point2 t(10, 10)
gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:08