MRPT  2.0.0
matrix_ops_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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 #include <gtest/gtest.h>
16 #include <mrpt/math/CMatrixFixed.h>
17 #include <mrpt/math/ops_matrices.h>
18 #include <mrpt/random.h>
19 #include <Eigen/Dense>
20 
21 using namespace mrpt;
22 using namespace mrpt::math;
23 using namespace mrpt::random;
24 using namespace std;
25 
26 #define CHECK_AND_RET_ERROR(_COND_, _MSG_) EXPECT_FALSE(_COND_) << _MSG_;
27 
28 TEST(Matrices, setSize)
29 {
30  {
32  EXPECT_TRUE((M.array() == 0).all());
33  }
34  {
35  CMatrixDouble M(5, 5);
36  EXPECT_TRUE((M.array() == 0).all());
37  }
38  {
39  CMatrixDouble M(5, 5);
40  M.setSize(6, 5, true /* set new entries to zero*/);
41  EXPECT_TRUE((M.array() == 0).all());
42  }
43  {
44  CMatrixDouble M(5, 5);
45  M.setSize(10, 5, true /* set new entries to zero*/);
46  EXPECT_TRUE((M.array() == 0).all());
47  }
48  {
49  CMatrixDouble M(5, 5);
50  M.setSize(5, 6, true /* set new entries to zero*/);
51  EXPECT_TRUE((M.array() == 0).all());
52  }
53  {
54  CMatrixDouble M(5, 5);
55  M.setSize(6, 6, true /* set new entries to zero*/);
56  EXPECT_TRUE((M.array() == 0).all());
57  }
58  {
59  CMatrixDouble M(5, 5);
60  M.setSize(10, 10, true /* set new entries to zero*/);
61  EXPECT_TRUE((M.array() == 0).all());
62  }
63 }
64 
66 {
67  {
68  const double vals[] = {
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,
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  const CMatrixFixed<double, 8, 8> M(vals);
74 
75  std::vector<size_t> vs;
76  vs.push_back(1);
77  vs.push_back(3);
78 
79  CMatrixDouble E;
80  mrpt::math::extractSubmatrixSymmetricalBlocks<2>(M, vs, E);
81 
82  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
83  3, 4, 7, 8, 10, 11, 14, 15};
84  const CMatrixDouble44 E_expected(valsE);
85 
86  EXPECT_TRUE(E_expected == E);
87  }
88 }
89 
91 {
92  {
93  const double vals[] = {
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,
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  const CMatrixFixed<double, 8, 8> M(vals);
99 
100  std::vector<size_t> vs;
101  vs.push_back(2);
102  vs.push_back(3);
103  vs.push_back(6);
104  vs.push_back(7);
105 
106  CMatrixDouble E;
108 
109  const double valsE[] = {3, 4, 7, 8, 10, 11, 14, 15,
110  3, 4, 7, 8, 10, 11, 14, 15};
111  const CMatrixDouble44 E_expected(valsE);
112 
113  EXPECT_TRUE(E_expected == E);
114  }
115 }
A namespace of pseudo-random numbers generators of diferent distributions.
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
void extractSubmatrixSymmetricalBlocks(const MAT &m, const std::vector< size_t > &block_indices, MATRIX &out)
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is a sequen...
Definition: ops_matrices.h:230
STL namespace.
TEST(Matrices, setSize)
This base provides a set of functions for maths stuff.
void extractSubmatrixSymmetrical(const MAT &m, const std::vector< size_t > &indices, MATRIX &out)
Get a submatrix from a square matrix, by collecting the elements M(idxs,idxs), where idxs is the sequ...
Definition: ops_matrices.h:310
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020