Main MRPT website > C++ reference for MRPT 1.9.9
matrix_ops_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 // Note: Matrices unit tests have been split in different files since
11 // building them with eigen3 eats a lot of RAM and may be a problem while
12 // compiling in small systems.
13 
16 #include <mrpt/random.h>
17 #include <gtest/gtest.h>
18 
19 using namespace mrpt;
20 using namespace mrpt::math;
21 using namespace mrpt::random;
22 using namespace std;
23 
24 #define CHECK_AND_RET_ERROR(_COND_, _MSG_) EXPECT_FALSE(_COND_) << _MSG_;
25 
26 TEST(Matrices, setSize)
27 {
28  {
30  EXPECT_TRUE((M.array() == 0).all());
31  }
32  {
33  CMatrixDouble M(5, 5);
34  EXPECT_TRUE((M.array() == 0).all());
35  }
36  {
37  CMatrixDouble M(5, 5);
38  M.setSize(6, 5);
39  EXPECT_TRUE((M.array() == 0).all());
40  }
41  {
42  CMatrixDouble M(5, 5);
43  M.setSize(10, 5);
44  EXPECT_TRUE((M.array() == 0).all());
45  }
46  {
47  CMatrixDouble M(5, 5);
48  M.setSize(5, 6);
49  EXPECT_TRUE((M.array() == 0).all());
50  }
51  {
52  CMatrixDouble M(5, 5);
53  M.setSize(6, 6);
54  EXPECT_TRUE((M.array() == 0).all());
55  }
56  {
57  CMatrixDouble M(5, 5);
58  M.setSize(10, 10);
59  EXPECT_TRUE((M.array() == 0).all());
60  }
61 }
62 
64 {
65  {
66  const double vals[] = {
67  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
68  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
69  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
70  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15};
72 
73  std::vector<size_t> vs;
74  vs.push_back(1);
75  vs.push_back(3);
76 
77  CMatrixDouble E;
78  M.extractSubmatrixSymmetricalBlocks(2, vs, E);
79 
80  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
81  3, 4, 7, 8, 10, 11, 14, 15};
82  const CMatrixDouble44 E_expected(valsE);
83 
84  EXPECT_TRUE(E_expected == E);
85  }
86 }
87 
89 {
90  {
91  const double vals[] = {
92  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
93  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
94  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
95  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15};
97 
98  std::vector<size_t> vs;
99  vs.push_back(2);
100  vs.push_back(3);
101  vs.push_back(6);
102  vs.push_back(7);
103 
104  CMatrixDouble E;
105  M.extractSubmatrixSymmetrical(vs, E);
106 
107  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
108  3, 4, 7, 8, 10, 11, 14, 15};
109  const CMatrixDouble44 E_expected(valsE);
110 
111  EXPECT_TRUE(E_expected == E);
112  }
113 }
CMatrixFixedNumeric.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
random.h
mrpt::math::CMatrixTemplateNumeric< double >
CMatrixTemplateNumeric.h
extractSubmatrixSymmetrical
void extractSubmatrixSymmetrical(const std::vector< size_t > &indices, MATRIX &out) const
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is the sequ...
Definition: eigen_plugins.h:1069
setSize
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
Definition: eigen_plugins.h:343
mrpt::math::CMatrixFixedNumeric
A numeric matrix of compile-time fixed size.
Definition: CMatrixFixedNumeric.h:40
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
TEST
TEST(Matrices, setSize)
Definition: matrix_ops_unittest.cpp:26
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
extractSubmatrixSymmetricalBlocks
void extractSubmatrixSymmetricalBlocks(const size_t block_size, const std::vector< size_t > &block_indices, MATRIX &out) const
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is a sequen...
Definition: eigen_plugins.h:1026



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST