Core/util/Macros.h
Go to the documentation of this file.
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 0
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 
104 #ifndef EIGEN_FAST_MATH
105 #define EIGEN_FAST_MATH 1
106 #endif
107 
108 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
109 
110 // concatenate two tokens
111 #define EIGEN_CAT2(a,b) a ## b
112 #define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
113 
114 // convert a token to a string
115 #define EIGEN_MAKESTRING2(a) #a
116 #define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
117 
118 // EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
119 // but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
120 // but GCC is still doing fine with just inline.
121 #if (defined _MSC_VER) || (defined __INTEL_COMPILER)
122 #define EIGEN_STRONG_INLINE __forceinline
123 #else
124 #define EIGEN_STRONG_INLINE inline
125 #endif
126 
127 // EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible
128 // attribute to maximize inlining. This should only be used when really necessary: in particular,
129 // it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times.
130 // FIXME with the always_inline attribute,
131 // gcc 3.4.x reports the following compilation error:
132 // Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
133 // : function body not available
134 #if EIGEN_GNUC_AT_LEAST(4,0)
135 #define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
136 #else
137 #define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
138 #endif
139 
140 #if (defined __GNUC__)
141 #define EIGEN_DONT_INLINE __attribute__((noinline))
142 #elif (defined _MSC_VER)
143 #define EIGEN_DONT_INLINE __declspec(noinline)
144 #else
145 #define EIGEN_DONT_INLINE
146 #endif
147 
148 #if (defined __GNUC__)
149 #define EIGEN_PERMISSIVE_EXPR __extension__
150 #else
151 #define EIGEN_PERMISSIVE_EXPR
152 #endif
153 
154 // this macro allows to get rid of linking errors about multiply defined functions.
155 // - static is not very good because it prevents definitions from different object files to be merged.
156 // So static causes the resulting linked executable to be bloated with multiple copies of the same function.
157 // - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
158 #define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
159 #define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS inline
160 
161 #ifdef NDEBUG
162 # ifndef EIGEN_NO_DEBUG
163 # define EIGEN_NO_DEBUG
164 # endif
165 #endif
166 
167 // eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89
168 #ifdef EIGEN_NO_DEBUG
169  #define eigen_plain_assert(x)
170 #else
171  #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO
172  namespace Eigen {
173  namespace internal {
174  inline bool copy_bool(bool b) { return b; }
175  }
176  }
177  #define eigen_plain_assert(x) assert(x)
178  #else
179  // work around bug 89
180  #include <cstdlib> // for abort
181  #include <iostream> // for std::cerr
182 
183  namespace Eigen {
184  namespace internal {
185  // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers.
186  // see bug 89.
187  namespace {
188  EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; }
189  }
190  inline void assert_fail(const char *condition, const char *function, const char *file, int line)
191  {
192  std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl;
193  abort();
194  }
195  }
196  }
197  #define eigen_plain_assert(x) \
198  do { \
199  if(!Eigen::internal::copy_bool(x)) \
200  Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \
201  } while(false)
202  #endif
203 #endif
204 
205 // eigen_assert can be overridden
206 #ifndef eigen_assert
207 #define eigen_assert(x) eigen_plain_assert(x)
208 #endif
209 
210 #ifdef EIGEN_INTERNAL_DEBUGGING
211 #define eigen_internal_assert(x) eigen_assert(x)
212 #else
213 #define eigen_internal_assert(x)
214 #endif
215 
216 #ifdef EIGEN_NO_DEBUG
217 #define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
218 #else
219 #define EIGEN_ONLY_USED_FOR_DEBUG(x)
220 #endif
221 
222 #ifndef EIGEN_NO_DEPRECATED_WARNING
223  #if (defined __GNUC__)
224  #define EIGEN_DEPRECATED __attribute__((deprecated))
225  #elif (defined _MSC_VER)
226  #define EIGEN_DEPRECATED __declspec(deprecated)
227  #else
228  #define EIGEN_DEPRECATED
229  #endif
230 #else
231  #define EIGEN_DEPRECATED
232 #endif
233 
234 #if (defined __GNUC__)
235 #define EIGEN_UNUSED __attribute__((unused))
236 #else
237 #define EIGEN_UNUSED
238 #endif
239 
240 // Suppresses 'unused variable' warnings.
241 #define EIGEN_UNUSED_VARIABLE(var) (void)var;
242 
243 #if !defined(EIGEN_ASM_COMMENT)
244  #if (defined __GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
245  #define EIGEN_ASM_COMMENT(X) asm("#" X)
246  #else
247  #define EIGEN_ASM_COMMENT(X)
248  #endif
249 #endif
250 
251 /* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements.
252  * However, we do that EVEN if vectorization (EIGEN_VECTORIZE) is disabled,
253  * so that vectorization doesn't affect binary compatibility.
254  *
255  * If we made alignment depend on whether or not EIGEN_VECTORIZE is defined, it would be impossible to link
256  * vectorized and non-vectorized code.
257  */
258 #if (defined __GNUC__) || (defined __PGI) || (defined __IBMCPP__) || (defined __ARMCC_VERSION)
259  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
260 #elif (defined _MSC_VER)
261  #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
262 #elif (defined __SUNPRO_CC)
263  // FIXME not sure about this one:
264  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
265 #else
266  #error Please tell me what is the equivalent of __attribute__((aligned(n))) for your compiler
267 #endif
268 
269 #define EIGEN_ALIGN16 EIGEN_ALIGN_TO_BOUNDARY(16)
270 
271 #if EIGEN_ALIGN_STATICALLY
272 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n) EIGEN_ALIGN_TO_BOUNDARY(n)
273 #define EIGEN_USER_ALIGN16 EIGEN_ALIGN16
274 #else
275 #define EIGEN_USER_ALIGN_TO_BOUNDARY(n)
276 #define EIGEN_USER_ALIGN16
277 #endif
278 
279 #ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
280  #define EIGEN_RESTRICT
281 #endif
282 #ifndef EIGEN_RESTRICT
283  #define EIGEN_RESTRICT __restrict
284 #endif
285 
286 #ifndef EIGEN_STACK_ALLOCATION_LIMIT
287 #define EIGEN_STACK_ALLOCATION_LIMIT 20000
288 #endif
289 
290 #ifndef EIGEN_DEFAULT_IO_FORMAT
291 #ifdef EIGEN_MAKING_DOCS
292 // format used in Eigen's documentation
293 // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
294 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
295 #else
296 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
297 #endif
298 #endif
299 
300 // just an empty macro !
301 #define EIGEN_EMPTY
302 
303 #if defined(_MSC_VER) && (!defined(__INTEL_COMPILER))
304 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
305  using Base::operator =;
306 #elif defined(__clang__) // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653)
307 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
308  using Base::operator =; \
309  EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
310  template <typename OtherDerived> \
311  EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
312 #else
313 #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
314  using Base::operator =; \
315  EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
316  { \
317  Base::operator=(other); \
318  return *this; \
319  }
320 #endif
321 
322 #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
323  EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
324 
333 #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
334  typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \
335  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
336  typedef typename Base::CoeffReturnType CoeffReturnType; \
337  typedef typename Eigen::internal::nested<Derived>::type Nested; \
338  typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
339  typedef typename Eigen::internal::traits<Derived>::Index Index; \
340  enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
341  ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
342  Flags = Eigen::internal::traits<Derived>::Flags, \
343  CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
344  SizeAtCompileTime = Base::SizeAtCompileTime, \
345  MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
346  IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
347 
348 
349 #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
350  typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \
351  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
352  typedef typename Base::PacketScalar PacketScalar; \
353  typedef typename Base::CoeffReturnType CoeffReturnType; \
354  typedef typename Eigen::internal::nested<Derived>::type Nested; \
355  typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
356  typedef typename Eigen::internal::traits<Derived>::Index Index; \
357  enum { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
358  ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
359  MaxRowsAtCompileTime = Eigen::internal::traits<Derived>::MaxRowsAtCompileTime, \
360  MaxColsAtCompileTime = Eigen::internal::traits<Derived>::MaxColsAtCompileTime, \
361  Flags = Eigen::internal::traits<Derived>::Flags, \
362  CoeffReadCost = Eigen::internal::traits<Derived>::CoeffReadCost, \
363  SizeAtCompileTime = Base::SizeAtCompileTime, \
364  MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
365  IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
366  using Base::derived; \
367  using Base::const_cast_derived;
368 
369 
370 #define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
371 #define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
372 
373 // EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
374 // followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
375 // finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
376 #define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
377  : ((int)a == 1 || (int)b == 1) ? 1 \
378  : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
379  : ((int)a <= (int)b) ? (int)a : (int)b)
380 
381 // EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
382 // now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
383 // (between 0 and 3), it is not more than 3.
384 #define EIGEN_SIZE_MIN_PREFER_FIXED(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
385  : ((int)a == 1 || (int)b == 1) ? 1 \
386  : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
387  : ((int)a == Dynamic) ? (int)b \
388  : ((int)b == Dynamic) ? (int)a \
389  : ((int)a <= (int)b) ? (int)a : (int)b)
390 
391 // see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
392 #define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
393  : ((int)a >= (int)b) ? (int)a : (int)b)
394 
395 #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
396 
397 #define EIGEN_IMPLIES(a,b) (!(a) || (b))
398 
399 #define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR) \
400  template<typename OtherDerived> \
401  EIGEN_STRONG_INLINE const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived> \
402  (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
403  { \
404  return CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); \
405  }
406 
407 // the expression type of a cwise product
408 #define EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS) \
409  CwiseBinaryOp< \
410  internal::scalar_product_op< \
411  typename internal::traits<LHS>::Scalar, \
412  typename internal::traits<RHS>::Scalar \
413  >, \
414  const LHS, \
415  const RHS \
416  >
417 
418 #endif // EIGEN_MACROS_H
Definition: LDLT.h:16
#define EIGEN_DONT_INLINE
bool copy_bool(bool b)


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:53