commainitializer.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) 2008 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 
12 
13 template<int M1, int M2, int N1, int N2>
15 {
17  MatrixXi m_dynamic(M1+M2, N1+N2);
18 
19  Matrix<int, M1, N1> mat11; mat11.setRandom();
20  Matrix<int, M1, N2> mat12; mat12.setRandom();
21  Matrix<int, M2, N1> mat21; mat21.setRandom();
22  Matrix<int, M2, N2> mat22; mat22.setRandom();
23 
24  MatrixXi matx11 = mat11, matx12 = mat12, matx21 = mat21, matx22 = mat22;
25 
26  {
27  VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat21, matx22).finished(), (m_dynamic << mat11, matx12, mat21, matx22).finished());
28  VERIFY_IS_EQUAL((m_fixed.template topLeftCorner<M1,N1>()), mat11);
29  VERIFY_IS_EQUAL((m_fixed.template topRightCorner<M1,N2>()), mat12);
30  VERIFY_IS_EQUAL((m_fixed.template bottomLeftCorner<M2,N1>()), mat21);
31  VERIFY_IS_EQUAL((m_fixed.template bottomRightCorner<M2,N2>()), mat22);
32  VERIFY_IS_EQUAL((m_fixed << mat12, mat11, matx21, mat22).finished(), (m_dynamic << mat12, matx11, matx21, mat22).finished());
33  }
34 
35  if(N1 > 0)
36  {
37  if(M1 > 0)
38  {
39  VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22));
40  }
41  if(M2 > 0)
42  {
43  VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22));
44  }
45  }
46  else
47  {
48  // allow insertion of zero-column blocks:
49  VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat11, mat11, mat21, mat21, mat22).finished(), (m_dynamic << mat12, mat22).finished());
50  }
51  if(M1 != M2)
52  {
53  VERIFY_RAISES_ASSERT((m_fixed << mat11, mat21, mat12, mat22));
54  }
55 }
56 
57 
58 template<int depth, int N=0>
60 {
61  static void run()
62  {
64  test_block_recursion<depth-1, N + (1 << (depth-1))>::run();
65  }
66 };
67 
68 template<int N>
70 {
71  static void run() {
72  test_blocks<(N>>6)&3, (N>>4)&3, (N>>2)&3, N & 3>();
73  }
74 };
75 
76 void test_basics() {
77  Matrix3d m3;
78  Matrix4d m4;
79 
80  VERIFY_RAISES_ASSERT( (m3 << 1, 2, 3, 4, 5, 6, 7, 8) );
81 
82  #ifndef _MSC_VER
83  VERIFY_RAISES_ASSERT( (m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) );
84  #endif
85 
86  double data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
88 
89  m3 = Matrix3d::Random();
90  m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
92 
93  Vector3d vec[3];
94  vec[0] << 1, 4, 7;
95  vec[1] << 2, 5, 8;
96  vec[2] << 3, 6, 9;
97  m3 = Matrix3d::Random();
98  m3 << vec[0], vec[1], vec[2];
100 
101  vec[0] << 1, 2, 3;
102  vec[1] << 4, 5, 6;
103  vec[2] << 7, 8, 9;
104  m3 = Matrix3d::Random();
105  m3 << vec[0].transpose(),
106  4, 5, 6,
107  vec[2].transpose();
109 }
110 
111 EIGEN_DECLARE_TEST(commainitializer)
112 {
113 
115 
116  // recursively test all block-sizes from 0 to 3:
118 }
M2
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12;Map< MatrixXf > M2(M1.data(), 6, 2)
Eigen::PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::setRandom
Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom(Index size)
Definition: Random.h:151
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
test_basics
void test_basics()
Definition: commainitializer.cpp:76
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(commainitializer)
Definition: commainitializer.cpp:111
test_block_recursion
Definition: commainitializer.cpp:59
VERIFY_RAISES_ASSERT
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:340
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
data
int data[]
Definition: Map_placement_new.cpp:1
M1
MatrixXf M1
Definition: Tutorial_SlicingCol.cpp:1
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
test_block_recursion< 0, N >::run
static void run()
Definition: commainitializer.cpp:71
m3
static const DiscreteKey m3(M(3), 2)
main.h
ref
Reference counting helper.
Definition: object.h:67
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
N
#define N
Definition: igam.h:9
test_block_recursion::run
static void run()
Definition: commainitializer.cpp:61
depth
static double depth
Definition: testSphericalCamera.cpp:64
test_blocks
void test_blocks()
Definition: commainitializer.cpp:14


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:07