You can control some aspects of Eigen by defining the preprocessor tokens using #define
. These macros should be defined before any Eigen headers are included. Often they are best set in the project options.
This page lists the preprocessor tokens recognized by Eigen.
These macros have a major effect and typically break the API (Application Programming Interface) and/or the ABI (Application Binary Interface). This can be rather dangerous: if parts of your program are compiled with one option, and other parts (or libraries that you use) are compiled with another option, your program may fail to link or exhibit subtle bugs. Nevertheless, these options can be useful for people who know what they are doing.
std::ptrdiff_t
by default.1x1
(resp. 2x1
or 1x2
) fixed size matrices is always interpreted as an initialization constructor where the argument(s) are the coefficient values and not the sizes. For instance,Vector2d v(2,1);will create a vector with coeficients [2,1], and not a
2x1
vector initialized with zeros (i.e., [0,0]). If such cases might occur, then it is recommended to use the default constructor with a explicit call to resize: Matrix<?,SizeAtCompileTime,1> v; v.resize(size); Matrix<?,RowsAtCompileTime,ColsAtCompileTime> m; m.resize(rows,cols);
EIGEN_INITIALIZE_MATRICES_BY_ZERO
for a discussion on a limitations of these macros when applied to 1x1
, 1x2
, and 2x1
fixed-size matrices.a = b
have to be of the same size; otherwise, Eigen automatically resizes a
so that it is of the correct size. Not defined by default.By default, Eigen strive to automatically detect and enable language features at compile-time based on the information provided by the compiler.
Individual features can be explicitly enabled or disabled by defining the following token to 0 or 1 respectively. For instance, one might limit the C++ version to C++03 by defining EIGEN_MAX_CPP_VER=03, but still enable C99 math functions by defining EIGEN_HAS_C99_MATH=1.
<iostreams>
.The Eigen library contains many assertions to guard against programming errors, both at compile time and at run time. However, these assertions do cost time and can thus be turned off.
NDEBUG
macro is defined (this is a standard C++ macro which disables all asserts).assert
, which aborts the program if the assertion is violated. Redefine this macro if you want to do something else, like throwing an exception.EIGEN_MALLOC_ALREADY_ALIGNED
- Can be set to 0 or 1 to tell whether default system malloc
already returns aligned buffers. In not defined, then this information is automatically deduced from the compiler and system preprocessor tokens.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. 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 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 EIGEN_MAX_ALIGN_BYTES=32
.EIGEN_MAX_STATIC_ALIGN_BYTES
- Same as EIGEN_MAX_ALIGN_BYTES
but for statically allocated data only. By default, if only EIGEN_MAX_ALIGN_BYTES
is defined, then EIGEN_MAX_STATIC_ALIGN_BYTES
== 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). Let us emphasize that EIGEN_MAX_*_ALIGN_BYTES
define only a diserable upper bound. In practice data is aligned to largest power-of-two common divisor of EIGEN_MAX_STATIC_ALIGN_BYTES
and the size of the data, such that memory is not wasted.EIGEN_DONT_PARALLELIZE
- if defined, this disables multi-threading. This is only relevant if you enabled OpenMP. See Eigen and multi-threading for details.EIGEN_DONT_VECTORIZE
- disables explicit vectorization when defined. Not defined by default, unless alignment is disabled by Eigen's platform test or the user defining EIGEN_DONT_ALIGN
.EIGEN_UNALIGNED_VECTORIZE
- disables/enables vectorization with unaligned stores. Default is 1 (enabled). If set to 0 (disabled), then expression for which the destination cannot be aligned are not vectorized (e.g., unaligned small fixed size vectors or matrices)EIGEN_FAST_MATH
- enables some optimizations which might affect the accuracy of the result. This currently enables the SSE vectorization of sin() and cos(), and speedups sqrt() for single precision. Defined to 1 by default. Define it to 0 to disable.EIGEN_UNROLLING_LIMIT
- defines the size of a loop to enable meta unrolling. Set it to zero to disable unrolling. The size of a loop here is expressed in Eigen's own notion of "number of FLOPS", it does not correspond to the number of iterations or the number of instructions. The default is value 110.EIGEN_STACK_ALLOCATION_LIMIT
- defines the maximum bytes for a buffer to be allocated on the stack. For internal temporary buffers, dynamic memory allocation is employed as a fall back. For fixed-size matrices or arrays, exceeding this threshold raises a compile time assertion. Use 0 to set no limit. Default is 128 KB.EIGEN_NO_CUDA
- disables CUDA support when defined. Might be useful in .cu files for which Eigen is used on the host only, and never called from device code.EIGEN_STRONG_INLINE
- This macro is used to qualify critical functions and methods that we expect the compiler to inline. By default it is defined to __forceinline
for MSVC and ICC, and to inline
for other compilers. A tipical usage is to define it to inline
for MSVC users wanting faster compilation times, at the risk of performance degradations in some rare cases for which MSVC inliner fails to do a good job.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.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.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.EIGEN_DONT_ALIGN
- Deprecated, it is a synonym for 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 EIGEN_UNALIGNED_VECTORIZE=1
. Not defined by default.EIGEN_DONT_ALIGN_STATICALLY
- Deprecated, it is a synonym for EIGEN_MAX_STATIC_ALIGN_BYTES=0
. It disables alignment of arrays on the stack. Not defined by default, unless EIGEN_DONT_ALIGN
is defined.It is possible to add new methods to many fundamental classes in Eigen by writing a plugin. As explained in the section Extending MatrixBase (and other classes), the plugin is specified by defining a EIGEN_xxx_PLUGIN
macro. The following macros are supported; none of them are defined by default.
These 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 should not be used by real-word code.
set_is_malloc_allowed(bool)
. If malloc is not allowed and Eigen tries to allocate memory dynamically anyway, an assertion failure results. Not defined by default.
© Eigen.
Licensed under the MPL2 License.
https://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html