xref: /aosp_15_r20/external/eigen/doc/PreprocessorDirectives.dox (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Linamespace Eigen {
2*bf2c3715SXin Li
3*bf2c3715SXin Li/** \page TopicPreprocessorDirectives Preprocessor directives
4*bf2c3715SXin Li
5*bf2c3715SXin LiYou can control some aspects of %Eigen by defining the preprocessor tokens using \c \#define. These macros
6*bf2c3715SXin Lishould be defined before any %Eigen headers are included. Often they are best set in the project options.
7*bf2c3715SXin Li
8*bf2c3715SXin LiThis page lists the preprocessor tokens recognized by %Eigen.
9*bf2c3715SXin Li
10*bf2c3715SXin Li\eigenAutoToc
11*bf2c3715SXin Li
12*bf2c3715SXin Li
13*bf2c3715SXin Li\section TopicPreprocessorDirectivesMajor Macros with major effects
14*bf2c3715SXin Li
15*bf2c3715SXin LiThese macros have a major effect and typically break the API (Application Programming Interface) and/or the
16*bf2c3715SXin LiABI (Application Binary Interface). This can be rather dangerous: if parts of your program are compiled with
17*bf2c3715SXin Lione option, and other parts (or libraries that you use) are compiled with another option, your program may
18*bf2c3715SXin Lifail to link or exhibit subtle bugs. Nevertheless, these options can be useful for people who know what they
19*bf2c3715SXin Liare doing.
20*bf2c3715SXin Li
21*bf2c3715SXin Li - \b EIGEN2_SUPPORT and \b EIGEN2_SUPPORT_STAGEnn_xxx are disabled starting from the 3.3 release.
22*bf2c3715SXin Li   Defining one of these will raise a compile-error. If you need to compile Eigen2 code,
23*bf2c3715SXin Li   <a href="http://eigen.tuxfamily.org/index.php?title=Eigen2">check this site</a>.
24*bf2c3715SXin Li - \b EIGEN_DEFAULT_DENSE_INDEX_TYPE - the type for column and row indices in matrices, vectors and array
25*bf2c3715SXin Li   (DenseBase::Index). Set to \c std::ptrdiff_t by default.
26*bf2c3715SXin Li - \b EIGEN_DEFAULT_IO_FORMAT - the IOFormat to use when printing a matrix if no %IOFormat is specified.
27*bf2c3715SXin Li   Defaults to the %IOFormat constructed by the default constructor IOFormat::IOFormat().
28*bf2c3715SXin Li - \b EIGEN_INITIALIZE_MATRICES_BY_ZERO - if defined, all entries of newly constructed matrices and arrays are
29*bf2c3715SXin Li   initialized to zero, as are new entries in matrices and arrays after resizing. Not defined by default.
30*bf2c3715SXin Li   \warning The unary (resp. binary) constructor of \c 1x1 (resp. \c 2x1 or \c 1x2) fixed size matrices is
31*bf2c3715SXin Li   always interpreted as an initialization constructor where the argument(s) are the coefficient values
32*bf2c3715SXin Li   and not the sizes. For instance, \code Vector2d v(2,1); \endcode will create a vector with coeficients [2,1],
33*bf2c3715SXin Li   and \b not a \c 2x1 vector initialized with zeros (i.e., [0,0]). If such cases might occur, then it is
34*bf2c3715SXin Li   recommended to use the default constructor with a explicit call to resize:
35*bf2c3715SXin Li   \code
36*bf2c3715SXin Li   Matrix<?,SizeAtCompileTime,1> v;
37*bf2c3715SXin Li   v.resize(size);
38*bf2c3715SXin Li   Matrix<?,RowsAtCompileTime,ColsAtCompileTime> m;
39*bf2c3715SXin Li   m.resize(rows,cols);
40*bf2c3715SXin Li   \endcode
41*bf2c3715SXin Li - \b EIGEN_INITIALIZE_MATRICES_BY_NAN - if defined, all entries of newly constructed matrices and arrays are
42*bf2c3715SXin Li   initialized to NaN, as are new entries in matrices and arrays after resizing. This option is especially
43*bf2c3715SXin Li   useful for debugging purpose, though a memory tool like <a href="http://valgrind.org/">valgrind</a> is
44*bf2c3715SXin Li   preferable. Not defined by default.
45*bf2c3715SXin Li   \warning See the documentation of \c EIGEN_INITIALIZE_MATRICES_BY_ZERO for a discussion on a limitations
46*bf2c3715SXin Li   of these macros when applied to \c 1x1, \c 1x2, and \c 2x1 fixed-size matrices.
47*bf2c3715SXin Li - \b EIGEN_NO_AUTOMATIC_RESIZING - if defined, the matrices (or arrays) on both sides of an assignment
48*bf2c3715SXin Li   <tt>a = b</tt> have to be of the same size; otherwise, %Eigen automatically resizes \c a so that it is of
49*bf2c3715SXin Li   the correct size. Not defined by default.
50*bf2c3715SXin Li
51*bf2c3715SXin Li
52*bf2c3715SXin Li\section TopicPreprocessorDirectivesCppVersion C++ standard features
53*bf2c3715SXin Li
54*bf2c3715SXin LiBy default, %Eigen strive to automatically detect and enable language features at compile-time based on
55*bf2c3715SXin Lithe information provided by the compiler.
56*bf2c3715SXin Li
57*bf2c3715SXin Li - \b EIGEN_MAX_CPP_VER - disables usage of C++ features requiring a version greater than EIGEN_MAX_CPP_VER.
58*bf2c3715SXin Li   Possible values are: 03, 11, 14, 17, etc. If not defined (the default), %Eigen enables all features supported
59*bf2c3715SXin Li   by the compiler.
60*bf2c3715SXin Li
61*bf2c3715SXin LiIndividual features can be explicitly enabled or disabled by defining the following token to 0 or 1 respectively.
62*bf2c3715SXin LiFor instance, one might limit the C++ version to C++03 by defining EIGEN_MAX_CPP_VER=03, but still enable C99 math
63*bf2c3715SXin Lifunctions by defining EIGEN_HAS_C99_MATH=1.
64*bf2c3715SXin Li
65*bf2c3715SXin Li - \b EIGEN_HAS_C99_MATH - controls the usage of C99 math functions such as erf, erfc, lgamma, etc.
66*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
67*bf2c3715SXin Li - \b EIGEN_HAS_CXX11_MATH - controls the implementation of some functions such as round, logp1, isinf, isnan, etc.
68*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
69*bf2c3715SXin Li - \b EIGEN_HAS_RVALUE_REFERENCES - defines whether rvalue references are supported
70*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
71*bf2c3715SXin Li - \b EIGEN_HAS_STD_RESULT_OF - defines whether std::result_of is supported
72*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
73*bf2c3715SXin Li - \b EIGEN_HAS_VARIADIC_TEMPLATES - defines whether variadic templates are supported
74*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
75*bf2c3715SXin Li - \b EIGEN_HAS_CONSTEXPR - defines whether relaxed const expression are supported
76*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<14.
77*bf2c3715SXin Li - \b EIGEN_HAS_CXX11_CONTAINERS - defines whether STL's containers follows C++11 specifications
78*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
79*bf2c3715SXin Li - \b EIGEN_HAS_CXX11_NOEXCEPT - defines whether noexcept is supported
80*bf2c3715SXin Li   Automatic detection disabled if EIGEN_MAX_CPP_VER<11.
81*bf2c3715SXin Li - \b EIGEN_NO_IO - Disables any usage and support for `<iostreams>`.
82*bf2c3715SXin Li
83*bf2c3715SXin Li\section TopicPreprocessorDirectivesAssertions Assertions
84*bf2c3715SXin Li
85*bf2c3715SXin LiThe %Eigen library contains many assertions to guard against programming errors, both at compile time and at
86*bf2c3715SXin Lirun time. However, these assertions do cost time and can thus be turned off.
87*bf2c3715SXin Li
88*bf2c3715SXin Li - \b EIGEN_NO_DEBUG - disables %Eigen's assertions if defined. Not defined by default, unless the
89*bf2c3715SXin Li   \c NDEBUG macro is defined (this is a standard C++ macro which disables all asserts).
90*bf2c3715SXin Li - \b EIGEN_NO_STATIC_ASSERT - if defined, compile-time static assertions are replaced by runtime assertions;
91*bf2c3715SXin Li   this saves compilation time. Not defined by default.
92*bf2c3715SXin Li - \b eigen_assert - macro with one argument that is used inside %Eigen for assertions. By default, it is
93*bf2c3715SXin Li   basically defined to be \c assert, which aborts the program if the assertion is violated. Redefine this
94*bf2c3715SXin Li   macro if you want to do something else, like throwing an exception.
95*bf2c3715SXin Li - \b EIGEN_MPL2_ONLY - disable non MPL2 compatible features, or in other words disable the features which
96*bf2c3715SXin Li   are still under the LGPL.
97*bf2c3715SXin Li
98*bf2c3715SXin Li
99*bf2c3715SXin Li\section TopicPreprocessorDirectivesPerformance Alignment, vectorization and performance tweaking
100*bf2c3715SXin Li
101*bf2c3715SXin Li - \b \c EIGEN_MALLOC_ALREADY_ALIGNED - Can be set to 0 or 1 to tell whether default system \c malloc already
102*bf2c3715SXin Li   returns aligned buffers. In not defined, then this information is automatically deduced from the compiler
103*bf2c3715SXin Li   and system preprocessor tokens.
104*bf2c3715SXin Li - \b \c EIGEN_MAX_ALIGN_BYTES - Must be a power of two, or 0. Defines an upper bound on the memory boundary in bytes on which dynamically and statically allocated data may be aligned by %Eigen. If not defined, a default value is automatically computed based on architecture, compiler, and OS.
105*bf2c3715SXin Li This option is typically used to enforce binary compatibility between code/libraries compiled with different SIMD options. For instance, one may compile AVX code and enforce ABI compatibility with existing SSE code by defining \c EIGEN_MAX_ALIGN_BYTES=16. In the other way round, since by default AVX implies 32 bytes alignment for best performance, one can compile SSE code to be ABI compatible with AVX code by defining \c EIGEN_MAX_ALIGN_BYTES=32.
106*bf2c3715SXin Li - \b \c EIGEN_MAX_STATIC_ALIGN_BYTES - Same as \c EIGEN_MAX_ALIGN_BYTES but for statically allocated data only. By default, if only  \c EIGEN_MAX_ALIGN_BYTES is defined, then \c EIGEN_MAX_STATIC_ALIGN_BYTES == \c EIGEN_MAX_ALIGN_BYTES, otherwise a default value is automatically computed based on architecture, compiler, and OS (can be smaller than the default value of EIGEN_MAX_ALIGN_BYTES on architectures that do not support stack alignment).
107*bf2c3715SXin Li Let us emphasize that \c EIGEN_MAX_*_ALIGN_BYTES define only a diserable upper bound. In practice data is aligned to largest power-of-two common divisor of \c EIGEN_MAX_STATIC_ALIGN_BYTES and the size of the data, such that memory is not wasted.
108*bf2c3715SXin Li - \b \c EIGEN_DONT_PARALLELIZE - if defined, this disables multi-threading. This is only relevant if you enabled OpenMP.
109*bf2c3715SXin Li   See \ref TopicMultiThreading for details.
110*bf2c3715SXin Li - \b \c EIGEN_DONT_VECTORIZE - disables explicit vectorization when defined. Not defined by default, unless
111*bf2c3715SXin Li   alignment is disabled by %Eigen's platform test or the user defining \c EIGEN_DONT_ALIGN.
112*bf2c3715SXin Li - \b \c EIGEN_UNALIGNED_VECTORIZE - disables/enables vectorization with unaligned stores. Default is 1 (enabled).
113*bf2c3715SXin Li   If set to 0 (disabled), then expression for which the destination cannot be aligned are not vectorized (e.g., unaligned
114*bf2c3715SXin Li   small fixed size vectors or matrices)
115*bf2c3715SXin Li - \b \c EIGEN_FAST_MATH - enables some optimizations which might affect the accuracy of the result. This currently
116*bf2c3715SXin Li   enables the SSE vectorization of sin() and cos(), and speedups sqrt() for single precision. Defined to 1 by default.
117*bf2c3715SXin Li   Define it to 0 to disable.
118*bf2c3715SXin Li - \b \c EIGEN_UNROLLING_LIMIT - defines the size of a loop to enable meta unrolling. Set it to zero to disable
119*bf2c3715SXin Li   unrolling. The size of a loop here is expressed in %Eigen's own notion of "number of FLOPS", it does not
120*bf2c3715SXin Li   correspond to the number of iterations or the number of instructions. The default is value 110.
121*bf2c3715SXin Li - \b \c EIGEN_STACK_ALLOCATION_LIMIT - defines the maximum bytes for a buffer to be allocated on the stack. For internal
122*bf2c3715SXin Li   temporary buffers, dynamic memory allocation is employed as a fall back. For fixed-size matrices or arrays, exceeding
123*bf2c3715SXin Li   this threshold raises a compile time assertion. Use 0 to set no limit. Default is 128 KB.
124*bf2c3715SXin Li - \b \c EIGEN_NO_CUDA - disables CUDA support when defined. Might be useful in .cu files for which Eigen is used on the host only,
125*bf2c3715SXin Li   and never called from device code.
126*bf2c3715SXin Li - \b \c EIGEN_STRONG_INLINE - This macro is used to qualify critical functions and methods that we expect the compiler to inline.
127*bf2c3715SXin Li   By default it is defined to \c __forceinline for MSVC and ICC, and to \c inline for other compilers. A tipical usage is to
128*bf2c3715SXin Li   define it to \c inline for MSVC users wanting faster compilation times, at the risk of performance degradations in some rare
129*bf2c3715SXin Li   cases for which MSVC inliner fails to do a good job.
130*bf2c3715SXin Li - \b \c EIGEN_DEFAULT_L1_CACHE_SIZE - Sets the default L1 cache size that is used in Eigen's GEBP kernel when the correct cache size cannot be determined at runtime.
131*bf2c3715SXin Li - \b \c EIGEN_DEFAULT_L2_CACHE_SIZE - Sets the default L2 cache size that is used in Eigen's GEBP kernel when the correct cache size cannot be determined at runtime.
132*bf2c3715SXin Li - \b \c EIGEN_DEFAULT_L3_CACHE_SIZE - Sets the default L3 cache size that is used in Eigen's GEBP kernel when the correct cache size cannot be determined at runtime.
133*bf2c3715SXin Li
134*bf2c3715SXin Li - \c EIGEN_DONT_ALIGN - Deprecated, it is a synonym for \c EIGEN_MAX_ALIGN_BYTES=0. It disables alignment completely. %Eigen will not try to align its objects and does not expect that any objects passed to it are aligned. This will turn off vectorization if \b \c EIGEN_UNALIGNED_VECTORIZE=1. Not defined by default.
135*bf2c3715SXin Li - \c EIGEN_DONT_ALIGN_STATICALLY - Deprecated, it is a synonym for \c EIGEN_MAX_STATIC_ALIGN_BYTES=0. It disables alignment of arrays on the stack. Not defined by default, unless \c EIGEN_DONT_ALIGN is defined.
136*bf2c3715SXin Li
137*bf2c3715SXin Li
138*bf2c3715SXin Li\section TopicPreprocessorDirectivesPlugins Plugins
139*bf2c3715SXin Li
140*bf2c3715SXin LiIt is possible to add new methods to many fundamental classes in %Eigen by writing a plugin. As explained in
141*bf2c3715SXin Lithe section \ref TopicCustomizing_Plugins, the plugin is specified by defining a \c EIGEN_xxx_PLUGIN macro. The
142*bf2c3715SXin Lifollowing macros are supported; none of them are defined by default.
143*bf2c3715SXin Li
144*bf2c3715SXin Li - \b EIGEN_ARRAY_PLUGIN - filename of plugin for extending the Array class.
145*bf2c3715SXin Li - \b EIGEN_ARRAYBASE_PLUGIN - filename of plugin for extending the ArrayBase class.
146*bf2c3715SXin Li - \b EIGEN_CWISE_PLUGIN - filename of plugin for extending the Cwise class.
147*bf2c3715SXin Li - \b EIGEN_DENSEBASE_PLUGIN - filename of plugin for extending the DenseBase class.
148*bf2c3715SXin Li - \b EIGEN_DYNAMICSPARSEMATRIX_PLUGIN - filename of plugin for extending the DynamicSparseMatrix class.
149*bf2c3715SXin Li - \b EIGEN_FUNCTORS_PLUGIN - filename of plugin for adding new functors and specializations of functor_traits.
150*bf2c3715SXin Li - \b EIGEN_MAPBASE_PLUGIN - filename of plugin for extending the MapBase class.
151*bf2c3715SXin Li - \b EIGEN_MATRIX_PLUGIN - filename of plugin for extending the Matrix class.
152*bf2c3715SXin Li - \b EIGEN_MATRIXBASE_PLUGIN - filename of plugin for extending the MatrixBase class.
153*bf2c3715SXin Li - \b EIGEN_PLAINOBJECTBASE_PLUGIN - filename of plugin for extending the PlainObjectBase class.
154*bf2c3715SXin Li - \b EIGEN_QUATERNION_PLUGIN - filename of plugin for extending the Quaternion class.
155*bf2c3715SXin Li - \b EIGEN_QUATERNIONBASE_PLUGIN - filename of plugin for extending the QuaternionBase class.
156*bf2c3715SXin Li - \b EIGEN_SPARSEMATRIX_PLUGIN - filename of plugin for extending the SparseMatrix class.
157*bf2c3715SXin Li - \b EIGEN_SPARSEMATRIXBASE_PLUGIN - filename of plugin for extending the SparseMatrixBase class.
158*bf2c3715SXin Li - \b EIGEN_SPARSEVECTOR_PLUGIN - filename of plugin for extending the SparseVector class.
159*bf2c3715SXin Li - \b EIGEN_TRANSFORM_PLUGIN - filename of plugin for extending the Transform class.
160*bf2c3715SXin Li - \b EIGEN_VECTORWISEOP_PLUGIN - filename of plugin for extending the VectorwiseOp class.
161*bf2c3715SXin Li
162*bf2c3715SXin Li\section TopicPreprocessorDirectivesDevelopers Macros for Eigen developers
163*bf2c3715SXin Li
164*bf2c3715SXin LiThese macros are mainly meant for people developing %Eigen and for testing purposes. Even though, they might be useful for power users and the curious for debugging and testing purpose, they \b should \b not \b be \b used by real-word code.
165*bf2c3715SXin Li
166*bf2c3715SXin Li - \b EIGEN_DEFAULT_TO_ROW_MAJOR - when defined, the default storage order for matrices becomes row-major
167*bf2c3715SXin Li   instead of column-major. Not defined by default.
168*bf2c3715SXin Li - \b EIGEN_INTERNAL_DEBUGGING - if defined, enables assertions in %Eigen's internal routines. This is useful
169*bf2c3715SXin Li   for debugging %Eigen itself. Not defined by default.
170*bf2c3715SXin Li - \b EIGEN_NO_MALLOC - if defined, any request from inside the %Eigen to allocate memory from the heap
171*bf2c3715SXin Li   results in an assertion failure. This is useful to check that some routine does not allocate memory
172*bf2c3715SXin Li   dynamically. Not defined by default.
173*bf2c3715SXin Li - \b EIGEN_RUNTIME_NO_MALLOC - if defined, a new switch is introduced which can be turned on and off by
174*bf2c3715SXin Li   calling <tt>set_is_malloc_allowed(bool)</tt>. If malloc is not allowed and %Eigen tries to allocate memory
175*bf2c3715SXin Li   dynamically anyway, an assertion failure results. Not defined by default.
176*bf2c3715SXin Li
177*bf2c3715SXin Li*/
178*bf2c3715SXin Li
179*bf2c3715SXin Li}
180