1namespace Eigen { 2 3/** \eigenManualPage TopicUnalignedArrayAssert Explanation of the assertion on unaligned arrays 4 5Hello! You are seeing this webpage because your program terminated on an assertion failure like this one: 6<pre> 7my_program: path/to/eigen/Eigen/src/Core/DenseStorage.h:44: 8Eigen::internal::matrix_array<T, Size, MatrixOptions, Align>::internal::matrix_array() 9[with T = double, int Size = 2, int MatrixOptions = 2, bool Align = true]: 10Assertion `(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion 11is explained here: http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html 12**** READ THIS WEB PAGE !!! ****"' failed. 13</pre> 14 15There are 4 known causes for this issue. Please read on to understand them and learn how to fix them. 16 17\eigenAutoToc 18 19\section where Where in my own code is the cause of the problem? 20 21First of all, you need to find out where in your own code this assertion was triggered from. At first glance, the error message doesn't look helpful, as it refers to a file inside Eigen! However, since your program crashed, if you can reproduce the crash, you can get a backtrace using any debugger. For example, if you're using GCC, you can use the GDB debugger as follows: 22\code 23$ gdb ./my_program # Start GDB on your program 24> run # Start running your program 25... # Now reproduce the crash! 26> bt # Obtain the backtrace 27\endcode 28Now that you know precisely where in your own code the problem is happening, read on to understand what you need to change. 29 30\section c1 Cause 1: Structures having Eigen objects as members 31 32If you have code like this, 33 34\code 35class Foo 36{ 37 //... 38 Eigen::Vector2d v; 39 //... 40}; 41//... 42Foo *foo = new Foo; 43\endcode 44 45then you need to read this separate page: \ref TopicStructHavingEigenMembers "Structures Having Eigen Members". 46 47Note that here, Eigen::Vector2d is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types". 48 49\section c2 Cause 2: STL Containers 50 51If you use STL Containers such as std::vector, std::map, ..., with Eigen objects, or with classes containing Eigen objects, like this, 52 53\code 54std::vector<Eigen::Matrix2f> my_vector; 55struct my_class { ... Eigen::Matrix2f m; ... }; 56std::map<int, my_class> my_map; 57\endcode 58 59then you need to read this separate page: \ref TopicStlContainers "Using STL Containers with Eigen". 60 61Note that here, Eigen::Matrix2f is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types" and \ref TopicStructHavingEigenMembers "structures having such Eigen objects as member". 62 63\section c3 Cause 3: Passing Eigen objects by value 64 65If some function in your code is getting an Eigen object passed by value, like this, 66 67\code 68void func(Eigen::Vector4d v); 69\endcode 70 71then you need to read this separate page: \ref TopicPassingByValue "Passing Eigen objects by value to functions". 72 73Note that here, Eigen::Vector4d is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types". 74 75\section c4 Cause 4: Compiler making a wrong assumption on stack alignment (for instance GCC on Windows) 76 77This is a must-read for people using GCC on Windows (like MinGW or TDM-GCC). If you have this assertion failure in an innocent function declaring a local variable like this: 78 79\code 80void foo() 81{ 82 Eigen::Quaternionf q; 83 //... 84} 85\endcode 86 87then you need to read this separate page: \ref TopicWrongStackAlignment "Compiler making a wrong assumption on stack alignment". 88 89Note that here, Eigen::Quaternionf is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types". 90 91\section explanation General explanation of this assertion 92 93\ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen objects" must absolutely be created at 16-byte-aligned locations, otherwise SIMD instructions adressing them will crash. 94 95Eigen normally takes care of these alignment issues for you, by setting an alignment attribute on them and by overloading their "operator new". 96 97However there are a few corner cases where these alignment settings get overridden: they are the possible causes for this assertion. 98 99\section getrid I don't care about vectorization, how do I get rid of that stuff? 100 101Two possibilities: 102<ul> 103 <li>Define EIGEN_DONT_ALIGN_STATICALLY. That disables all 128-bit static alignment code, while keeping 128-bit heap alignment. This has the effect of 104 disabling vectorization for fixed-size objects (like Matrix4d) while keeping vectorization of dynamic-size objects 105 (like MatrixXd). But do note that this breaks ABI compatibility with the default behavior of 128-bit static alignment.</li> 106 <li>Or define both EIGEN_DONT_VECTORIZE and EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT. This keeps the 107 128-bit alignment code and thus preserves ABI compatibility, but completely disables vectorization.</li> 108</ul> 109 110For more information, see <a href="http://eigen.tuxfamily.org/index.php?title=FAQ#I_disabled_vectorization.2C_but_I.27m_still_getting_annoyed_about_alignment_issues.21">this FAQ</a>. 111 112*/ 113 114} 115