MRPT  2.0.1
EigenAlignment_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 #include <gtest/gtest.h>
12 #include <mrpt/math/CMatrixFixed.h>
13 #include <mrpt/system/memory.h>
14 #include <Eigen/Dense>
15 #include <iostream>
16 
17 TEST(EigenAlignment, PrintAlignment)
18 {
19  // MRPT_MAX_ALIGN_BYTES from: <mrpt/core/alignment_req.h>
20  // EIGEN_MAX_ALIGN_BYTES from eigen macros.h
21 
22  std::cout << "MRPT_MAX_ALIGN_BYTES : " << MRPT_MAX_ALIGN_BYTES
23  << "\n"
24  "MRPT_MAX_STATIC_ALIGN_BYTES : "
25  << MRPT_MAX_STATIC_ALIGN_BYTES
26  << "\n"
27  "EIGEN_MAX_ALIGN_BYTES : "
28  << EIGEN_MAX_ALIGN_BYTES
29  << "\n"
30  "EIGEN_MAX_STATIC_ALIGN_BYTES : "
31  << EIGEN_MAX_STATIC_ALIGN_BYTES << "\n";
32 
33  EXPECT_GE(MRPT_MAX_ALIGN_BYTES, EIGEN_MAX_ALIGN_BYTES);
34  EXPECT_GE(MRPT_MAX_STATIC_ALIGN_BYTES, EIGEN_MAX_STATIC_ALIGN_BYTES);
35 }
36 
37 template <unsigned int INTER_SPACE>
38 struct Foo
39 {
41 
42  std::array<uint8_t, INTER_SPACE> dummy_space;
43 
45 };
46 
47 template <unsigned int INTER_SPACE>
48 void checkAlignedFoo(const Foo<INTER_SPACE>& d, const std::string& testName)
49 {
50  EXPECT_TRUE(mrpt::system::is_aligned<EIGEN_MAX_ALIGN_BYTES>(&d.m1(0, 0)))
51  << "test: " << testName << "\nINTER_SPACE=" << INTER_SPACE
52  << "\nm1(0,0)=" << static_cast<const void*>(&d.m1(0, 0))
53  << "\nFailed against: EIGEN_MAX_ALIGN_BYTES=" << EIGEN_MAX_ALIGN_BYTES;
54  EXPECT_TRUE(mrpt::system::is_aligned<EIGEN_MAX_ALIGN_BYTES>(&d.m2(0, 0)))
55  << "test: " << testName << "\nINTER_SPACE=" << INTER_SPACE
56  << "\nm2(0,0)=" << static_cast<const void*>(&d.m2(0, 0))
57  << "\nFailed against: EIGEN_MAX_ALIGN_BYTES=" << EIGEN_MAX_ALIGN_BYTES;
58 }
59 
60 template <unsigned int INTER_SPACE>
62 {
64  checkAlignedFoo(d, "do_test_AlignedMemOnStack");
65 }
66 template <unsigned int INTER_SPACE>
68 {
69  do_test_AlignedMemOnStack<INTER_SPACE>();
70  if constexpr (INTER_SPACE > 0)
71  do_test_AlignedMemOnStackUpTo<INTER_SPACE - 1>();
72 }
73 
74 template <unsigned int INTER_SPACE>
76 {
77  std::map<int, Foo<INTER_SPACE>> d;
78  for (int i = 0; i < 100; i++) d[i * 3 + i * i * 4 + 1];
79 
80  checkAlignedFoo(d.rbegin()->second, "do_test_AlignedMemInSTL");
81 }
82 template <unsigned int INTER_SPACE>
84 {
85  do_test_AlignedMemInSTL<INTER_SPACE>();
86  if constexpr (INTER_SPACE > 0)
87  do_test_AlignedMemInSTLUpTo<INTER_SPACE - 1>();
88 }
89 
90 TEST(EigenAlignment, AlignedMemOnStack) { do_test_AlignedMemOnStackUpTo<20>(); }
91 
92 TEST(EigenAlignment, AlignedMemInSTL) { do_test_AlignedMemInSTLUpTo<20>(); }
mrpt::math::CMatrixFixed< double, 3, 3 > m2
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
void do_test_AlignedMemInSTLUpTo()
std::array< uint8_t, INTER_SPACE > dummy_space
void do_test_AlignedMemOnStackUpTo()
void checkAlignedFoo(const Foo< INTER_SPACE > &d, const std::string &testName)
mrpt::math::CMatrixFixed< double, 3, 3 > m1
void do_test_AlignedMemOnStack()
TEST(EigenAlignment, PrintAlignment)
void do_test_AlignedMemInSTL()



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020