MRPT  1.9.9
matrix_ops5_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-2019, 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>
15 #include <mrpt/math/CMatrixFixed.h>
16 #include <mrpt/random.h>
17 #include <Eigen/Dense>
18 
19 using namespace mrpt;
20 using namespace mrpt::math;
21 using namespace mrpt::random;
22 using namespace std;
23 
24 TEST(Matrices, loadFromArray)
25 {
26  alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
27  const double nums[3 * 4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
28 
30  mat.loadFromArray(nums);
31 
32  for (int r = 0; r < 3; r++)
33  for (int c = 0; c < 4; c++) EXPECT_EQ(nums[4 * r + c], mat(r, c));
34 }
35 
36 alignas(MRPT_MAX_STATIC_ALIGN_BYTES) static double test_nums[3 * 4] = {
37  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
38 
39 TEST(Matrices, CMatrixFixedNumeric_loadWithEigenMap)
40 {
41  // Row major
42  const auto mat =
45  MRPT_MAX_STATIC_ALIGN_BYTES>(test_nums));
46 
47  for (int r = 0; r < 3; r++)
48  for (int c = 0; c < 4; c++) EXPECT_EQ(test_nums[4 * r + c], mat(r, c));
49 }
50 
51 TEST(Matrices, EigenMatrix_loadWithEigenMap)
52 {
53  // Col major
54  const Eigen::Matrix<double, 3, 4> mat =
55  Eigen::Map<Eigen::Matrix<double, 3, 4>, MRPT_MAX_STATIC_ALIGN_BYTES>(
56  test_nums);
57 
58  for (int r = 0; r < 3; r++) // Transposed!!
59  for (int c = 0; c < 4; c++) EXPECT_EQ(test_nums[3 * c + r], mat(r, c));
60 }
A namespace of pseudo-random numbers generators of diferent distributions.
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
static double test_nums[3 *4]
STL namespace.
void loadFromArray(const VECTOR &vals)
Definition: CMatrixFixed.h:171
This base provides a set of functions for maths stuff.
const GLubyte * c
Definition: glext.h:6406
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
TEST(Matrices, loadFromArray)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 479715d5b Tue Nov 12 07:26:21 2019 +0100 at mar nov 12 07:30:12 CET 2019