constructor.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) 2017 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 
11 #define TEST_ENABLE_TEMPORARY_TRACKING
12 
13 #include "main.h"
14 
15 template<typename MatrixType> struct Wrapper
16 {
18  inline Wrapper(const MatrixType &x) : m_mat(x) {}
19  inline operator const MatrixType& () const { return m_mat; }
20  inline operator MatrixType& () { return m_mat; }
21 };
22 
23 enum my_sizes { M = 12, N = 7};
24 
25 template<typename MatrixType> void ctor_init1(const MatrixType& m)
26 {
27  // Check logic in PlainObjectBase::_init1
28  Index rows = m.rows();
29  Index cols = m.cols();
30 
31  MatrixType m0 = MatrixType::Random(rows,cols);
32 
35  VERIFY_EVALUATION_COUNT( MatrixType m2(m0.block(0,0,rows,cols)) , 1);
36 
38  VERIFY_EVALUATION_COUNT( MatrixType m3(wrapper) , 1);
39 }
40 
41 
43 {
44  for(int i = 0; i < g_repeat; i++) {
46  CALL_SUBTEST_1( ctor_init1(Matrix4d()) );
47  CALL_SUBTEST_1( ctor_init1(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
48  CALL_SUBTEST_1( ctor_init1(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
49  }
50  {
51  Matrix<Index,1,1> a(123);
52  VERIFY_IS_EQUAL(a[0], 123);
53  }
54  {
55  Matrix<Index,1,1> a(123.0);
56  VERIFY_IS_EQUAL(a[0], 123);
57  }
58  {
59  Matrix<float,1,1> a(123);
60  VERIFY_IS_EQUAL(a[0], 123.f);
61  }
62  {
63  Array<Index,1,1> a(123);
64  VERIFY_IS_EQUAL(a[0], 123);
65  }
66  {
67  Array<Index,1,1> a(123.0);
68  VERIFY_IS_EQUAL(a[0], 123);
69  }
70  {
71  Array<float,1,1> a(123);
72  VERIFY_IS_EQUAL(a[0], 123.f);
73  }
74  {
75  Array<Index,3,3> a(123);
76  VERIFY_IS_EQUAL(a(4), 123);
77  }
78  {
79  Array<Index,3,3> a(123.0);
80  VERIFY_IS_EQUAL(a(4), 123);
81  }
82  {
83  Array<float,3,3> a(123);
84  VERIFY_IS_EQUAL(a(4), 123.f);
85  }
86  {
87  MatrixXi m1(M,N);
88  VERIFY_IS_EQUAL(m1.rows(),M);
89  VERIFY_IS_EQUAL(m1.cols(),N);
90  ArrayXXi a1(M,N);
91  VERIFY_IS_EQUAL(a1.rows(),M);
92  VERIFY_IS_EQUAL(a1.cols(),N);
93  VectorXi v1(M);
94  VERIFY_IS_EQUAL(v1.size(),M);
95  ArrayXi a2(M);
96  VERIFY_IS_EQUAL(a2.size(),M);
97  }
98 }
Point2 a1
Definition: testPose2.cpp:769
Matrix3f m
MatrixType m_mat
Definition: constructor.cpp:17
Vector v1
MatrixType m2(n_dims)
MatrixXf MatrixType
#define VERIFY_EVALUATION_COUNT(XPR, N)
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
#define CALL_SUBTEST_1(FUNC)
Matrix3d m1
Definition: IOFormat.cpp:2
void ctor_init1(const MatrixType &m)
Definition: constructor.cpp:25
static int g_repeat
Definition: main.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Point2 a2
Definition: testPose2.cpp:770
Wrapper(const MatrixType &x)
Definition: constructor.cpp:18
#define EIGEN_TEST_MAX_SIZE
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
The matrix class, also used for vectors and row-vectors.
my_sizes
Definition: constructor.cpp:23
EIGEN_DECLARE_TEST(constructor)
Definition: constructor.cpp:42
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:03