gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_of_const_values.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) 2014 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_assign
()
18
{
19
float
data1[6];
20
TensorMap<Tensor<const float, 2>
>
mat1
(data1, 2, 3);
21
float
data2[6];
22
const
TensorMap<Tensor<float, 2>
> mat2(data2, 2, 3);
23
24
for
(
int
i
= 0;
i
< 6; ++
i
) {
25
data1[
i
] =
i
;
26
data2[
i
] = -
i
;
27
}
28
29
Tensor<float, 2>
rslt1;
30
rslt1 =
mat1
;
31
Tensor<float, 2>
rslt2;
32
rslt2 = mat2;
33
34
Tensor<float, 2>
rslt3 =
mat1
;
35
Tensor<float, 2>
rslt4 = mat2;
36
37
Tensor<float, 2>
rslt5(
mat1
);
38
Tensor<float, 2>
rslt6(mat2);
39
40
for
(
int
i
= 0;
i
< 2; ++
i
) {
41
for
(
int
j
= 0;
j
< 3; ++
j
) {
42
VERIFY_IS_APPROX
(rslt1(
i
,
j
),
static_cast<
float
>
(
i
+ 2*
j
));
43
VERIFY_IS_APPROX
(rslt2(
i
,
j
),
static_cast<
float
>
(-
i
- 2*
j
));
44
VERIFY_IS_APPROX
(rslt3(
i
,
j
),
static_cast<
float
>
(
i
+ 2*
j
));
45
VERIFY_IS_APPROX
(rslt4(
i
,
j
),
static_cast<
float
>
(-
i
- 2*
j
));
46
VERIFY_IS_APPROX
(rslt5(
i
,
j
),
static_cast<
float
>
(
i
+ 2*
j
));
47
VERIFY_IS_APPROX
(rslt6(
i
,
j
),
static_cast<
float
>
(-
i
- 2*
j
));
48
}
49
}
50
}
51
52
53
static
void
test_plus
()
54
{
55
float
data1[6];
56
TensorMap<Tensor<const float, 2>
>
mat1
(data1, 2, 3);
57
float
data2[6];
58
TensorMap<Tensor<float, 2>
> mat2(data2, 2, 3);
59
60
for
(
int
i
= 0;
i
< 6; ++
i
) {
61
data1[
i
] =
i
;
62
data2[
i
] = -
i
;
63
}
64
65
Tensor<float, 2>
sum1;
66
sum1 =
mat1
+ mat2;
67
Tensor<float, 2>
sum2;
68
sum2 = mat2 +
mat1
;
69
70
for
(
int
i
= 0;
i
< 2; ++
i
) {
71
for
(
int
j
= 0;
j
< 3; ++
j
) {
72
VERIFY_IS_APPROX
(sum1(
i
,
j
), 0.0
f
);
73
VERIFY_IS_APPROX
(sum2(
i
,
j
), 0.0
f
);
74
}
75
}
76
}
77
78
79
static
void
test_plus_equal
()
80
{
81
float
data1[6];
82
TensorMap<Tensor<const float, 2>
>
mat1
(data1, 2, 3);
83
float
data2[6];
84
TensorMap<Tensor<float, 2>
> mat2(data2, 2, 3);
85
86
for
(
int
i
= 0;
i
< 6; ++
i
) {
87
data1[
i
] =
i
;
88
data2[
i
] = -
i
;
89
}
90
mat2 +=
mat1
;
91
92
for
(
int
i
= 0;
i
< 2; ++
i
) {
93
for
(
int
j
= 0;
j
< 3; ++
j
) {
94
VERIFY_IS_APPROX
(mat2(
i
,
j
), 0.0
f
);
95
}
96
}
97
}
98
99
100
EIGEN_DECLARE_TEST
(cxx11_tensor_of_const_values)
101
{
102
CALL_SUBTEST
(
test_assign
());
103
CALL_SUBTEST
(
test_plus
());
104
CALL_SUBTEST
(
test_plus_equal
());
105
}
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
mat1
MatrixXd mat1(size, size)
Eigen::RowMajor
@ RowMajor
Definition:
Constants.h:321
j
std::ptrdiff_t j
Definition:
tut_arithmetic_redux_minmax.cpp:2
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_of_const_values)
Definition:
cxx11_tensor_of_const_values.cpp:100
test_plus_equal
static void test_plus_equal()
Definition:
cxx11_tensor_of_const_values.cpp:79
test_assign
static void test_assign()
Definition:
cxx11_tensor_of_const_values.cpp:17
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition:
TensorForwardDeclarations.h:52
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
test_plus
static void test_plus()
Definition:
cxx11_tensor_of_const_values.cpp:53
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 Sat Nov 16 2024 04:02:09