Main MRPT website > C++ reference for MRPT 1.5.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-2017, 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 
14 
18 #include <mrpt/random.h>
19 #include <gtest/gtest.h>
20 
21 using namespace mrpt;
22 using namespace mrpt::utils;
23 using namespace mrpt::math;
24 using namespace mrpt::random;
25 using namespace mrpt::utils::metaprogramming;
26 using namespace std;
27 
28 #define CHECK_AND_RET_ERROR(_COND_,_MSG_) EXPECT_FALSE(_COND_) << _MSG_;
29 
30 TEST(Matrices, setSize)
31 {
32  {
34  EXPECT_TRUE( (M.array() == 0).all() );
35  }
36  {
37  CMatrixDouble M(5,5);
38  EXPECT_TRUE( (M.array() == 0).all() );
39  }
40  {
41  CMatrixDouble M(5,5);
42  M.setSize(6,5);
43  EXPECT_TRUE( (M.array() == 0).all() );
44  }
45  {
46  CMatrixDouble M(5,5);
47  M.setSize(10,5);
48  EXPECT_TRUE( (M.array() == 0).all() );
49  }
50  {
51  CMatrixDouble M(5,5);
52  M.setSize(5,6);
53  EXPECT_TRUE( (M.array() == 0).all() );
54  }
55  {
56  CMatrixDouble M(5,5);
57  M.setSize(6,6);
58  EXPECT_TRUE( (M.array() == 0).all() );
59  }
60  {
61  CMatrixDouble M(5,5);
62  M.setSize(10,10);
63  EXPECT_TRUE( (M.array() == 0).all() );
64  }
65 }
66 
68 {
69  {
70  const double vals[] = {
71  1,2,3,4,5,6,7,8,
72  8,9,10,11,12,13,14,15,
73  1,2,3,4,5,6,7,8,
74  8,9,10,11,12,13,14,15,
75  1,2,3,4,5,6,7,8,
76  8,9,10,11,12,13,14,15,
77  1,2,3,4,5,6,7,8,
78  8,9,10,11,12,13,14,15 };
79  const CMatrixFixedNumeric<double,8,8> M(vals);
80 
81  std::vector<size_t> vs;
82  vs.push_back(1);
83  vs.push_back(3);
84 
85  CMatrixDouble E;
86  M.extractSubmatrixSymmetricalBlocks(2,vs,E);
87 
88  const double valsE[] = {
89  3,4,7,8,
90  10,11,14,15,
91  3,4,7,8,
92  10,11,14,15 };
93  const CMatrixDouble44 E_expected(valsE);
94 
95  EXPECT_TRUE( E_expected == E );
96  }
97 }
98 
100 {
101  {
102  const double vals[] = {
103  1,2,3,4,5,6,7,8,
104  8,9,10,11,12,13,14,15,
105  1,2,3,4,5,6,7,8,
106  8,9,10,11,12,13,14,15,
107  1,2,3,4,5,6,7,8,
108  8,9,10,11,12,13,14,15,
109  1,2,3,4,5,6,7,8,
110  8,9,10,11,12,13,14,15 };
111  const CMatrixFixedNumeric<double,8,8> M(vals);
112 
113  std::vector<size_t> vs;
114  vs.push_back(2);
115  vs.push_back(3);
116  vs.push_back(6);
117  vs.push_back(7);
118 
119  CMatrixDouble E;
120  M.extractSubmatrixSymmetrical(vs,E);
121 
122  const double valsE[] = {
123  3,4,7,8,
124  10,11,14,15,
125  3,4,7,8,
126  10,11,14,15 };
127  const CMatrixDouble44 E_expected(valsE);
128 
129  EXPECT_TRUE( E_expected == E );
130  }
131 }
132 
133 
A namespace of pseudo-random numbers genrators of diferent distributions.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
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.
Definition: CArrayNumeric.h:19
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...
A set of utility objects for metaprogramming with STL algorithms.
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.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020