gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_dimension.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
16
17
static
void
test_dynamic_size
()
18
{
19
Eigen::DSizes<int, 3>
dimensions
(2,3,7);
20
21
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<0>(dimensions), 2);
22
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<1>(dimensions), 3);
23
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<2>(dimensions), 7);
24
VERIFY_IS_EQUAL
((
int
)dimensions.
TotalSize
(), 2*3*7);
25
VERIFY_IS_EQUAL
((
int
)dimensions[0], 2);
26
VERIFY_IS_EQUAL
((
int
)dimensions[1], 3);
27
VERIFY_IS_EQUAL
((
int
)dimensions[2], 7);
28
}
29
30
static
void
test_fixed_size
()
31
{
32
Eigen::Sizes<2,3,7>
dimensions
;
33
34
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<0>(dimensions), 2);
35
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<1>(dimensions), 3);
36
VERIFY_IS_EQUAL
((
int
)Eigen::internal::array_get<2>(dimensions), 7);
37
VERIFY_IS_EQUAL
((
int
)dimensions.
TotalSize
(), 2*3*7);
38
}
39
40
static
void
test_match
()
41
{
42
Eigen::DSizes<unsigned int, 3>
dyn((
unsigned
int
)2,(
unsigned
int
)3,(
unsigned
int
)7);
43
Eigen::Sizes<2,3,7>
stat;
44
VERIFY_IS_EQUAL
(
Eigen::dimensions_match
(dyn, stat),
true
);
45
46
Eigen::DSizes<int, 3>
dyn1(2,3,7);
47
Eigen::DSizes<int, 2>
dyn2(2,3);
48
VERIFY_IS_EQUAL
(
Eigen::dimensions_match
(dyn1, dyn2),
false
);
49
}
50
51
static
void
test_rank_zero
()
52
{
53
Eigen::Sizes<>
scalar
;
54
VERIFY_IS_EQUAL
((
int
)scalar.
TotalSize
(), 1);
55
VERIFY_IS_EQUAL
((
int
)scalar.
rank
(), 0);
56
VERIFY_IS_EQUAL
((
int
)
internal::array_prod
(scalar), 1);
57
58
Eigen::DSizes<ptrdiff_t, 0>
dscalar;
59
VERIFY_IS_EQUAL
((
int
)dscalar.
TotalSize
(), 1);
60
VERIFY_IS_EQUAL
((
int
)dscalar.
rank
(), 0);
61
}
62
63
static
void
test_index_type_promotion
() {
64
Eigen::DSizes<int, 3>
src0(1, 2, 3);
65
Eigen::array<int, 3>
src1;
66
src1[0] = 4;
67
src1[1] = 5;
68
src1[2] = 6;
69
70
Eigen::DSizes<long, 3>
dst0(src0);
71
Eigen::DSizes<long, 3>
dst1(src1);
72
73
VERIFY_IS_EQUAL
(dst0[0], 1
L
);
74
VERIFY_IS_EQUAL
(dst0[1], 2
L
);
75
VERIFY_IS_EQUAL
(dst0[2], 3
L
);
76
VERIFY_IS_EQUAL
(dst1[0], 4
L
);
77
VERIFY_IS_EQUAL
(dst1[1], 5
L
);
78
VERIFY_IS_EQUAL
(dst1[2], 6
L
);
79
}
80
81
EIGEN_DECLARE_TEST
(cxx11_tensor_dimension)
82
{
83
CALL_SUBTEST
(
test_dynamic_size
());
84
CALL_SUBTEST
(
test_fixed_size
());
85
CALL_SUBTEST
(
test_match
());
86
CALL_SUBTEST
(
test_rank_zero
());
87
CALL_SUBTEST
(
test_index_type_promotion
());
88
}
Eigen::internal::array_prod
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition:
TensorDimensions.h:140
Eigen::Sizes::rank
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank() const
Definition:
TensorDimensions.h:99
Eigen::DSizes
Definition:
TensorDimensions.h:263
Eigen::dimensions_match
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2)
Definition:
TensorDimensions.h:484
L
MatrixXd L
Definition:
LLT_example.cpp:6
Eigen::Sizes
Definition:
TensorDimensions.h:93
main.h
test_fixed_size
static void test_fixed_size()
Definition:
cxx11_tensor_dimension.cpp:30
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:386
Eigen::DSizes::TotalSize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
Definition:
TensorDimensions.h:271
test_index_type_promotion
static void test_index_type_promotion()
Definition:
cxx11_tensor_dimension.cpp:63
Eigen::DSizes::rank
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
Definition:
TensorDimensions.h:267
test_match
static void test_match()
Definition:
cxx11_tensor_dimension.cpp:40
Eigen::array
Definition:
EmulateArray.h:21
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_dimension)
Definition:
cxx11_tensor_dimension.cpp:81
Eigen::Sizes::TotalSize
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize()
Definition:
TensorDimensions.h:103
test_dynamic_size
static void test_dynamic_size()
Definition:
cxx11_tensor_dimension.cpp:17
dimensions
const std::vector< size_t > dimensions
Definition:
testVerticalBlockMatrix.cpp:27
scalar
mxArray * scalar(mxClassID classid)
Definition:
matlab.h:82
test_rank_zero
static void test_rank_zero()
Definition:
cxx11_tensor_dimension.cpp:51
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:07