Macros.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_MACROS_H
00012 #define EIGEN_MACROS_H
00013 
00014 #define EIGEN_WORLD_VERSION 3
00015 #define EIGEN_MAJOR_VERSION 2
00016 #define EIGEN_MINOR_VERSION 0
00017 
00018 #define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \
00019                                       (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \
00020                                                                  EIGEN_MINOR_VERSION>=z))))
00021 #ifdef __GNUC__
00022   #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__==x && __GNUC_MINOR__>=y) || __GNUC__>x)
00023 #else
00024   #define EIGEN_GNUC_AT_LEAST(x,y) 0
00025 #endif
00026  
00027 #ifdef __GNUC__
00028   #define EIGEN_GNUC_AT_MOST(x,y) ((__GNUC__==x && __GNUC_MINOR__<=y) || __GNUC__<x)
00029 #else
00030   #define EIGEN_GNUC_AT_MOST(x,y) 0
00031 #endif
00032 
00033 #if EIGEN_GNUC_AT_MOST(4,3) && !defined(__clang__)
00034   // see bug 89
00035   #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 0
00036 #else
00037   #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 1
00038 #endif
00039 
00040 #if defined(__GNUC__) && (__GNUC__ <= 3)
00041 #define EIGEN_GCC3_OR_OLDER 1
00042 #else
00043 #define EIGEN_GCC3_OR_OLDER 0
00044 #endif
00045 
00046 // 16 byte alignment is only useful for vectorization. Since it affects the ABI, we need to enable
00047 // 16 byte alignment on all platforms where vectorization might be enabled. In theory we could always
00048 // enable alignment, but it can be a cause of problems on some platforms, so we just disable it in
00049 // certain common platform (compiler+architecture combinations) to avoid these problems.
00050 // Only static alignment is really problematic (relies on nonstandard compiler extensions that don't
00051 // work everywhere, for example don't work on GCC/ARM), try to keep heap alignment even
00052 // when we have to disable static alignment.
00053 #if defined(__GNUC__) && !(defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__ppc__) || defined(__ia64__))
00054 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
00055 #else
00056 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0
00057 #endif
00058 
00059 // static alignment is completely disabled with GCC 3, Sun Studio, and QCC/QNX
00060 #if !EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT \
00061  && !EIGEN_GCC3_OR_OLDER \
00062  && !defined(__SUNPRO_CC) \
00063  && !defined(__QNXNTO__)
00064   #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 1
00065 #else
00066   #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 0
00067 #endif
00068 
00069 #ifdef EIGEN_DONT_ALIGN
00070   #ifndef EIGEN_DONT_ALIGN_STATICALLY
00071     #define EIGEN_DONT_ALIGN_STATICALLY
00072   #endif
00073   #define EIGEN_ALIGN 0
00074 #else
00075   #define EIGEN_ALIGN 1
00076 #endif
00077 
00078 // EIGEN_ALIGN_STATICALLY is the true test whether we want to align arrays on the stack or not. It takes into account both the user choice to explicitly disable
00079 // alignment (EIGEN_DONT_ALIGN_STATICALLY) and the architecture config (EIGEN_ARCH_WANTS_STACK_ALIGNMENT). Henceforth, only EIGEN_ALIGN_STATICALLY should be used.
00080 #if EIGEN_ARCH_WANTS_STACK_ALIGNMENT && !defined(EIGEN_DONT_ALIGN_STATICALLY)
00081   #define EIGEN_ALIGN_STATICALLY 1
00082 #else
00083   #define EIGEN_ALIGN_STATICALLY 0
00084   #ifndef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00085     #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00086   #endif
00087 #endif
00088 
00089 #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
00090 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION RowMajor
00091 #else
00092 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ColMajor
00093 #endif
00094 
00095 #ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
00096 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
00097 #endif
00098 
00104 #ifndef EIGEN_FAST_MATH
00105 #define EIGEN_FAST_MATH 1
00106 #endif
00107 
00108 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
00109 
00110 // concatenate two tokens
00111 #define EIGEN_CAT2(a,b) a ## b
00112 #define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
00113 
00114 // convert a token to a string
00115 #define EIGEN_MAKESTRING2(a) #a
00116 #define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
00117 
00118 // EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
00119 // but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
00120 // but GCC is still doing fine with just inline.
00121 #if (defined _MSC_VER) || (defined __INTEL_COMPILER)
00122 #define EIGEN_STRONG_INLINE __forceinline
00123 #else
00124 #define EIGEN_STRONG_INLINE inline
00125 #endif
00126 
00127 // EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible
00128 // attribute to maximize inlining. This should only be used when really necessary: in particular,
00129 // it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times.
00130 // FIXME with the always_inline attribute,
00131 // gcc 3.4.x reports the following compilation error:
00132 //   Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
00133 //    : function body not available
00134 #if EIGEN_GNUC_AT_LEAST(4,0)
00135 #define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
00136 #else
00137 #define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
00138 #endif
00139 
00140 #if (defined __GNUC__)
00141 #define EIGEN_DONT_INLINE __attribute__((noinline))
00142 #elif (defined _MSC_VER)
00143 #define EIGEN_DONT_INLINE __declspec(noinline)
00144 #else
00145 #define EIGEN_DONT_INLINE
00146 #endif
00147 
00148 #if (defined __GNUC__)
00149 #define EIGEN_PERMISSIVE_EXPR __extension__
00150 #else
00151 #define EIGEN_PERMISSIVE_EXPR
00152 #endif
00153 
00154 // this macro allows to get rid of linking errors about multiply defined functions.
00155 //  - static is not very good because it prevents definitions from different object files to be merged.
00156 //           So static causes the resulting linked executable to be bloated with multiple copies of the same function.
00157 //  - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
00158 #define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00159 #define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS inline
00160 
00161 #ifdef NDEBUG
00162 # ifndef EIGEN_NO_DEBUG
00163 #  define EIGEN_NO_DEBUG
00164 # endif
00165 #endif
00166 
00167 // eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89
00168 #ifdef EIGEN_NO_DEBUG
00169   #define eigen_plain_assert(x)
00170 #else
00171   #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO
00172     namespace Eigen {
00173     namespace internal {
00174     inline bool copy_bool(bool b) { return b; }
00175     }
00176     }
00177     #define eigen_plain_assert(x) assert(x)
00178   #else
00179     // work around bug 89
00180     #include <cstdlib>   // for abort
00181     #include <iostream>  // for std::cerr
00182 
00183     namespace Eigen {
00184     namespace internal {
00185     // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers.
00186     // see bug 89.
00187     namespace {
00188     EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; }
00189     }
00190     inline void assert_fail(const char *condition, const char *function, const char *file, int line)
00191     {
00192       std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl;
00193       abort();
00194     }
00195     }
00196     }
00197     #define eigen_plain_assert(x) \
00198       do { \
00199         if(!Eigen::internal::copy_bool(x)) \
00200           Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \
00201       } while(false)
00202   #endif
00203 #endif
00204 
00205 // eigen_assert can be overridden
00206 #ifndef eigen_assert
00207 #define eigen_assert(x) eigen_plain_assert(x)
00208 #endif
00209 
00210 #ifdef EIGEN_INTERNAL_DEBUGGING
00211 #define eigen_internal_assert(x) eigen_assert(x)
00212 #else
00213 #define eigen_internal_assert(x)
00214 #endif
00215 
00216 #ifdef EIGEN_NO_DEBUG
00217 #define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
00218 #else
00219 #define EIGEN_ONLY_USED_FOR_DEBUG(x)
00220 #endif
00221 
00222 #ifndef EIGEN_NO_DEPRECATED_WARNING
00223   #if (defined __GNUC__)
00224     #define EIGEN_DEPRECATED __attribute__((deprecated))
00225   #elif (defined _MSC_VER)
00226     #define EIGEN_DEPRECATED __declspec(deprecated)
00227   #else
00228     #define EIGEN_DEPRECATED
00229   #endif
00230 #else
00231   #define EIGEN_DEPRECATED
00232 #endif
00233 
00234 #if (defined __GNUC__)
00235 #define EIGEN_UNUSED __attribute__((unused))
00236 #else
00237 #define EIGEN_UNUSED
00238 #endif
00239 
00240 // Suppresses 'unused variable' warnings.
00241 #define EIGEN_UNUSED_VARIABLE(var) (void)var;
00242 
00243 #if !defined(EIGEN_ASM_COMMENT)
00244   #if (defined __GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
00245     #define EIGEN_ASM_COMMENT(X)  asm("#" X)
00246   #else
00247     #define EIGEN_ASM_COMMENT(X)
00248   #endif
00249 #endif
00250 
00251 /* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements.
00252  * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled,
00253  * so that vectorization doesn't affect binary compatibility.
00254  *
00255  * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link
00256  * vectorized and non-vectorized code.
00257  */
00258 #if (defined __GNUC__) || (defined __PGI) || (defined __IBMCPP__) || (defined __ARMCC_VERSION)
00259   #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
00260 #elif (defined _MSC_VER)
00261   #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
00262 #elif (defined __SUNPRO_CC)
00263   // FIXME not sure about this one:
00264   #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
00265 #else
00266   #error Please tell me what is the equivalent of __attribute__((aligned(n))) for your compiler
00267 #endif
00268 
00269 #define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16)
00270 
00271 #if EIGEN_ALIGN_STATICALLY
00272 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n) EIGEN_ALIGN_TO_BOUNDARY(n)
00273 #define EIGEN_USER_ALIGN16 EIGEN_ALIGN16
00274 #else
00275 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n)
00276 #define EIGEN_USER_ALIGN16
00277 #endif
00278 
00279 #ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
00280   #define EIGEN_RESTRICT
00281 #endif
00282 #ifndef EIGEN_RESTRICT
00283   #define EIGEN_RESTRICT __restrict
00284 #endif
00285 
00286 #ifndef EIGEN_STACK_ALLOCATION_LIMIT
00287 #define EIGEN_STACK_ALLOCATION_LIMIT 20000
00288 #endif
00289 
00290 #ifndef EIGEN_DEFAULT_IO_FORMAT
00291 #ifdef EIGEN_MAKING_DOCS
00292 // format used in Eigen's documentation
00293 // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
00294 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
00295 #else
00296 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
00297 #endif
00298 #endif
00299 
00300 // just an empty macro !
00301 #define EIGEN_EMPTY
00302 
00303 #if defined(_MSC_VER) && (!defined(__INTEL_COMPILER))
00304 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
00305   using Base::operator =;
00306 #elif defined(__clang__) // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653)
00307 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
00308   using Base::operator =; \
00309   EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
00310   template <typename OtherDerived> \
00311   EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
00312 #else
00313 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
00314   using Base::operator =; \
00315   EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
00316   { \
00317     Base::operator=(other); \
00318     return *this; \
00319   }
00320 #endif
00321 
00322 #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
00323   EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
00324 
00333 #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
00334   typedef typename Eigen::internal::traits<Derived>::Scalar Scalar;  \
00335   typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;  \
00336   typedef typename Base::CoeffReturnType CoeffReturnType;  \
00337   typedef typename Eigen::internal::nested<Derived>::type Nested; \
00338   typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
00339   typedef typename Eigen::internal::traits<Derived>::Index Index; \
00340   enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
00341         ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
00342         Flags = Eigen::internal::traits<Derived>::Flags, \
00343         CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
00344         SizeAtCompileTime = Base::SizeAtCompileTime, \
00345         MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
00346         IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
00347 
00348 
00349 #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
00350   typedef typename Eigen::internal::traits<Derived>::Scalar Scalar;  \
00351   typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;  \
00352   typedef typename Base::PacketScalar PacketScalar; \
00353   typedef typename Base::CoeffReturnType CoeffReturnType;  \
00354   typedef typename Eigen::internal::nested<Derived>::type Nested; \
00355   typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
00356   typedef typename Eigen::internal::traits<Derived>::Index Index; \
00357   enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
00358         ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
00359         MaxRowsAtCompileTime = Eigen::internal::traits<Derived>::MaxRowsAtCompileTime, \
00360         MaxColsAtCompileTime = Eigen::internal::traits<Derived>::MaxColsAtCompileTime, \
00361         Flags = Eigen::internal::traits<Derived>::Flags, \
00362         CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
00363         SizeAtCompileTime = Base::SizeAtCompileTime, \
00364         MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
00365         IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
00366   using Base::derived; \
00367   using Base::const_cast_derived;
00368 
00369 
00370 #define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
00371 #define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
00372 
00373 // EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
00374 // followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
00375 // finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
00376 #define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
00377                            : ((int)a == 1 || (int)b == 1) ? 1 \
00378                            : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
00379                            : ((int)a <= (int)b) ? (int)a : (int)b)
00380 
00381 // EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
00382 // now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
00383 // (between 0 and 3), it is not more than 3.
00384 #define EIGEN_SIZE_MIN_PREFER_FIXED(a,b)  (((int)a == 0 || (int)b == 0) ? 0 \
00385                            : ((int)a == 1 || (int)b == 1) ? 1 \
00386                            : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
00387                            : ((int)a == Dynamic) ? (int)b \
00388                            : ((int)b == Dynamic) ? (int)a \
00389                            : ((int)a <= (int)b) ? (int)a : (int)b)
00390 
00391 // see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
00392 #define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
00393                            : ((int)a >= (int)b) ? (int)a : (int)b)
00394 
00395 #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
00396 
00397 #define EIGEN_IMPLIES(a,b) (!(a) || (b))
00398 
00399 #define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
00400   template<typename OtherDerived> \
00401   EIGEN_STRONG_INLINE const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived> \
00402   (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
00403   { \
00404     return CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); \
00405   }
00406 
00407 // the expression type of a cwise product
00408 #define EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS) \
00409     CwiseBinaryOp< \
00410       internal::scalar_product_op< \
00411           typename internal::traits<LHS>::Scalar, \
00412           typename internal::traits<RHS>::Scalar \
00413       >, \
00414       const LHS, \
00415       const RHS \
00416     >
00417 
00418 #endif // EIGEN_MACROS_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:37:54