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



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