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-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 
17 #include <mrpt/random.h>
18 #include <gtest/gtest.h>
19 
20 using namespace mrpt;
21 using namespace mrpt::utils;
22 using namespace mrpt::math;
23 using namespace mrpt::random;
24 using namespace mrpt::utils::metaprogramming;
25 using namespace std;
26 
27 #define CHECK_AND_RET_ERROR(_COND_, _MSG_) EXPECT_FALSE(_COND_) << _MSG_;
28 
29 TEST(Matrices, setSize)
30 {
31  {
33  EXPECT_TRUE((M.array() == 0).all());
34  }
35  {
36  CMatrixDouble M(5, 5);
37  EXPECT_TRUE((M.array() == 0).all());
38  }
39  {
40  CMatrixDouble M(5, 5);
41  M.setSize(6, 5);
42  EXPECT_TRUE((M.array() == 0).all());
43  }
44  {
45  CMatrixDouble M(5, 5);
46  M.setSize(10, 5);
47  EXPECT_TRUE((M.array() == 0).all());
48  }
49  {
50  CMatrixDouble M(5, 5);
51  M.setSize(5, 6);
52  EXPECT_TRUE((M.array() == 0).all());
53  }
54  {
55  CMatrixDouble M(5, 5);
56  M.setSize(6, 6);
57  EXPECT_TRUE((M.array() == 0).all());
58  }
59  {
60  CMatrixDouble M(5, 5);
61  M.setSize(10, 10);
62  EXPECT_TRUE((M.array() == 0).all());
63  }
64 }
65 
67 {
68  {
69  const double vals[] = {
70  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
71  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
72  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
73  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15};
75 
76  std::vector<size_t> vs;
77  vs.push_back(1);
78  vs.push_back(3);
79 
80  CMatrixDouble E;
81  M.extractSubmatrixSymmetricalBlocks(2, vs, E);
82 
83  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
84  3, 4, 7, 8, 10, 11, 14, 15};
85  const CMatrixDouble44 E_expected(valsE);
86 
87  EXPECT_TRUE(E_expected == E);
88  }
89 }
90 
92 {
93  {
94  const double vals[] = {
95  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
96  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
97  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15,
98  1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15};
100 
101  std::vector<size_t> vs;
102  vs.push_back(2);
103  vs.push_back(3);
104  vs.push_back(6);
105  vs.push_back(7);
106 
107  CMatrixDouble E;
108  M.extractSubmatrixSymmetrical(vs, E);
109 
110  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
111  3, 4, 7, 8, 10, 11, 14, 15};
112  const CMatrixDouble44 E_expected(valsE);
113 
114  EXPECT_TRUE(E_expected == E);
115  }
116 }
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.
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.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019