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 }
A namespace of pseudo-random numbers generators of diferent distributions.
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...
STL namespace.
TEST(Matrices, setSize)
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020