Main MRPT website > C++ reference
MRPT logo

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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_MACROS_H
00027 #define EIGEN_MACROS_H
00028 
00029 #define EIGEN_WORLD_VERSION 2
00030 #define EIGEN_MAJOR_VERSION 92
00031 #define EIGEN_MINOR_VERSION 0
00032 
00033 #define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \
00034                                       (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \
00035                                                                  EIGEN_MINOR_VERSION>=z))))
00036 #ifdef __GNUC__
00037   #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__>=x && __GNUC_MINOR__>=y) || __GNUC__>x)
00038 #else
00039   #define EIGEN_GNUC_AT_LEAST(x,y) 0
00040 #endif
00041 
00042 #if defined(__GNUC__) && (__GNUC__ <= 3)
00043 #define EIGEN_GCC3_OR_OLDER 1
00044 #else
00045 #define EIGEN_GCC3_OR_OLDER 0
00046 #endif
00047 
00048 // 16 byte alignment is only useful for vectorization. Since it affects the ABI, we need to enable
00049 // 16 byte alignment on all platforms where vectorization might be enabled. In theory we could always
00050 // enable alignment, but it can be a cause of problems on some platforms, so we just disable it in
00051 // certain common platform (compiler+architecture combinations) to avoid these problems.
00052 // Only static alignment is really problematic (relies on nonstandard compiler extensions that don't
00053 // work everywhere, for example don't work on GCC/ARM), try to keep heap alignment even
00054 // when we have to disable static alignment.
00055 #if defined(__GNUC__) && !(defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__ppc__) || defined(__ia64__))
00056 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
00057 #else
00058 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0
00059 #endif
00060 
00061 // static alignment is completely disabled with GCC 3, Sun Studio, and QCC/QNX
00062 #if !EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT \
00063  && !EIGEN_GCC3_OR_OLDER \
00064  && !defined(__SUNPRO_CC) \
00065  && !defined(__QNXNTO__)
00066   #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 1
00067 #else
00068   #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 0
00069 #endif
00070 
00071 #ifdef EIGEN_DONT_ALIGN
00072   #ifndef EIGEN_DONT_ALIGN_STATICALLY
00073     #define EIGEN_DONT_ALIGN_STATICALLY
00074   #endif
00075   #define EIGEN_ALIGN 0
00076 #else
00077   #define EIGEN_ALIGN 1
00078 #endif
00079 
00080 // 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
00081 // alignment (EIGEN_DONT_ALIGN_STATICALLY) and the architecture config (EIGEN_ARCH_WANTS_STACK_ALIGNMENT). Henceforth, only EIGEN_ALIGN_STATICALLY should be used.
00082 #if EIGEN_ARCH_WANTS_STACK_ALIGNMENT && !defined(EIGEN_DONT_ALIGN_STATICALLY)
00083   #define EIGEN_ALIGN_STATICALLY 1
00084 #else
00085   #define EIGEN_ALIGN_STATICALLY 0
00086   #ifndef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00087     #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
00088   #endif
00089 #endif
00090 
00091 #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
00092 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION RowMajor
00093 #else
00094 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ColMajor
00095 #endif
00096 
00097 #ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
00098 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
00099 #endif
00100 
00101 /** Allows to disable some optimizations which might affect the accuracy of the result.
00102   * Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them.
00103   * They currently include:
00104   *   - single precision Cwise::sin() and Cwise::cos() when SSE vectorization is enabled.
00105   */
00106 #ifndef EIGEN_FAST_MATH
00107 #define EIGEN_FAST_MATH 1
00108 #endif
00109 
00110 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
00111 
00112 #ifdef NDEBUG
00113 # ifndef EIGEN_NO_DEBUG
00114 #  define EIGEN_NO_DEBUG
00115 # endif
00116 #endif
00117 
00118 #ifndef eigen_assert
00119 #ifdef EIGEN_NO_DEBUG
00120 #define eigen_assert(x)
00121 #else
00122 #define eigen_assert(x) assert(x)
00123 #endif
00124 #endif
00125 
00126 #ifdef EIGEN_INTERNAL_DEBUGGING
00127 #define eigen_internal_assert(x) eigen_assert(x)
00128 #else
00129 #define eigen_internal_assert(x)
00130 #endif
00131 
00132 #ifdef EIGEN_NO_DEBUG
00133 #define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
00134 #else
00135 #define EIGEN_ONLY_USED_FOR_DEBUG(x)
00136 #endif
00137 
00138 // EIGEN_ALWAYS_INLINE_ATTRIB should be use in the declaration of function
00139 // which should be inlined even in debug mode.
00140 // FIXME with the always_inline attribute,
00141 // gcc 3.4.x reports the following compilation error:
00142 //   Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
00143 //    : function body not available
00144 #if EIGEN_GNUC_AT_LEAST(4,0)
00145 #define EIGEN_ALWAYS_INLINE_ATTRIB __attribute__((always_inline))
00146 #else
00147 #define EIGEN_ALWAYS_INLINE_ATTRIB
00148 #endif
00149 
00150 #if EIGEN_GNUC_AT_LEAST(4,1)
00151 #define EIGEN_FLATTEN_ATTRIB __attribute__((flatten))
00152 #else
00153 #define EIGEN_FLATTEN_ATTRIB
00154 #endif
00155 
00156 // EIGEN_FORCE_INLINE means "inline as much as possible"
00157 #if (defined _MSC_VER) || (defined __intel_compiler)
00158 #define EIGEN_STRONG_INLINE __forceinline
00159 #else
00160 #define EIGEN_STRONG_INLINE inline
00161 #endif
00162 
00163 #if (defined __GNUC__)
00164 #define EIGEN_DONT_INLINE __attribute__((noinline))
00165 #elif (defined _MSC_VER)
00166 #define EIGEN_DONT_INLINE __declspec(noinline)
00167 #else
00168 #define EIGEN_DONT_INLINE
00169 #endif
00170 
00171 // this macro allows to get rid of linking errors about multiply defined functions.
00172 //  - static is not very good because it prevents definitions from different object files to be merged.
00173 //           So static causes the resulting linked executable to be bloated with multiple copies of the same function.
00174 //  - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
00175 #define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
00176 #define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS inline
00177 
00178 #if (defined __GNUC__)
00179 #define EIGEN_DEPRECATED __attribute__((deprecated))
00180 #elif (defined _MSC_VER)
00181 #define EIGEN_DEPRECATED __declspec(deprecated)
00182 #else
00183 #define EIGEN_DEPRECATED
00184 #endif
00185 
00186 #if (defined __GNUC__)
00187 #define EIGEN_UNUSED __attribute__((unused))
00188 #else
00189 #define EIGEN_UNUSED
00190 #endif
00191 
00192 // Suppresses 'unused variable' warnings.
00193 #define EIGEN_UNUSED_VARIABLE(var) (void)var;
00194 
00195 #if (defined __GNUC__)
00196 #define EIGEN_ASM_COMMENT(X)  asm("#"X)
00197 #else
00198 #define EIGEN_ASM_COMMENT(X)
00199 #endif
00200 
00201 /* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements.
00202  * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled,
00203  * so that vectorization doesn't affect binary compatibility.
00204  *
00205  * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link
00206  * vectorized and non-vectorized code.
00207  */
00208 #if !EIGEN_ALIGN_STATICALLY
00209   #define EIGEN_ALIGN_TO_BOUNDARY(n)
00210 #elif (defined __GNUC__) || (defined __PGI) || (defined __IBMCPP__)
00211   #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
00212 #elif (defined _MSC_VER)
00213   #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
00214 #elif (defined __SUNPRO_CC)
00215   // FIXME not sure about this one:
00216   #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
00217 #else
00218   #error Please tell me what is the equivalent of __attribute__((aligned(n))) for your compiler
00219 #endif
00220 
00221 #define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16)
00222 
00223 #ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
00224   #define EIGEN_RESTRICT
00225 #endif
00226 #ifndef EIGEN_RESTRICT
00227   #define EIGEN_RESTRICT __restrict
00228 #endif
00229 
00230 #ifndef EIGEN_STACK_ALLOCATION_LIMIT
00231 #define EIGEN_STACK_ALLOCATION_LIMIT 20000
00232 #endif
00233 
00234 #ifndef EIGEN_DEFAULT_IO_FORMAT
00235 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
00236 #endif
00237 
00238 // just an empty macro !
00239 #define EIGEN_EMPTY
00240 
00241 // concatenate two tokens
00242 #define EIGEN_CAT2(a,b) a ## b
00243 #define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
00244 
00245 // convert a token to a string
00246 #define EIGEN_MAKESTRING2(a) #a
00247 #define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
00248 
00249 // format used in Eigen's documentation
00250 // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
00251 #define EIGEN_DOCS_IO_FORMAT IOFormat(3, 0, " ", "\n", "", "")
00252 
00253 #if defined(_MSC_VER) && (!defined(__INTEL_COMPILER))
00254 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
00255   using Base::operator =;
00256 #else
00257 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
00258   using Base::operator =; \
00259   EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
00260   { \
00261     Base::operator=(other); \
00262     return *this; \
00263   }
00264 #endif
00265 
00266 #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
00267   EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
00268 
00269 /**
00270 * Just a side note. Commenting within defines works only by documenting
00271 * behind the object (via '!<'). Comments cannot be multi-line and thus
00272 * we have these extra long lines. What is confusing doxygen over here is
00273 * that we use '\' and basically have a bunch of typedefs with their
00274 * documentation in a single line.
00275 **/
00276 
00277 #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
00278   typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \
00279   typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \
00280   typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \
00281   typedef typename Eigen::internal::nested<Derived>::type Nested; \
00282   typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
00283   typedef typename Eigen::internal::traits<Derived>::Index Index; \
00284   enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
00285         ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
00286         Flags = Eigen::internal::traits<Derived>::Flags, \
00287         CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
00288         SizeAtCompileTime = Base::SizeAtCompileTime, \
00289         MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
00290         IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
00291 
00292 
00293 #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
00294   typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \
00295   typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!< \brief The underlying numeric type for composed scalar types. \details In cases where Scalar is e.g. std::complex<T>, T were corresponding to RealScalar. */ \
00296   typedef typename Base::PacketScalar PacketScalar; \
00297   typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ \
00298   typedef typename Eigen::internal::nested<Derived>::type Nested; \
00299   typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
00300   typedef typename Eigen::internal::traits<Derived>::Index Index; \
00301   enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
00302         ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
00303         MaxRowsAtCompileTime = Eigen::internal::traits<Derived>::MaxRowsAtCompileTime, \
00304         MaxColsAtCompileTime = Eigen::internal::traits<Derived>::MaxColsAtCompileTime, \
00305         Flags = Eigen::internal::traits<Derived>::Flags, \
00306         CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
00307         SizeAtCompileTime = Base::SizeAtCompileTime, \
00308         MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
00309         IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
00310   using Base::derived; \
00311   using Base::const_cast_derived;
00312 
00313 
00314 #define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
00315 #define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
00316 
00317 // EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
00318 // followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
00319 // finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
00320 #define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
00321                            : ((int)a == 1 || (int)b == 1) ? 1 \
00322                            : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
00323                            : ((int)a <= (int)b) ? (int)a : (int)b)
00324 
00325 // EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
00326 // now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
00327 // (between 0 and 3), it is not more than 3.
00328 #define EIGEN_SIZE_MIN_PREFER_FIXED(a,b)  (((int)a == 0 || (int)b == 0) ? 0 \
00329                            : ((int)a == 1 || (int)b == 1) ? 1 \
00330                            : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
00331                            : ((int)a == Dynamic) ? (int)b \
00332                            : ((int)b == Dynamic) ? (int)a \
00333                            : ((int)a <= (int)b) ? (int)a : (int)b)
00334 
00335 // see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
00336 #define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
00337                            : ((int)a >= (int)b) ? (int)a : (int)b)
00338 
00339 #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
00340 
00341 #define EIGEN_IMPLIES(a,b) (!(a) || (b))
00342 
00343 #define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
00344   template<typename OtherDerived> \
00345   EIGEN_STRONG_INLINE const CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived> \
00346   METHOD(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
00347   { \
00348     return CwiseBinaryOp<FUNCTOR<Scalar>, Derived, OtherDerived>(derived(), other.derived()); \
00349   }
00350 
00351 // the expression type of a cwise product
00352 #define EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS) \
00353     CwiseBinaryOp< \
00354       internal::scalar_product_op< \
00355           typename internal::traits<LHS>::Scalar, \
00356           typename internal::traits<RHS>::Scalar \
00357       >, \
00358       LHS, \
00359       RHS \
00360     >
00361 
00362 #endif // EIGEN_MACROS_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011