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 template<typename MatrixType> void ctor_init1(const MatrixType& m)
24 {
25  // Check logic in PlainObjectBase::_init1
26  Index rows = m.rows();
27  Index cols = m.cols();
28 
29  MatrixType m0 = MatrixType::Random(rows,cols);
30 
33  VERIFY_EVALUATION_COUNT( MatrixType m2(m0.block(0,0,rows,cols)) , 1);
34 
36  VERIFY_EVALUATION_COUNT( MatrixType m3(wrapper) , 1);
37 }
38 
39 
41 {
42  for(int i = 0; i < g_repeat; i++) {
43  CALL_SUBTEST_1( ctor_init1(Matrix<float, 1, 1>()) );
44  CALL_SUBTEST_1( ctor_init1(Matrix4d()) );
45  CALL_SUBTEST_1( ctor_init1(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
46  CALL_SUBTEST_1( ctor_init1(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
47  }
48  {
49  Matrix<Index,1,1> a(123);
50  VERIFY_IS_EQUAL(a[0], 123);
51  }
52  {
53  Matrix<Index,1,1> a(123.0);
54  VERIFY_IS_EQUAL(a[0], 123);
55  }
56  {
57  Matrix<float,1,1> a(123);
58  VERIFY_IS_EQUAL(a[0], 123.f);
59  }
60  {
61  Array<Index,1,1> a(123);
62  VERIFY_IS_EQUAL(a[0], 123);
63  }
64  {
65  Array<Index,1,1> a(123.0);
66  VERIFY_IS_EQUAL(a[0], 123);
67  }
68  {
69  Array<float,1,1> a(123);
70  VERIFY_IS_EQUAL(a[0], 123.f);
71  }
72  {
73  Array<Index,3,3> a(123);
74  VERIFY_IS_EQUAL(a(4), 123);
75  }
76  {
77  Array<Index,3,3> a(123.0);
78  VERIFY_IS_EQUAL(a(4), 123);
79  }
80  {
81  Array<float,3,3> a(123);
82  VERIFY_IS_EQUAL(a(4), 123.f);
83  }
84 }
Matrix3f m
MatrixType m_mat
Definition: constructor.cpp:17
MatrixType m2(n_dims)
void test_constructor()
Definition: constructor.cpp:40
MatrixXf MatrixType
Array33i a
#define VERIFY_EVALUATION_COUNT(XPR, N)
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:331
Matrix3d m1
Definition: IOFormat.cpp:2
void ctor_init1(const MatrixType &m)
Definition: constructor.cpp:23
static int g_repeat
Definition: main.h:144
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
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.
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 Sat May 8 2021 02:41:51