Eigen  3.2.7
Macros.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_MACROS_H
12 #define EIGEN_MACROS_H
13 
14 #define EIGEN_WORLD_VERSION 3
15 #define EIGEN_MAJOR_VERSION 2
16 #define EIGEN_MINOR_VERSION 7
17 
18 #define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \
19  (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \
20  EIGEN_MINOR_VERSION>=z))))
21 #ifdef __GNUC__
22  #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__==x && __GNUC_MINOR__>=y) || __GNUC__>x)
23 #else
24  #define EIGEN_GNUC_AT_LEAST(x,y) 0
25 #endif
26 
27 #ifdef __GNUC__
28  #define EIGEN_GNUC_AT_MOST(x,y) ((__GNUC__==x && __GNUC_MINOR__<=y) || __GNUC__<x)
29 #else
30  #define EIGEN_GNUC_AT_MOST(x,y) 0
31 #endif
32 
33 #if EIGEN_GNUC_AT_MOST(4,3) && !defined(__clang__)
34  // see bug 89
35  #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 0
36 #else
37  #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 1
38 #endif
39 
40 #if defined(__GNUC__) && (__GNUC__ <= 3)
41 #define EIGEN_GCC3_OR_OLDER 1
42 #else
43 #define EIGEN_GCC3_OR_OLDER 0
44 #endif
45 
46 // 16 byte alignment is only useful for vectorization. Since it affects the ABI, we need to enable
47 // 16 byte alignment on all platforms where vectorization might be enabled. In theory we could always
48 // enable alignment, but it can be a cause of problems on some platforms, so we just disable it in
49 // certain common platform (compiler+architecture combinations) to avoid these problems.
50 // Only static alignment is really problematic (relies on nonstandard compiler extensions that don't
51 // work everywhere, for example don't work on GCC/ARM), try to keep heap alignment even
52 // when we have to disable static alignment.
53 #if defined(__GNUC__) && !(defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__ppc__) || defined(__ia64__))
54 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
55 #else
56 #define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0
57 #endif
58 
59 // static alignment is completely disabled with GCC 3, Sun Studio, and QCC/QNX
60 #if !EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT \
61  && !EIGEN_GCC3_OR_OLDER \
62  && !defined(__SUNPRO_CC) \
63  && !defined(__QNXNTO__)
64  #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 1
65 #else
66  #define EIGEN_ARCH_WANTS_STACK_ALIGNMENT 0
67 #endif
68 
69 #ifdef EIGEN_DONT_ALIGN
70  #ifndef EIGEN_DONT_ALIGN_STATICALLY
71  #define EIGEN_DONT_ALIGN_STATICALLY
72  #endif
73  #define EIGEN_ALIGN 0
74 #else
75  #define EIGEN_ALIGN 1
76 #endif
77 
78 // 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
79 // alignment (EIGEN_DONT_ALIGN_STATICALLY) and the architecture config (EIGEN_ARCH_WANTS_STACK_ALIGNMENT). Henceforth, only EIGEN_ALIGN_STATICALLY should be used.
80 #if EIGEN_ARCH_WANTS_STACK_ALIGNMENT && !defined(EIGEN_DONT_ALIGN_STATICALLY)
81  #define EIGEN_ALIGN_STATICALLY 1
82 #else
83  #define EIGEN_ALIGN_STATICALLY 0
84  #ifndef EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
85  #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
86  #endif
87 #endif
88 
89 #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
90 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION RowMajor
91 #else
92 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION ColMajor
93 #endif
94 
95 #ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
96 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
97 #endif
98 
99 // A Clang feature extension to determine compiler features.
100 // We use it to determine 'cxx_rvalue_references'
101 #ifndef __has_feature
102 # define __has_feature(x) 0
103 #endif
104 
105 // Do we support r-value references?
106 #if (__has_feature(cxx_rvalue_references) || \
107  defined(__GXX_EXPERIMENTAL_CXX0X__) || \
108  (defined(_MSC_VER) && _MSC_VER >= 1600))
109  #define EIGEN_HAVE_RVALUE_REFERENCES
110 #endif
111 
112 
113 // Cross compiler wrapper around LLVM's __has_builtin
114 #ifdef __has_builtin
115 # define EIGEN_HAS_BUILTIN(x) __has_builtin(x)
116 #else
117 # define EIGEN_HAS_BUILTIN(x) 0
118 #endif
119 
125 #ifndef EIGEN_FAST_MATH
126 #define EIGEN_FAST_MATH 1
127 #endif
128 
129 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
130 
131 // concatenate two tokens
132 #define EIGEN_CAT2(a,b) a ## b
133 #define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
134 
135 // convert a token to a string
136 #define EIGEN_MAKESTRING2(a) #a
137 #define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
138 
139 // EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
140 // but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
141 // but GCC is still doing fine with just inline.
142 #if (defined _MSC_VER) || (defined __INTEL_COMPILER)
143 #define EIGEN_STRONG_INLINE __forceinline
144 #else
145 #define EIGEN_STRONG_INLINE inline
146 #endif
147 
148 // EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible
149 // attribute to maximize inlining. This should only be used when really necessary: in particular,
150 // it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times.
151 // FIXME with the always_inline attribute,
152 // gcc 3.4.x reports the following compilation error:
153 // Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
154 // : function body not available
155 #if EIGEN_GNUC_AT_LEAST(4,0)
156 #define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
157 #else
158 #define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
159 #endif
160 
161 #if (defined __GNUC__)
162 #define EIGEN_DONT_INLINE __attribute__((noinline))
163 #elif (defined _MSC_VER)
164 #define EIGEN_DONT_INLINE __declspec(noinline)
165 #else
166 #define EIGEN_DONT_INLINE
167 #endif
168 
169 #if (defined __GNUC__)
170 #define EIGEN_PERMISSIVE_EXPR __extension__
171 #else
172 #define EIGEN_PERMISSIVE_EXPR
173 #endif
174 
175 // this macro allows to get rid of linking errors about multiply defined functions.
176 // - static is not very good because it prevents definitions from different object files to be merged.
177 // So static causes the resulting linked executable to be bloated with multiple copies of the same function.
178 // - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
179 #define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
180 #define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS inline
181 
182 #ifdef NDEBUG
183 # ifndef EIGEN_NO_DEBUG
184 # define EIGEN_NO_DEBUG
185 # endif
186 #endif
187 
188 // eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89
189 #ifdef EIGEN_NO_DEBUG
190  #define eigen_plain_assert(x)
191 #else
192  #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO
193  namespace Eigen {
194  namespace internal {
195  inline bool copy_bool(bool b) { return b; }
196  }
197  }
198  #define eigen_plain_assert(x) assert(x)
199  #else
200  // work around bug 89
201  #include <cstdlib> // for abort
202  #include <iostream> // for std::cerr
203 
204  namespace Eigen {
205  namespace internal {
206  // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers.
207  // see bug 89.
208  namespace {
209  EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; }
210  }
211  inline void assert_fail(const char *condition, const char *function, const char *file, int line)
212  {
213  std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl;
214  abort();
215  }
216  }
217  }
218  #define eigen_plain_assert(x) \
219  do { \
220  if(!Eigen::internal::copy_bool(x)) \
221  Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \
222  } while(false)
223  #endif
224 #endif
225 
226 // eigen_assert can be overridden
227 #ifndef eigen_assert
228 #define eigen_assert(x) eigen_plain_assert(x)
229 #endif
230 
231 #ifdef EIGEN_INTERNAL_DEBUGGING
232 #define eigen_internal_assert(x) eigen_assert(x)
233 #else
234 #define eigen_internal_assert(x)
235 #endif
236 
237 #ifdef EIGEN_NO_DEBUG
238 #define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
239 #else
240 #define EIGEN_ONLY_USED_FOR_DEBUG(x)
241 #endif
242 
243 #ifndef EIGEN_NO_DEPRECATED_WARNING
244  #if (defined __GNUC__)
245  #define EIGEN_DEPRECATED __attribute__((deprecated))
246  #elif (defined _MSC_VER)
247  #define EIGEN_DEPRECATED __declspec(deprecated)
248  #else
249  #define EIGEN_DEPRECATED
250  #endif
251 #else
252  #define EIGEN_DEPRECATED
253 #endif
254 
255 #if (defined __GNUC__)
256 #define EIGEN_UNUSED __attribute__((unused))
257 #else
258 #define EIGEN_UNUSED
259 #endif
260 
261 // Suppresses 'unused variable' warnings.
262 namespace Eigen {
263  namespace internal {
264  template<typename T> void ignore_unused_variable(const T&) {}
265  }
266 }
267 #define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var);
268 
269 #if !defined(EIGEN_ASM_COMMENT)
270  #if (defined __GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
271  #define EIGEN_ASM_COMMENT(X) __asm__("#" X)
272  #else
273  #define EIGEN_ASM_COMMENT(X)
274  #endif
275 #endif
276 
277 /* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements.
278  * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled,
279  * so that vectorization doesn't affect binary compatibility.
280  *
281  * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link
282  * vectorized and non-vectorized code.
283  */
284 #if (defined __GNUC__) || (defined __PGI) || (defined __IBMCPP__) || (defined __ARMCC_VERSION)
285  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
286 #elif (defined _MSC_VER)
287  #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
288 #elif (defined __SUNPRO_CC)
289  // FIXME not sure about this one:
290  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
291 #else
292  #error Please tell me what is the equivalent of __attribute__((aligned(n))) for your compiler
293 #endif
294 
295 #define EIGEN_ALIGN8 EIGEN_ALIGN_TO_BOUNDARY(8)
296 #define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16)
297 
298 #if EIGEN_ALIGN_STATICALLY
299 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n) EIGEN_ALIGN_TO_BOUNDARY(n)
300 #define EIGEN_USER_ALIGN16 EIGEN_ALIGN16
301 #else
302 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n)
303 #define EIGEN_USER_ALIGN16
304 #endif
305 
306 #ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
307  #define EIGEN_RESTRICT
308 #endif
309 #ifndef EIGEN_RESTRICT
310  #define EIGEN_RESTRICT __restrict
311 #endif
312 
313 #ifndef EIGEN_STACK_ALLOCATION_LIMIT
314 // 131072 == 128 KB
315 #define EIGEN_STACK_ALLOCATION_LIMIT 131072
316 #endif
317 
318 #ifndef EIGEN_DEFAULT_IO_FORMAT
319 #ifdef EIGEN_MAKING_DOCS
320 // format used in Eigen's documentation
321 // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
322 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
323 #else
324 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
325 #endif
326 #endif
327 
328 // just an empty macro !
329 #define EIGEN_EMPTY
330 
331 #if defined(_MSC_VER) && (_MSC_VER < 1900) && (!defined(__INTEL_COMPILER))
332 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
333  using Base::operator =;
334 #elif defined(__clang__) // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653)
335 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
336  using Base::operator =; \
337  EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
338  template <typename OtherDerived> \
339  EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
340 #else
341 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
342  using Base::operator =; \
343  EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
344  { \
345  Base::operator=(other); \
346  return *this; \
347  }
348 #endif
349 
354 #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
355 
364 #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
365  typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \
366  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
367  typedef typename Base::CoeffReturnType CoeffReturnType; \
368  typedef typename Eigen::internal::nested<Derived>::type Nested; \
369  typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
370  typedef typename Eigen::internal::traits<Derived>::Index Index; \
371  enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
372  ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
373  Flags = Eigen::internal::traits<Derived>::Flags, \
374  CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
375  SizeAtCompileTime = Base::SizeAtCompileTime, \
376  MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
377  IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
378 
379 
380 #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
381  typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \
382  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
383  typedef typename Base::PacketScalar PacketScalar; \
384  typedef typename Base::CoeffReturnType CoeffReturnType; \
385  typedef typename Eigen::internal::nested<Derived>::type Nested; \
386  typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
387  typedef typename Eigen::internal::traits<Derived>::Index Index; \
388  enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
389  ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
390  MaxRowsAtCompileTime = Eigen::internal::traits<Derived>::MaxRowsAtCompileTime, \
391  MaxColsAtCompileTime = Eigen::internal::traits<Derived>::MaxColsAtCompileTime, \
392  Flags = Eigen::internal::traits<Derived>::Flags, \
393  CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
394  SizeAtCompileTime = Base::SizeAtCompileTime, \
395  MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
396  IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
397  using Base::derived; \
398  using Base::const_cast_derived;
399 
400 
401 #define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
402 #define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
403 
404 // EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
405 // followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
406 // finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
407 #define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
408  : ((int)a == 1 || (int)b == 1) ? 1 \
409  : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
410  : ((int)a <= (int)b) ? (int)a : (int)b)
411 
412 // EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
413 // now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
414 // (between 0 and 3), it is not more than 3.
415 #define EIGEN_SIZE_MIN_PREFER_FIXED(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
416  : ((int)a == 1 || (int)b == 1) ? 1 \
417  : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
418  : ((int)a == Dynamic) ? (int)b \
419  : ((int)b == Dynamic) ? (int)a \
420  : ((int)a <= (int)b) ? (int)a : (int)b)
421 
422 // see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
423 #define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
424  : ((int)a >= (int)b) ? (int)a : (int)b)
425 
426 #define EIGEN_ADD_COST(a,b) int(a)==Dynamic || int(b)==Dynamic ? Dynamic : int(a)+int(b)
427 
428 #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
429 
430 #define EIGEN_IMPLIES(a,b) (!(a) || (b))
431 
432 #define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
433  template<typename OtherDerived> \
434  EIGEN_STRONG_INLINE const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived> \
435  (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
436  { \
437  return CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); \
438  }
439 
440 // the expression type of a cwise product
441 #define EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS) \
442  CwiseBinaryOp< \
443  internal::scalar_product_op< \
444  typename internal::traits<LHS>::Scalar, \
445  typename internal::traits<RHS>::Scalar \
446  >, \
447  const LHS, \
448  const RHS \
449  >
450 
451 #endif // EIGEN_MACROS_H
Definition: LDLT.h:16
Definition: Eigen_Colamd.h:54