gtsam
3rdparty
Eigen
test
num_dimensions.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) 2018 Gael Guennebaud <gael.guennebaud@inria.fr>
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
#include <Eigen/SparseCore>
12
13
template
<
int
ExpectedDim,
typename
Xpr>
14
void
check_dim
(
const
Xpr& ) {
15
STATIC_CHECK
( Xpr::NumDimensions == ExpectedDim );
16
}
17
18
#if EIGEN_HAS_CXX11
19
template
<
template
<
typename
,
int
,
int
>
class
Object
>
20
void
map_num_dimensions()
21
{
22
typedef
Object<double, 1, 1>
ArrayScalarType;
23
typedef
Object<double, 2, 1>
ArrayVectorType;
24
typedef
Object<double, 1, 2>
TransposeArrayVectorType;
25
typedef
Object<double, 2, 2>
ArrayType;
26
typedef
Object<double, Eigen::Dynamic, 1>
DynamicArrayVectorType;
27
typedef
Object<double, 1, Eigen::Dynamic>
DynamicTransposeArrayVectorType;
28
typedef
Object<double, Eigen::Dynamic, Eigen::Dynamic>
DynamicArrayType;
29
30
STATIC_CHECK
(ArrayScalarType::NumDimensions == 0);
31
STATIC_CHECK
(ArrayVectorType::NumDimensions == 1);
32
STATIC_CHECK
(TransposeArrayVectorType::NumDimensions == 1);
33
STATIC_CHECK
(ArrayType::NumDimensions == 2);
34
STATIC_CHECK
(DynamicArrayVectorType::NumDimensions == 1);
35
STATIC_CHECK
(DynamicTransposeArrayVectorType::NumDimensions == 1);
36
STATIC_CHECK
(DynamicArrayType::NumDimensions == 2);
37
38
typedef
Eigen::Map<ArrayScalarType>
ArrayScalarMap;
39
typedef
Eigen::Map<ArrayVectorType>
ArrayVectorMap;
40
typedef
Eigen::Map<TransposeArrayVectorType>
TransposeArrayVectorMap;
41
typedef
Eigen::Map<ArrayType>
ArrayMap;
42
typedef
Eigen::Map<DynamicArrayVectorType>
DynamicArrayVectorMap;
43
typedef
Eigen::Map<DynamicTransposeArrayVectorType>
DynamicTransposeArrayVectorMap;
44
typedef
Eigen::Map<DynamicArrayType>
DynamicArrayMap;
45
46
STATIC_CHECK
(ArrayScalarMap::NumDimensions == 0);
47
STATIC_CHECK
(ArrayVectorMap::NumDimensions == 1);
48
STATIC_CHECK
(TransposeArrayVectorMap::NumDimensions == 1);
49
STATIC_CHECK
(ArrayMap::NumDimensions == 2);
50
STATIC_CHECK
(DynamicArrayVectorMap::NumDimensions == 1);
51
STATIC_CHECK
(DynamicTransposeArrayVectorMap::NumDimensions == 1);
52
STATIC_CHECK
(DynamicArrayMap::NumDimensions == 2);
53
}
54
55
template
<
typename
Scalar,
int
Rows,
int
Cols>
56
using
TArray =
Array<Scalar,Rows,Cols>
;
57
58
template
<
typename
Scalar,
int
Rows,
int
Cols>
59
using
TMatrix =
Matrix<Scalar,Rows,Cols>
;
60
61
#endif
62
63
EIGEN_DECLARE_TEST
(num_dimensions)
64
{
65
int
n
= 10;
66
ArrayXXd
A
(
n
,
n
);
67
CALL_SUBTEST
( check_dim<2>(
A
) );
68
CALL_SUBTEST
( check_dim<2>(
A
.block(1,1,2,2)) );
69
CALL_SUBTEST
( check_dim<1>(
A
.col(1)) );
70
CALL_SUBTEST
( check_dim<1>(
A
.row(1)) );
71
72
MatrixXd
M
(
n
,
n
);
73
CALL_SUBTEST
( check_dim<0>(
M
.row(1)*
M
.col(1)) );
74
75
SparseMatrix<double>
S
(
n
,
n
);
76
CALL_SUBTEST
( check_dim<2>(
S
) );
77
CALL_SUBTEST
( check_dim<2>(
S
.block(1,1,2,2)) );
78
CALL_SUBTEST
( check_dim<1>(
S
.col(1)) );
79
CALL_SUBTEST
( check_dim<1>(
S
.row(1)) );
80
81
SparseVector<double>
s
(
n
);
82
CALL_SUBTEST
( check_dim<1>(
s
) );
83
CALL_SUBTEST
( check_dim<1>(
s
.head(2)) );
84
85
86
#if EIGEN_HAS_CXX11
87
CALL_SUBTEST
( map_num_dimensions<TArray>() );
88
CALL_SUBTEST
( map_num_dimensions<TMatrix>() );
89
#endif
90
}
Eigen::SparseMatrix< double >
s
RealScalar s
Definition:
level1_cplx_impl.h:126
Eigen::Array
General-purpose arrays with easy API for coefficient-wise operations.
Definition:
Array.h:45
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition:
bench_gemm.cpp:48
n
int n
Definition:
BiCGSTAB_simple.cpp:1
Object
Reference counted object base class.
Definition:
object.h:9
check_dim
void check_dim(const Xpr &)
Definition:
num_dimensions.cpp:14
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition:
Map.h:94
main.h
Eigen::SparseVector< double >
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(num_dimensions)
Definition:
num_dimensions.cpp:63
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
STATIC_CHECK
#define STATIC_CHECK(COND)
Definition:
main.h:397
S
DiscreteKey S(1, 2)
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition:
bench_gemm.cpp:51
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:13