1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2015 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 //------------------------------------------------------------------------------------------
15 // Eigen version and basic defaults
16 //------------------------------------------------------------------------------------------
17 
18 #define EIGEN_WORLD_VERSION 3
19 #define EIGEN_MAJOR_VERSION 3
20 #define EIGEN_MINOR_VERSION 90
21 
22 #define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \
23                                       (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \
24                                                                  EIGEN_MINOR_VERSION>=z))))
25 
26 #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
27 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::RowMajor
28 #else
29 #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::ColMajor
30 #endif
31 
32 #ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
33 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
34 #endif
35 
36 // Upperbound on the C++ version to use.
37 // Expected values are 03, 11, 14, 17, etc.
38 // By default, let's use an arbitrarily large C++ version.
39 #ifndef EIGEN_MAX_CPP_VER
40 #define EIGEN_MAX_CPP_VER 99
41 #endif
42 
43 /** Allows to disable some optimizations which might affect the accuracy of the result.
44   * Such optimization are enabled by default, and set EIGEN_FAST_MATH to 0 to disable them.
45   * They currently include:
46   *   - single precision ArrayBase::sin() and ArrayBase::cos() for SSE and AVX vectorization.
47   */
48 #ifndef EIGEN_FAST_MATH
49 #define EIGEN_FAST_MATH 1
50 #endif
51 
52 #ifndef EIGEN_STACK_ALLOCATION_LIMIT
53 // 131072 == 128 KB
54 #define EIGEN_STACK_ALLOCATION_LIMIT 131072
55 #endif
56 
57 //------------------------------------------------------------------------------------------
58 // Compiler identification, EIGEN_COMP_*
59 //------------------------------------------------------------------------------------------
60 
61 /// \internal EIGEN_COMP_GNUC set to 1 for all compilers compatible with GCC
62 #ifdef __GNUC__
63   #define EIGEN_COMP_GNUC (__GNUC__*10+__GNUC_MINOR__)
64 #else
65   #define EIGEN_COMP_GNUC 0
66 #endif
67 
68 /// \internal EIGEN_COMP_CLANG set to major+minor version (e.g., 307 for clang 3.7) if the compiler is clang
69 #if defined(__clang__)
70   #define EIGEN_COMP_CLANG (__clang_major__*100+__clang_minor__)
71 #else
72   #define EIGEN_COMP_CLANG 0
73 #endif
74 
75 /// \internal EIGEN_COMP_CASTXML set to 1 if being preprocessed by CastXML
76 #if defined(__castxml__)
77   #define EIGEN_COMP_CASTXML 1
78 #else
79   #define EIGEN_COMP_CASTXML 0
80 #endif
81 
82 /// \internal EIGEN_COMP_LLVM set to 1 if the compiler backend is llvm
83 #if defined(__llvm__)
84   #define EIGEN_COMP_LLVM 1
85 #else
86   #define EIGEN_COMP_LLVM 0
87 #endif
88 
89 /// \internal EIGEN_COMP_ICC set to __INTEL_COMPILER if the compiler is Intel compiler, 0 otherwise
90 #if defined(__INTEL_COMPILER)
91   #define EIGEN_COMP_ICC __INTEL_COMPILER
92 #else
93   #define EIGEN_COMP_ICC 0
94 #endif
95 
96 /// \internal EIGEN_COMP_MINGW set to 1 if the compiler is mingw
97 #if defined(__MINGW32__)
98   #define EIGEN_COMP_MINGW 1
99 #else
100   #define EIGEN_COMP_MINGW 0
101 #endif
102 
103 /// \internal EIGEN_COMP_SUNCC set to 1 if the compiler is Solaris Studio
104 #if defined(__SUNPRO_CC)
105   #define EIGEN_COMP_SUNCC 1
106 #else
107   #define EIGEN_COMP_SUNCC 0
108 #endif
109 
110 /// \internal EIGEN_COMP_MSVC set to _MSC_VER if the compiler is Microsoft Visual C++, 0 otherwise.
111 #if defined(_MSC_VER)
112   #define EIGEN_COMP_MSVC _MSC_VER
113 #else
114   #define EIGEN_COMP_MSVC 0
115 #endif
116 
117 #if defined(__NVCC__)
118 #if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9)
119   #define EIGEN_COMP_NVCC  ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100))
120 #elif defined(__CUDACC_VER__)
121   #define EIGEN_COMP_NVCC __CUDACC_VER__
122 #else
123   #error "NVCC did not define compiler version."
124 #endif
125 #else
126   #define EIGEN_COMP_NVCC 0
127 #endif
128 
129 // For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC:
130 //  name        ver   MSC_VER
131 //  2008         9      1500
132 //  2010        10      1600
133 //  2012        11      1700
134 //  2013        12      1800
135 //  2015        14      1900
136 //  "15"        15      1900
137 //  2017-14.1   15.0    1910
138 //  2017-14.11  15.3    1911
139 //  2017-14.12  15.5    1912
140 //  2017-14.13  15.6    1913
141 //  2017-14.14  15.7    1914
142 
143 /// \internal EIGEN_COMP_MSVC_LANG set to _MSVC_LANG if the compiler is Microsoft Visual C++, 0 otherwise.
144 #if defined(_MSVC_LANG)
145   #define EIGEN_COMP_MSVC_LANG _MSVC_LANG
146 #else
147   #define EIGEN_COMP_MSVC_LANG 0
148 #endif
149 
150 // For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC_LANG:
151 // MSVC option                          Standard  MSVC_LANG
152 // /std:c++14 (default as of VS 2019)   C++14     201402L
153 // /std:c++17                           C++17     201703L
154 // /std:c++latest                       >C++17    >201703L
155 
156 /// \internal EIGEN_COMP_MSVC_STRICT set to 1 if the compiler is really Microsoft Visual C++ and not ,e.g., ICC or clang-cl
157 #if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC || EIGEN_COMP_LLVM || EIGEN_COMP_CLANG)
158   #define EIGEN_COMP_MSVC_STRICT _MSC_VER
159 #else
160   #define EIGEN_COMP_MSVC_STRICT 0
161 #endif
162 
163 /// \internal EIGEN_COMP_IBM set to xlc version if the compiler is IBM XL C++
164 // XLC   version
165 // 3.1   0x0301
166 // 4.5   0x0405
167 // 5.0   0x0500
168 // 12.1  0x0C01
169 #if defined(__IBMCPP__) || defined(__xlc__) || defined(__ibmxl__)
170   #define EIGEN_COMP_IBM __xlC__
171 #else
172   #define EIGEN_COMP_IBM 0
173 #endif
174 
175 /// \internal EIGEN_COMP_PGI set to PGI version if the compiler is Portland Group Compiler
176 #if defined(__PGI)
177   #define EIGEN_COMP_PGI (__PGIC__*100+__PGIC_MINOR__)
178 #else
179   #define EIGEN_COMP_PGI 0
180 #endif
181 
182 /// \internal EIGEN_COMP_ARM set to 1 if the compiler is ARM Compiler
183 #if defined(__CC_ARM) || defined(__ARMCC_VERSION)
184   #define EIGEN_COMP_ARM 1
185 #else
186   #define EIGEN_COMP_ARM 0
187 #endif
188 
189 /// \internal EIGEN_COMP_EMSCRIPTEN set to 1 if the compiler is Emscripten Compiler
190 #if defined(__EMSCRIPTEN__)
191   #define EIGEN_COMP_EMSCRIPTEN 1
192 #else
193   #define EIGEN_COMP_EMSCRIPTEN 0
194 #endif
195 
196 
197 /// \internal EIGEN_GNUC_STRICT set to 1 if the compiler is really GCC and not a compatible compiler (e.g., ICC, clang, mingw, etc.)
198 #if EIGEN_COMP_GNUC && !(EIGEN_COMP_CLANG || EIGEN_COMP_ICC || EIGEN_COMP_MINGW || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM || EIGEN_COMP_EMSCRIPTEN)
199   #define EIGEN_COMP_GNUC_STRICT 1
200 #else
201   #define EIGEN_COMP_GNUC_STRICT 0
202 #endif
203 
204 
205 #if EIGEN_COMP_GNUC
206   #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__==x && __GNUC_MINOR__>=y) || __GNUC__>x)
207   #define EIGEN_GNUC_AT_MOST(x,y)  ((__GNUC__==x && __GNUC_MINOR__<=y) || __GNUC__<x)
208   #define EIGEN_GNUC_AT(x,y)       ( __GNUC__==x && __GNUC_MINOR__==y )
209 #else
210   #define EIGEN_GNUC_AT_LEAST(x,y) 0
211   #define EIGEN_GNUC_AT_MOST(x,y)  0
212   #define EIGEN_GNUC_AT(x,y)       0
213 #endif
214 
215 // FIXME: could probably be removed as we do not support gcc 3.x anymore
216 #if EIGEN_COMP_GNUC && (__GNUC__ <= 3)
217 #define EIGEN_GCC3_OR_OLDER 1
218 #else
219 #define EIGEN_GCC3_OR_OLDER 0
220 #endif
221 
222 
223 
224 //------------------------------------------------------------------------------------------
225 // Architecture identification, EIGEN_ARCH_*
226 //------------------------------------------------------------------------------------------
227 
228 
229 #if defined(__x86_64__) || defined(_M_X64) || defined(__amd64)
230   #define EIGEN_ARCH_x86_64 1
231 #else
232   #define EIGEN_ARCH_x86_64 0
233 #endif
234 
235 #if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__i386)
236   #define EIGEN_ARCH_i386 1
237 #else
238   #define EIGEN_ARCH_i386 0
239 #endif
240 
241 #if EIGEN_ARCH_x86_64 || EIGEN_ARCH_i386
242   #define EIGEN_ARCH_i386_OR_x86_64 1
243 #else
244   #define EIGEN_ARCH_i386_OR_x86_64 0
245 #endif
246 
247 /// \internal EIGEN_ARCH_ARM set to 1 if the architecture is ARM
248 #if defined(__arm__)
249   #define EIGEN_ARCH_ARM 1
250 #else
251   #define EIGEN_ARCH_ARM 0
252 #endif
253 
254 /// \internal EIGEN_ARCH_ARM64 set to 1 if the architecture is ARM64
255 #if defined(__aarch64__)
256   #define EIGEN_ARCH_ARM64 1
257 #else
258   #define EIGEN_ARCH_ARM64 0
259 #endif
260 
261 /// \internal EIGEN_ARCH_ARM_OR_ARM64 set to 1 if the architecture is ARM or ARM64
262 #if EIGEN_ARCH_ARM || EIGEN_ARCH_ARM64
263   #define EIGEN_ARCH_ARM_OR_ARM64 1
264 #else
265   #define EIGEN_ARCH_ARM_OR_ARM64 0
266 #endif
267 
268 /// \internal EIGEN_HAS_ARM64_FP16 set to 1 if the architecture provides an IEEE
269 /// compliant Arm fp16 type
270 #if EIGEN_ARCH_ARM64
271   #ifndef EIGEN_HAS_ARM64_FP16
272     #if defined(__ARM_FP16_FORMAT_IEEE)
273       #define EIGEN_HAS_ARM64_FP16 1
274     #else
275       #define EIGEN_HAS_ARM64_FP16 0
276     #endif
277   #endif
278 #endif
279 
280 /// \internal EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC set to 1 if the architecture
281 /// supports Neon vector intrinsics for fp16.
282 #if EIGEN_ARCH_ARM64
283   #ifndef EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
284     #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
285       #define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 1
286     #else
287       #define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 0
288     #endif
289   #endif
290 #endif
291 
292 /// \internal EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC set to 1 if the architecture
293 /// supports Neon scalar intrinsics for fp16.
294 #if EIGEN_ARCH_ARM64
295   #ifndef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
296     #if defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
297       #define EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC 1
298     #endif
299   #endif
300 #endif
301 
302 /// \internal EIGEN_ARCH_MIPS set to 1 if the architecture is MIPS
303 #if defined(__mips__) || defined(__mips)
304   #define EIGEN_ARCH_MIPS 1
305 #else
306   #define EIGEN_ARCH_MIPS 0
307 #endif
308 
309 /// \internal EIGEN_ARCH_SPARC set to 1 if the architecture is SPARC
310 #if defined(__sparc__) || defined(__sparc)
311   #define EIGEN_ARCH_SPARC 1
312 #else
313   #define EIGEN_ARCH_SPARC 0
314 #endif
315 
316 /// \internal EIGEN_ARCH_IA64 set to 1 if the architecture is Intel Itanium
317 #if defined(__ia64__)
318   #define EIGEN_ARCH_IA64 1
319 #else
320   #define EIGEN_ARCH_IA64 0
321 #endif
322 
323 /// \internal EIGEN_ARCH_PPC set to 1 if the architecture is PowerPC
324 #if defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC)
325   #define EIGEN_ARCH_PPC 1
326 #else
327   #define EIGEN_ARCH_PPC 0
328 #endif
329 
330 
331 
332 //------------------------------------------------------------------------------------------
333 // Operating system identification, EIGEN_OS_*
334 //------------------------------------------------------------------------------------------
335 
336 /// \internal EIGEN_OS_UNIX set to 1 if the OS is a unix variant
337 #if defined(__unix__) || defined(__unix)
338   #define EIGEN_OS_UNIX 1
339 #else
340   #define EIGEN_OS_UNIX 0
341 #endif
342 
343 /// \internal EIGEN_OS_LINUX set to 1 if the OS is based on Linux kernel
344 #if defined(__linux__)
345   #define EIGEN_OS_LINUX 1
346 #else
347   #define EIGEN_OS_LINUX 0
348 #endif
349 
350 /// \internal EIGEN_OS_ANDROID set to 1 if the OS is Android
351 // note: ANDROID is defined when using ndk_build, __ANDROID__ is defined when using a standalone toolchain.
352 #if defined(__ANDROID__) || defined(ANDROID)
353   #define EIGEN_OS_ANDROID 1
354 #else
355   #define EIGEN_OS_ANDROID 0
356 #endif
357 
358 /// \internal EIGEN_OS_GNULINUX set to 1 if the OS is GNU Linux and not Linux-based OS (e.g., not android)
359 #if defined(__gnu_linux__) && !(EIGEN_OS_ANDROID)
360   #define EIGEN_OS_GNULINUX 1
361 #else
362   #define EIGEN_OS_GNULINUX 0
363 #endif
364 
365 /// \internal EIGEN_OS_BSD set to 1 if the OS is a BSD variant
366 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
367   #define EIGEN_OS_BSD 1
368 #else
369   #define EIGEN_OS_BSD 0
370 #endif
371 
372 /// \internal EIGEN_OS_MAC set to 1 if the OS is MacOS
373 #if defined(__APPLE__)
374   #define EIGEN_OS_MAC 1
375 #else
376   #define EIGEN_OS_MAC 0
377 #endif
378 
379 /// \internal EIGEN_OS_QNX set to 1 if the OS is QNX
380 #if defined(__QNX__)
381   #define EIGEN_OS_QNX 1
382 #else
383   #define EIGEN_OS_QNX 0
384 #endif
385 
386 /// \internal EIGEN_OS_WIN set to 1 if the OS is Windows based
387 #if defined(_WIN32)
388   #define EIGEN_OS_WIN 1
389 #else
390   #define EIGEN_OS_WIN 0
391 #endif
392 
393 /// \internal EIGEN_OS_WIN64 set to 1 if the OS is Windows 64bits
394 #if defined(_WIN64)
395   #define EIGEN_OS_WIN64 1
396 #else
397   #define EIGEN_OS_WIN64 0
398 #endif
399 
400 /// \internal EIGEN_OS_WINCE set to 1 if the OS is Windows CE
401 #if defined(_WIN32_WCE)
402   #define EIGEN_OS_WINCE 1
403 #else
404   #define EIGEN_OS_WINCE 0
405 #endif
406 
407 /// \internal EIGEN_OS_CYGWIN set to 1 if the OS is Windows/Cygwin
408 #if defined(__CYGWIN__)
409   #define EIGEN_OS_CYGWIN 1
410 #else
411   #define EIGEN_OS_CYGWIN 0
412 #endif
413 
414 /// \internal EIGEN_OS_WIN_STRICT set to 1 if the OS is really Windows and not some variants
415 #if EIGEN_OS_WIN && !( EIGEN_OS_WINCE || EIGEN_OS_CYGWIN )
416   #define EIGEN_OS_WIN_STRICT 1
417 #else
418   #define EIGEN_OS_WIN_STRICT 0
419 #endif
420 
421 /// \internal EIGEN_OS_SUN set to __SUNPRO_C if the OS is SUN
422 // compiler  solaris   __SUNPRO_C
423 // version   studio
424 // 5.7       10        0x570
425 // 5.8       11        0x580
426 // 5.9       12        0x590
427 // 5.10	     12.1      0x5100
428 // 5.11	     12.2      0x5110
429 // 5.12	     12.3      0x5120
430 #if (defined(sun) || defined(__sun)) && !(defined(__SVR4) || defined(__svr4__))
431   #define EIGEN_OS_SUN __SUNPRO_C
432 #else
433   #define EIGEN_OS_SUN 0
434 #endif
435 
436 /// \internal EIGEN_OS_SOLARIS set to 1 if the OS is Solaris
437 #if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
438   #define EIGEN_OS_SOLARIS 1
439 #else
440   #define EIGEN_OS_SOLARIS 0
441 #endif
442 
443 
444 //------------------------------------------------------------------------------------------
445 // Detect GPU compilers and architectures
446 //------------------------------------------------------------------------------------------
447 
448 // NVCC is not supported as the target platform for HIPCC
449 // Note that this also makes EIGEN_CUDACC and EIGEN_HIPCC mutually exclusive
450 #if defined(__NVCC__) && defined(__HIPCC__)
451   #error "NVCC as the target platform for HIPCC is currently not supported."
452 #endif
453 
454 #if defined(__CUDACC__) && !defined(EIGEN_NO_CUDA)
455   // Means the compiler is either nvcc or clang with CUDA enabled
456   #define EIGEN_CUDACC __CUDACC__
457 #endif
458 
459 #if defined(__CUDA_ARCH__) && !defined(EIGEN_NO_CUDA)
460   // Means we are generating code for the device
461   #define EIGEN_CUDA_ARCH __CUDA_ARCH__
462 #endif
463 
464 #if defined(EIGEN_CUDACC)
465 #include <cuda.h>
466   #define EIGEN_CUDA_SDK_VER (CUDA_VERSION * 10)
467 #else
468   #define EIGEN_CUDA_SDK_VER 0
469 #endif
470 
471 #if defined(__HIPCC__) && !defined(EIGEN_NO_HIP)
472   // Means the compiler is HIPCC (analogous to EIGEN_CUDACC, but for HIP)
473   #define EIGEN_HIPCC __HIPCC__
474 
475   // We need to include hip_runtime.h here because it pulls in
476   // ++ hip_common.h which contains the define for  __HIP_DEVICE_COMPILE__
477   // ++ host_defines.h which contains the defines for the __host__ and __device__ macros
478   #include <hip/hip_runtime.h>
479 
480   #if defined(__HIP_DEVICE_COMPILE__)
481     // analogous to EIGEN_CUDA_ARCH, but for HIP
482     #define EIGEN_HIP_DEVICE_COMPILE __HIP_DEVICE_COMPILE__
483   #endif
484 
485   // For HIP (ROCm 3.5 and higher), we need to explicitly set the launch_bounds attribute
486   // value to 1024. The compiler assigns a default value of 256 when the attribute is not
487   // specified. This results in failures on the HIP platform, for cases when a GPU kernel
488   // without an explicit launch_bounds attribute is called with a threads_per_block value
489   // greater than 256.
490   //
491   // This is a regression in functioanlity and is expected to be fixed within the next
492   // couple of ROCm releases (compiler will go back to using 1024 value as the default)
493   //
494   // In the meantime, we will use a "only enabled for HIP" macro to set the launch_bounds
495   // attribute.
496 
497   #define EIGEN_HIP_LAUNCH_BOUNDS_1024 __launch_bounds__(1024)
498 
499 #endif
500 
501 #if !defined(EIGEN_HIP_LAUNCH_BOUNDS_1024)
502 #define EIGEN_HIP_LAUNCH_BOUNDS_1024
503 #endif // !defined(EIGEN_HIP_LAUNCH_BOUNDS_1024)
504 
505 // Unify CUDA/HIPCC
506 
507 #if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
508 //
509 // If either EIGEN_CUDACC or EIGEN_HIPCC is defined, then define EIGEN_GPUCC
510 //
511 #define EIGEN_GPUCC
512 //
513 // EIGEN_HIPCC implies the HIP compiler and is used to tweak Eigen code for use in HIP kernels
514 // EIGEN_CUDACC implies the CUDA compiler and is used to tweak Eigen code for use in CUDA kernels
515 //
516 // In most cases the same tweaks are required to the Eigen code to enable in both the HIP and CUDA kernels.
517 // For those cases, the corresponding code should be guarded with
518 //      #if defined(EIGEN_GPUCC)
519 // instead of
520 //      #if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
521 //
522 // For cases where the tweak is specific to HIP, the code should be guarded with
523 //      #if defined(EIGEN_HIPCC)
524 //
525 // For cases where the tweak is specific to CUDA, the code should be guarded with
526 //      #if defined(EIGEN_CUDACC)
527 //
528 #endif
529 
530 #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
531 //
532 // If either EIGEN_CUDA_ARCH or EIGEN_HIP_DEVICE_COMPILE is defined, then define EIGEN_GPU_COMPILE_PHASE
533 //
534 #define EIGEN_GPU_COMPILE_PHASE
535 //
536 // GPU compilers (HIPCC, NVCC) typically do two passes over the source code,
537 //   + one to compile the source for the "host" (ie CPU)
538 //   + another to compile the source for the "device" (ie. GPU)
539 //
540 // Code that needs to enabled only during the either the "host" or "device" compilation phase
541 // needs to be guarded with a macro that indicates the current compilation phase
542 //
543 // EIGEN_HIP_DEVICE_COMPILE implies the device compilation phase in HIP
544 // EIGEN_CUDA_ARCH implies the device compilation phase in CUDA
545 //
546 // In most cases, the "host" / "device" specific code is the same for both HIP and CUDA
547 // For those cases, the code should be guarded with
548 //       #if defined(EIGEN_GPU_COMPILE_PHASE)
549 // instead of
550 //       #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
551 //
552 // For cases where the tweak is specific to HIP, the code should be guarded with
553 //      #if defined(EIGEN_HIP_DEVICE_COMPILE)
554 //
555 // For cases where the tweak is specific to CUDA, the code should be guarded with
556 //      #if defined(EIGEN_CUDA_ARCH)
557 //
558 #endif
559 
560 #if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__)
561 // EIGEN_USE_SYCL is a user-defined macro while __SYCL_DEVICE_ONLY__ is a compiler-defined macro.
562 // In most cases we want to check if both macros are defined which can be done using the define below.
563 #define SYCL_DEVICE_ONLY
564 #endif
565 
566 //------------------------------------------------------------------------------------------
567 // Detect Compiler/Architecture/OS specific features
568 //------------------------------------------------------------------------------------------
569 
570 #if EIGEN_GNUC_AT_MOST(4,3) && !EIGEN_COMP_CLANG
571   // see bug 89
572   #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 0
573 #else
574   #define EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO 1
575 #endif
576 
577 // Cross compiler wrapper around LLVM's __has_builtin
578 #ifdef __has_builtin
579 #  define EIGEN_HAS_BUILTIN(x) __has_builtin(x)
580 #else
581 #  define EIGEN_HAS_BUILTIN(x) 0
582 #endif
583 
584 // A Clang feature extension to determine compiler features.
585 // We use it to determine 'cxx_rvalue_references'
586 #ifndef __has_feature
587 # define __has_feature(x) 0
588 #endif
589 
590 // Some old compilers do not support template specializations like:
591 // template<typename T,int N> void foo(const T x[N]);
592 #if !(   EIGEN_COMP_CLANG && (   (EIGEN_COMP_CLANG<309)                                                       \
593                               || (defined(__apple_build_version__) && (__apple_build_version__ < 9000000)))  \
594       || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49)
595 #define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 1
596 #else
597 #define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 0
598 #endif
599 
600 
601 // The macro EIGEN_COMP_CXXVER defines the c++ verson expected by the compiler.
602 // For instance, if compiling with gcc and -std=c++17, then EIGEN_COMP_CXXVER
603 // is defined to 17.
604 #if   (defined(__cplusplus) && (__cplusplus >  201402L) || EIGEN_COMP_MSVC_LANG > 201402L)
605 #define EIGEN_COMP_CXXVER 17
606 #elif (defined(__cplusplus) && (__cplusplus >  201103L) || EIGEN_COMP_MSVC >= 1910)
607 #define EIGEN_COMP_CXXVER 14
608 #elif (defined(__cplusplus) && (__cplusplus >= 201103L) || EIGEN_COMP_MSVC >= 1900)
609 #define EIGEN_COMP_CXXVER 11
610 #else
611 #define EIGEN_COMP_CXXVER 03
612 #endif
613 
614 
615 // The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features
616 // but in practice we should not rely on them but rather on the availabilty of
617 // individual features as defined later.
618 // This is why there is no EIGEN_HAS_CXX17.
619 // FIXME: get rid of EIGEN_HAS_CXX14 and maybe even EIGEN_HAS_CXX11.
620 #if EIGEN_MAX_CPP_VER>=11 && EIGEN_COMP_CXXVER>=11
621 #define EIGEN_HAS_CXX11 1
622 #else
623 #define EIGEN_HAS_CXX11 0
624 #endif
625 
626 #if EIGEN_MAX_CPP_VER>=14 && EIGEN_COMP_CXXVER>=14
627 #define EIGEN_HAS_CXX14 1
628 #else
629 #define EIGEN_HAS_CXX14 0
630 #endif
631 
632 // Do we support r-value references?
633 #ifndef EIGEN_HAS_RVALUE_REFERENCES
634 #if EIGEN_MAX_CPP_VER>=11 && \
635     (__has_feature(cxx_rvalue_references) || \
636     (defined(__cplusplus) && __cplusplus >= 201103L) || \
637     (EIGEN_COMP_MSVC >= 1600))
638   #define EIGEN_HAS_RVALUE_REFERENCES 1
639 #else
640   #define EIGEN_HAS_RVALUE_REFERENCES 0
641 #endif
642 #endif
643 
644 // Does the compiler support C99?
645 // Need to include <cmath> to make sure _GLIBCXX_USE_C99 gets defined
646 #include <cmath>
647 #ifndef EIGEN_HAS_C99_MATH
648 #if EIGEN_MAX_CPP_VER>=11 && \
649     ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901))       \
650   || (defined(__GNUC__) && defined(_GLIBCXX_USE_C99)) \
651   || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) \
652   || (EIGEN_COMP_MSVC >= 1900) || defined(SYCL_DEVICE_ONLY))
653   #define EIGEN_HAS_C99_MATH 1
654 #else
655   #define EIGEN_HAS_C99_MATH 0
656 #endif
657 #endif
658 
659 // Does the compiler support result_of?
660 // It's likely that MSVC 2013 supports result_of but I couldn't not find a good source for that,
661 // so let's be conservative.
662 #ifndef EIGEN_HAS_STD_RESULT_OF
663 #if EIGEN_MAX_CPP_VER>=11 && \
664     (__has_feature(cxx_lambdas) || (defined(__cplusplus) && __cplusplus >= 201103L) || EIGEN_COMP_MSVC >= 1900)
665 #define EIGEN_HAS_STD_RESULT_OF 1
666 #else
667 #define EIGEN_HAS_STD_RESULT_OF 0
668 #endif
669 #endif
670 
671 #ifndef EIGEN_HAS_ALIGNAS
672 #if EIGEN_MAX_CPP_VER>=11 && EIGEN_HAS_CXX11 &&   \
673       (     __has_feature(cxx_alignas)            \
674         ||  EIGEN_HAS_CXX14                       \
675         || (EIGEN_COMP_MSVC >= 1800)              \
676         || (EIGEN_GNUC_AT_LEAST(4,8))             \
677         || (EIGEN_COMP_CLANG>=305)                \
678         || (EIGEN_COMP_ICC>=1500)                 \
679         || (EIGEN_COMP_PGI>=1500)                 \
680         || (EIGEN_COMP_SUNCC>=0x5130))
681 #define EIGEN_HAS_ALIGNAS 1
682 #else
683 #define EIGEN_HAS_ALIGNAS 0
684 #endif
685 #endif
686 
687 // Does the compiler support type_traits?
688 // - full support of type traits was added only to GCC 5.1.0.
689 // - 20150626 corresponds to the last release of 4.x libstdc++
690 #ifndef EIGEN_HAS_TYPE_TRAITS
691 #if EIGEN_MAX_CPP_VER>=11 && (EIGEN_HAS_CXX11 || EIGEN_COMP_MSVC >= 1700) \
692   && ((!EIGEN_COMP_GNUC_STRICT) || EIGEN_GNUC_AT_LEAST(5, 1)) \
693   && ((!defined(__GLIBCXX__))   || __GLIBCXX__ > 20150626)
694 #define EIGEN_HAS_TYPE_TRAITS 1
695 #define EIGEN_INCLUDE_TYPE_TRAITS
696 #else
697 #define EIGEN_HAS_TYPE_TRAITS 0
698 #endif
699 #endif
700 
701 // Does the compiler support variadic templates?
702 #ifndef EIGEN_HAS_VARIADIC_TEMPLATES
703 #if EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) \
704   && (!defined(__NVCC__) || !EIGEN_ARCH_ARM_OR_ARM64 || (EIGEN_COMP_NVCC >= 80000) )
705     // ^^ Disable the use of variadic templates when compiling with versions of nvcc older than 8.0 on ARM devices:
706     //    this prevents nvcc from crashing when compiling Eigen on Tegra X1
707 #define EIGEN_HAS_VARIADIC_TEMPLATES 1
708 #elif  EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) && defined(SYCL_DEVICE_ONLY)
709 #define EIGEN_HAS_VARIADIC_TEMPLATES 1
710 #else
711 #define EIGEN_HAS_VARIADIC_TEMPLATES 0
712 #endif
713 #endif
714 
715 // Does the compiler fully support const expressions? (as in c++14)
716 #ifndef EIGEN_HAS_CONSTEXPR
717   #if defined(EIGEN_CUDACC)
718   // Const expressions are supported provided that c++11 is enabled and we're using either clang or nvcc 7.5 or above
719     #if EIGEN_MAX_CPP_VER>=14 && (__cplusplus > 199711L && (EIGEN_COMP_CLANG || EIGEN_COMP_NVCC >= 70500))
720       #define EIGEN_HAS_CONSTEXPR 1
721     #endif
722   #elif EIGEN_MAX_CPP_VER>=14 && (__has_feature(cxx_relaxed_constexpr) || (defined(__cplusplus) && __cplusplus >= 201402L) || \
723     (EIGEN_GNUC_AT_LEAST(4,8) && (__cplusplus > 199711L)) || \
724     (EIGEN_COMP_CLANG >= 306 && (__cplusplus > 199711L)))
725     #define EIGEN_HAS_CONSTEXPR 1
726   #endif
727 
728   #ifndef EIGEN_HAS_CONSTEXPR
729     #define EIGEN_HAS_CONSTEXPR 0
730   #endif
731 
732 #endif // EIGEN_HAS_CONSTEXPR
733 
734 #if EIGEN_HAS_CONSTEXPR
735 #define EIGEN_CONSTEXPR constexpr
736 #else
737 #define EIGEN_CONSTEXPR
738 #endif
739 
740 // Does the compiler support C++11 math?
741 // Let's be conservative and enable the default C++11 implementation only if we are sure it exists
742 #ifndef EIGEN_HAS_CXX11_MATH
743   #if EIGEN_MAX_CPP_VER>=11 && ((__cplusplus > 201103L) || (__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC)  \
744       && (EIGEN_ARCH_i386_OR_x86_64) && (EIGEN_OS_GNULINUX || EIGEN_OS_WIN_STRICT || EIGEN_OS_MAC))
745     #define EIGEN_HAS_CXX11_MATH 1
746   #else
747     #define EIGEN_HAS_CXX11_MATH 0
748   #endif
749 #endif
750 
751 // Does the compiler support proper C++11 containers?
752 #ifndef EIGEN_HAS_CXX11_CONTAINERS
753   #if    EIGEN_MAX_CPP_VER>=11 && \
754          ((__cplusplus > 201103L) \
755       || ((__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_ICC>=1400)) \
756       || EIGEN_COMP_MSVC >= 1900)
757     #define EIGEN_HAS_CXX11_CONTAINERS 1
758   #else
759     #define EIGEN_HAS_CXX11_CONTAINERS 0
760   #endif
761 #endif
762 
763 // Does the compiler support C++11 noexcept?
764 #ifndef EIGEN_HAS_CXX11_NOEXCEPT
765   #if    EIGEN_MAX_CPP_VER>=11 && \
766          (__has_feature(cxx_noexcept) \
767       || (__cplusplus > 201103L) \
768       || ((__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_ICC>=1400)) \
769       || EIGEN_COMP_MSVC >= 1900)
770     #define EIGEN_HAS_CXX11_NOEXCEPT 1
771   #else
772     #define EIGEN_HAS_CXX11_NOEXCEPT 0
773   #endif
774 #endif
775 
776 #ifndef EIGEN_HAS_CXX11_ATOMIC
777   #if    EIGEN_MAX_CPP_VER>=11 && \
778          (__has_feature(cxx_atomic) \
779       || (__cplusplus > 201103L) \
780       || ((__cplusplus >= 201103L) && (EIGEN_COMP_MSVC==0 || EIGEN_COMP_MSVC >= 1700)))
781     #define EIGEN_HAS_CXX11_ATOMIC 1
782   #else
783     #define EIGEN_HAS_CXX11_ATOMIC 0
784   #endif
785 #endif
786 
787 #ifndef EIGEN_HAS_CXX11_OVERRIDE_FINAL
788   #if    EIGEN_MAX_CPP_VER>=11 && \
789        (__cplusplus >= 201103L || EIGEN_COMP_MSVC >= 1700)
790     #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 1
791   #else
792     #define EIGEN_HAS_CXX11_OVERRIDE_FINAL 0
793   #endif
794 #endif
795 
796 // NOTE: the required Apple's clang version is very conservative
797 //       and it could be that XCode 9 works just fine.
798 // NOTE: the MSVC version is based on https://en.cppreference.com/w/cpp/compiler_support
799 //       and not tested.
800 #ifndef EIGEN_HAS_CXX17_OVERALIGN
801 #if EIGEN_MAX_CPP_VER>=17 && EIGEN_COMP_CXXVER>=17 && (                                 \
802            (EIGEN_COMP_MSVC >= 1912)                                                    \
803         || (EIGEN_GNUC_AT_LEAST(7,0))                                                   \
804         || ((!defined(__apple_build_version__)) && (EIGEN_COMP_CLANG>=500))             \
805         || (( defined(__apple_build_version__)) && (__apple_build_version__>=10000000)) \
806       )
807 #define EIGEN_HAS_CXX17_OVERALIGN 1
808 #else
809 #define EIGEN_HAS_CXX17_OVERALIGN 0
810 #endif
811 #endif
812 
813 #if defined(EIGEN_CUDACC) && EIGEN_HAS_CONSTEXPR
814   // While available already with c++11, this is useful mostly starting with c++14 and relaxed constexpr rules
815   #if defined(__NVCC__)
816     // nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr
817     #ifdef __CUDACC_RELAXED_CONSTEXPR__
818       #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
819     #endif
820   #elif defined(__clang__) && defined(__CUDA__) && __has_feature(cxx_relaxed_constexpr)
821     // clang++ always considers constexpr functions as implicitly __host__ __device__
822     #define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
823   #endif
824 #endif
825 
826 // Does the compiler support the __int128 and __uint128_t extensions for 128-bit
827 // integer arithmetic?
828 //
829 // Clang and GCC define __SIZEOF_INT128__ when these extensions are supported,
830 // but we avoid using them in certain cases:
831 //
832 // * Building using Clang for Windows, where the Clang runtime library has
833 //   128-bit support only on LP64 architectures, but Windows is LLP64.
834 #ifndef EIGEN_HAS_BUILTIN_INT128
835 #if defined(__SIZEOF_INT128__) && !(EIGEN_OS_WIN && EIGEN_COMP_CLANG)
836 #define EIGEN_HAS_BUILTIN_INT128 1
837 #else
838 #define EIGEN_HAS_BUILTIN_INT128 0
839 #endif
840 #endif
841 
842 //------------------------------------------------------------------------------------------
843 // Preprocessor programming helpers
844 //------------------------------------------------------------------------------------------
845 
846 // This macro can be used to prevent from macro expansion, e.g.:
847 //   std::max EIGEN_NOT_A_MACRO(a,b)
848 #define EIGEN_NOT_A_MACRO
849 
850 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
851 
852 // concatenate two tokens
853 #define EIGEN_CAT2(a,b) a ## b
854 #define EIGEN_CAT(a,b) EIGEN_CAT2(a,b)
855 
856 #define EIGEN_COMMA ,
857 
858 // convert a token to a string
859 #define EIGEN_MAKESTRING2(a) #a
860 #define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
861 
862 // EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
863 // but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
864 // but GCC is still doing fine with just inline.
865 #ifndef EIGEN_STRONG_INLINE
866 #if EIGEN_COMP_MSVC || EIGEN_COMP_ICC
867 #define EIGEN_STRONG_INLINE __forceinline
868 #else
869 #define EIGEN_STRONG_INLINE inline
870 #endif
871 #endif
872 
873 // EIGEN_ALWAYS_INLINE is the stronget, it has the effect of making the function inline and adding every possible
874 // attribute to maximize inlining. This should only be used when really necessary: in particular,
875 // it uses __attribute__((always_inline)) on GCC, which most of the time is useless and can severely harm compile times.
876 // FIXME with the always_inline attribute,
877 // gcc 3.4.x and 4.1 reports the following compilation error:
878 //   Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval<Derived> Eigen::MatrixBase<Scalar, Derived>::eval() const'
879 //    : function body not available
880 //   See also bug 1367
881 #if EIGEN_GNUC_AT_LEAST(4,2) && !defined(SYCL_DEVICE_ONLY)
882 #define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
883 #else
884 #define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
885 #endif
886 
887 #if EIGEN_COMP_GNUC
888 #define EIGEN_DONT_INLINE __attribute__((noinline))
889 #elif EIGEN_COMP_MSVC
890 #define EIGEN_DONT_INLINE __declspec(noinline)
891 #else
892 #define EIGEN_DONT_INLINE
893 #endif
894 
895 #if EIGEN_COMP_GNUC
896 #define EIGEN_PERMISSIVE_EXPR __extension__
897 #else
898 #define EIGEN_PERMISSIVE_EXPR
899 #endif
900 
901 // GPU stuff
902 
903 // Disable some features when compiling with GPU compilers (NVCC/clang-cuda/SYCL/HIPCC)
904 #if defined(EIGEN_CUDACC) || defined(SYCL_DEVICE_ONLY) || defined(EIGEN_HIPCC)
905   // Do not try asserts on device code
906   #ifndef EIGEN_NO_DEBUG
907   #define EIGEN_NO_DEBUG
908   #endif
909 
910   #ifdef EIGEN_INTERNAL_DEBUGGING
911   #undef EIGEN_INTERNAL_DEBUGGING
912   #endif
913 
914   #ifdef EIGEN_EXCEPTIONS
915   #undef EIGEN_EXCEPTIONS
916   #endif
917 #endif
918 
919 #if defined(SYCL_DEVICE_ONLY)
920   #ifndef EIGEN_DONT_VECTORIZE
921     #define EIGEN_DONT_VECTORIZE
922   #endif
923   #define EIGEN_DEVICE_FUNC __attribute__((flatten)) __attribute__((always_inline))
924 // All functions callable from CUDA/HIP code must be qualified with __device__
925 #elif defined(EIGEN_GPUCC)
926     #define EIGEN_DEVICE_FUNC __host__ __device__
927 #else
928   #define EIGEN_DEVICE_FUNC
929 #endif
930 
931 
932 // this macro allows to get rid of linking errors about multiply defined functions.
933 //  - static is not very good because it prevents definitions from different object files to be merged.
934 //           So static causes the resulting linked executable to be bloated with multiple copies of the same function.
935 //  - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
936 #define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
937 #define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC inline
938 
939 #ifdef NDEBUG
940 # ifndef EIGEN_NO_DEBUG
941 #  define EIGEN_NO_DEBUG
942 # endif
943 #endif
944 
945 // eigen_plain_assert is where we implement the workaround for the assert() bug in GCC <= 4.3, see bug 89
946 #ifdef EIGEN_NO_DEBUG
947   #ifdef SYCL_DEVICE_ONLY // used to silence the warning on SYCL device
948     #define eigen_plain_assert(x) EIGEN_UNUSED_VARIABLE(x)
949   #else
950     #define eigen_plain_assert(x)
951   #endif
952 #else
953   #if EIGEN_SAFE_TO_USE_STANDARD_ASSERT_MACRO
954     namespace Eigen {
955     namespace internal {
copy_bool(bool b)956     inline bool copy_bool(bool b) { return b; }
957     }
958     }
959     #define eigen_plain_assert(x) assert(x)
960   #else
961     // work around bug 89
962     #include <cstdlib>   // for abort
963     #include <iostream>  // for std::cerr
964 
965     namespace Eigen {
966     namespace internal {
967     // trivial function copying a bool. Must be EIGEN_DONT_INLINE, so we implement it after including Eigen headers.
968     // see bug 89.
969     namespace {
copy_bool(bool b)970     EIGEN_DONT_INLINE bool copy_bool(bool b) { return b; }
971     }
assert_fail(const char * condition,const char * function,const char * file,int line)972     inline void assert_fail(const char *condition, const char *function, const char *file, int line)
973     {
974       std::cerr << "assertion failed: " << condition << " in function " << function << " at " << file << ":" << line << std::endl;
975       abort();
976     }
977     }
978     }
979     #define eigen_plain_assert(x) \
980       do { \
981         if(!Eigen::internal::copy_bool(x)) \
982           Eigen::internal::assert_fail(EIGEN_MAKESTRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__); \
983       } while(false)
984   #endif
985 #endif
986 
987 // eigen_assert can be overridden
988 #ifndef eigen_assert
989 #define eigen_assert(x) eigen_plain_assert(x)
990 #endif
991 
992 #ifdef EIGEN_INTERNAL_DEBUGGING
993 #define eigen_internal_assert(x) eigen_assert(x)
994 #else
995 #define eigen_internal_assert(x)
996 #endif
997 
998 #ifdef EIGEN_NO_DEBUG
999 #define EIGEN_ONLY_USED_FOR_DEBUG(x) EIGEN_UNUSED_VARIABLE(x)
1000 #else
1001 #define EIGEN_ONLY_USED_FOR_DEBUG(x)
1002 #endif
1003 
1004 #ifndef EIGEN_NO_DEPRECATED_WARNING
1005   #if EIGEN_COMP_GNUC
1006     #define EIGEN_DEPRECATED __attribute__((deprecated))
1007   #elif EIGEN_COMP_MSVC
1008     #define EIGEN_DEPRECATED __declspec(deprecated)
1009   #else
1010     #define EIGEN_DEPRECATED
1011   #endif
1012 #else
1013   #define EIGEN_DEPRECATED
1014 #endif
1015 
1016 #if EIGEN_COMP_GNUC
1017 #define EIGEN_UNUSED __attribute__((unused))
1018 #else
1019 #define EIGEN_UNUSED
1020 #endif
1021 
1022 // Suppresses 'unused variable' warnings.
1023 namespace Eigen {
1024   namespace internal {
ignore_unused_variable(const T &)1025     template<typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void ignore_unused_variable(const T&) {}
1026   }
1027 }
1028 #define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var);
1029 
1030 #if !defined(EIGEN_ASM_COMMENT)
1031   #if EIGEN_COMP_GNUC && (EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64)
1032     #define EIGEN_ASM_COMMENT(X)  __asm__("#" X)
1033   #else
1034     #define EIGEN_ASM_COMMENT(X)
1035   #endif
1036 #endif
1037 
1038 
1039 #if EIGEN_COMP_MSVC
1040   // NOTE MSVC often gives C4127 warnings with compiletime if statements. See bug 1362.
1041   // This workaround is ugly, but it does the job.
1042 #  define EIGEN_CONST_CONDITIONAL(cond)  (void)0, cond
1043 #else
1044 #  define EIGEN_CONST_CONDITIONAL(cond)  cond
1045 #endif
1046 
1047 #ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
1048   #define EIGEN_RESTRICT
1049 #endif
1050 #ifndef EIGEN_RESTRICT
1051   #define EIGEN_RESTRICT __restrict
1052 #endif
1053 
1054 
1055 #ifndef EIGEN_DEFAULT_IO_FORMAT
1056 #ifdef EIGEN_MAKING_DOCS
1057 // format used in Eigen's documentation
1058 // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
1059 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
1060 #else
1061 #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
1062 #endif
1063 #endif
1064 
1065 // just an empty macro !
1066 #define EIGEN_EMPTY
1067 
1068 
1069 // When compiling CUDA/HIP device code with NVCC or HIPCC
1070 // pull in math functions from the global namespace.
1071 // In host mode, and when device code is compiled with clang,
1072 // use the std versions.
1073 #if (defined(EIGEN_CUDA_ARCH) && defined(__NVCC__)) || defined(EIGEN_HIP_DEVICE_COMPILE)
1074   #define EIGEN_USING_STD(FUNC) using ::FUNC;
1075 #else
1076   #define EIGEN_USING_STD(FUNC) using std::FUNC;
1077 #endif
1078 
1079 #if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC < 1900 || EIGEN_COMP_NVCC)
1080   // for older MSVC versions, as well as 1900 && CUDA 8, using the base operator is sufficient (cf Bugs 1000, 1324)
1081   #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1082     using Base::operator =;
1083 #elif EIGEN_COMP_CLANG // workaround clang bug (see http://forum.kde.org/viewtopic.php?f=74&t=102653)
1084   #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1085     using Base::operator =; \
1086     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { Base::operator=(other); return *this; } \
1087     template <typename OtherDerived> \
1088     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const DenseBase<OtherDerived>& other) { Base::operator=(other.derived()); return *this; }
1089 #else
1090   #define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1091     using Base::operator =; \
1092     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) \
1093     { \
1094       Base::operator=(other); \
1095       return *this; \
1096     }
1097 #endif
1098 
1099 
1100 /**
1101  * \internal
1102  * \brief Macro to explicitly define the default copy constructor.
1103  * This is necessary, because the implicit definition is deprecated if the copy-assignment is overridden.
1104  */
1105 #if EIGEN_HAS_CXX11
1106 #define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) CLASS(const CLASS&) = default;
1107 #else
1108 #define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
1109 #endif
1110 
1111 
1112 
1113 /** \internal
1114  * \brief Macro to manually inherit assignment operators.
1115  * This is necessary, because the implicitly defined assignment operator gets deleted when a custom operator= is defined.
1116  * With C++11 or later this also default-implements the copy-constructor
1117  */
1118 #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)  \
1119     EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1120     EIGEN_DEFAULT_COPY_CONSTRUCTOR(Derived)
1121 
1122 /** \internal
1123  * \brief Macro to manually define default constructors and destructors.
1124  * This is necessary when the copy constructor is re-defined.
1125  * For empty helper classes this should usually be protected, to avoid accidentally creating empty objects.
1126  *
1127  * Hiding the default destructor lead to problems in C++03 mode together with boost::multiprecision
1128  */
1129 #if EIGEN_HAS_CXX11
1130 #define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)  \
1131     Derived() = default; \
1132     ~Derived() = default;
1133 #else
1134 #define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived)  \
1135     Derived() {}; \
1136     /* ~Derived() {}; */
1137 #endif
1138 
1139 
1140 
1141 
1142 
1143 /**
1144 * Just a side note. Commenting within defines works only by documenting
1145 * behind the object (via '!<'). Comments cannot be multi-line and thus
1146 * we have these extra long lines. What is confusing doxygen over here is
1147 * that we use '\' and basically have a bunch of typedefs with their
1148 * documentation in a single line.
1149 **/
1150 
1151 #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
1152   typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; /*!< \brief Numeric type, e.g. float, double, int or std::complex<float>. */ \
1153   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. */ \
1154   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. */ \
1155   typedef typename Eigen::internal::ref_selector<Derived>::type Nested; \
1156   typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
1157   typedef typename Eigen::internal::traits<Derived>::StorageIndex StorageIndex; \
1158   enum CompileTimeTraits \
1159       { RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
1160         ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
1161         Flags = Eigen::internal::traits<Derived>::Flags, \
1162         SizeAtCompileTime = Base::SizeAtCompileTime, \
1163         MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
1164         IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
1165   using Base::derived; \
1166   using Base::const_cast_derived;
1167 
1168 
1169 // FIXME Maybe the EIGEN_DENSE_PUBLIC_INTERFACE could be removed as importing PacketScalar is rarely needed
1170 #define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
1171   EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
1172   typedef typename Base::PacketScalar PacketScalar;
1173 
1174 
1175 #define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
1176 #define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
1177 
1178 // EIGEN_SIZE_MIN_PREFER_DYNAMIC gives the min between compile-time sizes. 0 has absolute priority, followed by 1,
1179 // followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over
1180 // finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3.
1181 #define EIGEN_SIZE_MIN_PREFER_DYNAMIC(a,b) (((int)a == 0 || (int)b == 0) ? 0 \
1182                            : ((int)a == 1 || (int)b == 1) ? 1 \
1183                            : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
1184                            : ((int)a <= (int)b) ? (int)a : (int)b)
1185 
1186 // EIGEN_SIZE_MIN_PREFER_FIXED is a variant of EIGEN_SIZE_MIN_PREFER_DYNAMIC comparing MaxSizes. The difference is that finite values
1187 // now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is
1188 // (between 0 and 3), it is not more than 3.
1189 #define EIGEN_SIZE_MIN_PREFER_FIXED(a,b)  (((int)a == 0 || (int)b == 0) ? 0 \
1190                            : ((int)a == 1 || (int)b == 1) ? 1 \
1191                            : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \
1192                            : ((int)a == Dynamic) ? (int)b \
1193                            : ((int)b == Dynamic) ? (int)a \
1194                            : ((int)a <= (int)b) ? (int)a : (int)b)
1195 
1196 // see EIGEN_SIZE_MIN_PREFER_DYNAMIC. No need for a separate variant for MaxSizes here.
1197 #define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \
1198                            : ((int)a >= (int)b) ? (int)a : (int)b)
1199 
1200 #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b)))
1201 
1202 #define EIGEN_IMPLIES(a,b) (!(a) || (b))
1203 
1204 #if EIGEN_HAS_BUILTIN(__builtin_expect) || EIGEN_COMP_GNUC
1205 #define EIGEN_PREDICT_FALSE(x) (__builtin_expect(x, false))
1206 #define EIGEN_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
1207 #else
1208 #define EIGEN_PREDICT_FALSE(x) (x)
1209 #define EIGEN_PREDICT_TRUE(x) (x)
1210 #endif
1211 
1212 // the expression type of a standard coefficient wise binary operation
1213 #define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS,RHS,OPNAME) \
1214     CwiseBinaryOp< \
1215       EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)< \
1216           typename internal::traits<LHS>::Scalar, \
1217           typename internal::traits<RHS>::Scalar \
1218       >, \
1219       const LHS, \
1220       const RHS \
1221     >
1222 
1223 #define EIGEN_MAKE_CWISE_BINARY_OP(METHOD,OPNAME) \
1224   template<typename OtherDerived> \
1225   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME) \
1226   (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
1227   { \
1228     return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,OPNAME)(derived(), other.derived()); \
1229   }
1230 
1231 #define EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,TYPEA,TYPEB) \
1232   (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<TYPEA,TYPEB,EIGEN_CAT(EIGEN_CAT(Eigen::internal::scalar_,OPNAME),_op)<TYPEA,TYPEB>  > >::value)
1233 
1234 #define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR,SCALAR,OPNAME) \
1235   CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<typename internal::traits<EXPR>::Scalar,SCALAR>, const EXPR, \
1236                 const typename internal::plain_constant_type<EXPR,SCALAR>::type>
1237 
1238 #define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR,EXPR,OPNAME) \
1239   CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(internal::scalar_,OPNAME),_op)<SCALAR,typename internal::traits<EXPR>::Scalar>, \
1240                 const typename internal::plain_constant_type<EXPR,SCALAR>::type, const EXPR>
1241 
1242 // Workaround for MSVC 2010 (see ML thread "patch with compile for for MSVC 2010")
1243 #if EIGEN_COMP_MSVC_STRICT && (EIGEN_COMP_MSVC_STRICT<=1600)
1244 #define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) typename internal::enable_if<true,X>::type
1245 #else
1246 #define EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(X) X
1247 #endif
1248 
1249 #define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME) \
1250   template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
1251   EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type,OPNAME))\
1252   (METHOD)(const T& scalar) const { \
1253     typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,Scalar,T)>::type PromotedT; \
1254     return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedT,OPNAME)(derived(), \
1255            typename internal::plain_constant_type<Derived,PromotedT>::type(derived().rows(), derived().cols(), internal::scalar_constant_op<PromotedT>(scalar))); \
1256   }
1257 
1258 #define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
1259   template <typename T> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE friend \
1260   EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type,Derived,OPNAME)) \
1261   (METHOD)(const T& scalar, const StorageBaseType& matrix) { \
1262     typedef typename internal::promote_scalar_arg<Scalar,T,EIGEN_SCALAR_BINARY_SUPPORTED(OPNAME,T,Scalar)>::type PromotedT; \
1263     return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedT,Derived,OPNAME)( \
1264            typename internal::plain_constant_type<Derived,PromotedT>::type(matrix.derived().rows(), matrix.derived().cols(), internal::scalar_constant_op<PromotedT>(scalar)), matrix.derived()); \
1265   }
1266 
1267 #define EIGEN_MAKE_SCALAR_BINARY_OP(METHOD,OPNAME) \
1268   EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD,OPNAME) \
1269   EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD,OPNAME)
1270 
1271 
1272 #if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_USE_SYCL) && !defined(EIGEN_HIP_DEVICE_COMPILE)
1273   #define EIGEN_EXCEPTIONS
1274 #endif
1275 
1276 
1277 #ifdef EIGEN_EXCEPTIONS
1278 #  define EIGEN_THROW_X(X) throw X
1279 #  define EIGEN_THROW throw
1280 #  define EIGEN_TRY try
1281 #  define EIGEN_CATCH(X) catch (X)
1282 #else
1283 #  if defined(EIGEN_CUDA_ARCH)
1284 #    define EIGEN_THROW_X(X) asm("trap;")
1285 #    define EIGEN_THROW asm("trap;")
1286 #  elif defined(EIGEN_HIP_DEVICE_COMPILE)
1287 #    define EIGEN_THROW_X(X) asm("s_trap 0")
1288 #    define EIGEN_THROW asm("s_trap 0")
1289 #  else
1290 #    define EIGEN_THROW_X(X) std::abort()
1291 #    define EIGEN_THROW std::abort()
1292 #  endif
1293 #  define EIGEN_TRY if (true)
1294 #  define EIGEN_CATCH(X) else
1295 #endif
1296 
1297 
1298 #if EIGEN_HAS_CXX11_NOEXCEPT
1299 #   define EIGEN_INCLUDE_TYPE_TRAITS
1300 #   define EIGEN_NOEXCEPT noexcept
1301 #   define EIGEN_NOEXCEPT_IF(x) noexcept(x)
1302 #   define EIGEN_NO_THROW noexcept(true)
1303 #   define EIGEN_EXCEPTION_SPEC(X) noexcept(false)
1304 #else
1305 #   define EIGEN_NOEXCEPT
1306 #   define EIGEN_NOEXCEPT_IF(x)
1307 #   define EIGEN_NO_THROW throw()
1308 #   if EIGEN_COMP_MSVC || EIGEN_COMP_CXXVER>=17
1309       // MSVC does not support exception specifications (warning C4290),
1310       // and they are deprecated in c++11 anyway. This is even an error in c++17.
1311 #     define EIGEN_EXCEPTION_SPEC(X) throw()
1312 #   else
1313 #     define EIGEN_EXCEPTION_SPEC(X) throw(X)
1314 #   endif
1315 #endif
1316 
1317 #if EIGEN_HAS_VARIADIC_TEMPLATES
1318 // The all function is used to enable a variadic version of eigen_assert which can take a parameter pack as its input.
1319 namespace Eigen {
1320 namespace internal {
1321 
all()1322 inline bool all(){ return true; }
1323 
1324 template<typename T, typename ...Ts>
all(T t,Ts...ts)1325 bool all(T t, Ts ... ts){ return t && all(ts...); }
1326 
1327 }
1328 }
1329 #endif
1330 
1331 #if EIGEN_HAS_CXX11_OVERRIDE_FINAL
1332 // provide override and final specifiers if they are available:
1333 #   define EIGEN_OVERRIDE override
1334 #   define EIGEN_FINAL final
1335 #else
1336 #   define EIGEN_OVERRIDE
1337 #   define EIGEN_FINAL
1338 #endif
1339 
1340 // Wrapping #pragma unroll in a macro since it is required for SYCL
1341 #if defined(SYCL_DEVICE_ONLY)
1342   #if defined(_MSC_VER)
1343     #define EIGEN_UNROLL_LOOP __pragma(unroll)
1344   #else
1345     #define EIGEN_UNROLL_LOOP _Pragma("unroll")
1346   #endif
1347 #else
1348   #define EIGEN_UNROLL_LOOP
1349 #endif
1350 
1351 #endif // EIGEN_MACROS_H
1352