Main MRPT website > C++ reference for 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 }
CMatrixFixedNumeric.h
c
const GLubyte * c
Definition: glext.h:6313
test_nums
static double test_nums[3 *4]
Definition: matrix_ops5_unittest.cpp:35
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
random.h
TEST
TEST(Matrices, loadFromArray)
Definition: matrix_ops5_unittest.cpp:23
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::math::CMatrixFixedNumeric::loadFromArray
void loadFromArray(const T *vals)
Definition: CMatrixFixedNumeric.h:76
mrpt::math::CMatrixFixedNumeric
A numeric matrix of compile-time fixed size.
Definition: CMatrixFixedNumeric.h:40
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
MRPT_MAX_ALIGN_BYTES
#define MRPT_MAX_ALIGN_BYTES
Definition: aligned_allocator.h:21



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST