Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
Macros.h
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_MACROS_H
13#define EIGEN_MACROS_H
14// IWYU pragma: private
15#include "../InternalHeaderCheck.h"
16
17// for __cpp_lib feature test macros
18#if defined(__has_include) && __has_include(<version>)
19#include <version>
20#endif
21
22//------------------------------------------------------------------------------------------
23// Eigen version and basic defaults
24//------------------------------------------------------------------------------------------
25
26#define EIGEN_VERSION_AT_LEAST(x, y, z) \
27 (EIGEN_MAJOR_VERSION > x || \
28 (EIGEN_MAJOR_VERSION >= x && (EIGEN_MINOR_VERSION > y || (EIGEN_MINOR_VERSION >= y && EIGEN_PATCH_VERSION >= z))))
29
30#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
31#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::RowMajor
32#else
33#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION Eigen::ColMajor
34#endif
35
36#ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE
37#define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t
38#endif
39
40// Upperbound on the C++ version to use.
41// Expected values are 03, 11, 14, 17, etc.
42// By default, let's use an arbitrarily large C++ version.
43#ifndef EIGEN_MAX_CPP_VER
44#define EIGEN_MAX_CPP_VER 99
45#endif
46
52#ifndef EIGEN_FAST_MATH
53#define EIGEN_FAST_MATH 1
54#endif
55
56#ifndef EIGEN_STACK_ALLOCATION_LIMIT
57// 131072 == 128 KB
58#define EIGEN_STACK_ALLOCATION_LIMIT 131072
59// Marks the limit above as Eigen's own, so that a backend needing more room can raise it without
60// overriding a caller's stack-safety policy. ConfigureVectorization.h consumes and undefines it.
61#define EIGEN_STACK_ALLOCATION_LIMIT_WAS_DEFAULTED
62#endif
63
64//------------------------------------------------------------------------------------------
65// Compiler identification, EIGEN_COMP_*
66//------------------------------------------------------------------------------------------
67
69#ifdef __GNUC__
70#define EIGEN_COMP_GNUC (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
71#else
72#define EIGEN_COMP_GNUC 0
73#endif
74
76#if defined(__clang__)
77#define EIGEN_COMP_CLANG (__clang_major__ * 100 + __clang_minor__ * 10 + __clang_patchlevel__)
78#else
79#define EIGEN_COMP_CLANG 0
80#endif
81
84#if defined(__clang__) && defined(__apple_build_version__)
85#define EIGEN_COMP_CLANGAPPLE __apple_build_version__
86#else
87#define EIGEN_COMP_CLANGAPPLE 0
88#endif
89
91#if defined(__castxml__)
92#define EIGEN_COMP_CASTXML 1
93#else
94#define EIGEN_COMP_CASTXML 0
95#endif
96
98#if defined(__llvm__)
99#define EIGEN_COMP_LLVM 1
100#else
101#define EIGEN_COMP_LLVM 0
102#endif
103
105#if defined(__INTEL_COMPILER)
106#define EIGEN_COMP_ICC __INTEL_COMPILER
107#else
108#define EIGEN_COMP_ICC 0
109#endif
110
112#if defined(__INTEL_CLANG_COMPILER)
113#define EIGEN_COMP_CLANGICC __INTEL_CLANG_COMPILER
114#else
115#define EIGEN_COMP_CLANGICC 0
116#endif
117
119#if defined(__MINGW32__)
120#define EIGEN_COMP_MINGW 1
121#else
122#define EIGEN_COMP_MINGW 0
123#endif
124
126#if defined(__SUNPRO_CC)
127#define EIGEN_COMP_SUNCC 1
128#else
129#define EIGEN_COMP_SUNCC 0
130#endif
131
133#if defined(_MSC_VER)
134#define EIGEN_COMP_MSVC _MSC_VER
135#else
136#define EIGEN_COMP_MSVC 0
137#endif
138
139#if defined(__NVCC__)
140// CUDA 11.4+ always defines __CUDACC_VER_MAJOR__.
141#define EIGEN_COMP_NVCC ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100))
142#else
143#define EIGEN_COMP_NVCC 0
144#endif
145
146// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC:
147// name ver MSC_VER
148// 2015 14 1900
149// "15" 15 1900
150// 2017-14.1 15.0 1910
151// 2017-14.11 15.3 1911
152// 2017-14.12 15.5 1912
153// 2017-14.13 15.6 1913
154// 2017-14.14 15.7 1914
155// 2017 15.8 1915
156// 2017 15.9 1916
157// 2019 RTW 16.0 1920
158
160#if defined(_MSVC_LANG)
161#define EIGEN_COMP_MSVC_LANG _MSVC_LANG
162#else
163#define EIGEN_COMP_MSVC_LANG 0
164#endif
165
166// For the record, here is a table summarizing the possible values for EIGEN_COMP_MSVC_LANG:
167// MSVC option Standard MSVC_LANG
168// /std:c++14 (default as of VS 2019) C++14 201402L
169// /std:c++17 C++17 201703L
170// /std:c++latest >C++17 >201703L
171
174#if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC || EIGEN_COMP_LLVM || EIGEN_COMP_CLANG)
175#define EIGEN_COMP_MSVC_STRICT _MSC_VER
176#else
177#define EIGEN_COMP_MSVC_STRICT 0
178#endif
179
181// XLC version
182// 3.1 0x0301
183// 4.5 0x0405
184// 5.0 0x0500
185// 12.1 0x0C01
186#if defined(__IBMCPP__) || defined(__xlc__) || defined(__ibmxl__)
187#define EIGEN_COMP_IBM __xlC__
188#else
189#define EIGEN_COMP_IBM 0
190#endif
191
193#if defined(__PGI)
194#define EIGEN_COMP_PGI (__PGIC__ * 100 + __PGIC_MINOR__)
195#else
196#define EIGEN_COMP_PGI 0
197#endif
198
200#if defined(__NVCOMPILER)
201#define EIGEN_COMP_NVHPC (__NVCOMPILER_MAJOR__ * 100 + __NVCOMPILER_MINOR__)
202#else
203#define EIGEN_COMP_NVHPC 0
204#endif
205
207#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
208#define EIGEN_COMP_ARM 1
209#else
210#define EIGEN_COMP_ARM 0
211#endif
212
214#if defined(__EMSCRIPTEN__)
215#define EIGEN_COMP_EMSCRIPTEN 1
216#else
217#define EIGEN_COMP_EMSCRIPTEN 0
218#endif
219
223#if defined(__FUJITSU)
224#define EIGEN_COMP_FCC (__FCC_major__ * 100 + __FCC_minor__ * 10 + __FCC_patchlevel__)
225#else
226#define EIGEN_COMP_FCC 0
227#endif
228
232#if defined(__CLANG_FUJITSU)
233#define EIGEN_COMP_CLANGFCC (__FCC_major__ * 100 + __FCC_minor__ * 10 + __FCC_patchlevel__)
234#else
235#define EIGEN_COMP_CLANGFCC 0
236#endif
237
241#if defined(_CRAYC) && !defined(__clang__)
242#define EIGEN_COMP_CPE (_RELEASE_MAJOR * 100 + _RELEASE_MINOR * 10 + _RELEASE_PATCHLEVEL)
243#else
244#define EIGEN_COMP_CPE 0
245#endif
246
250#if defined(_CRAYC) && defined(__clang__)
251#define EIGEN_COMP_CLANGCPE (_RELEASE_MAJOR * 100 + _RELEASE_MINOR * 10 + _RELEASE_PATCHLEVEL)
252#else
253#define EIGEN_COMP_CLANGCPE 0
254#endif
255
257#if defined(__LCC__) && defined(__MCST__)
258#define EIGEN_COMP_LCC (__LCC__ * 100 + __LCC_MINOR__)
259#else
260#define EIGEN_COMP_LCC 0
261#endif
262
265#if EIGEN_COMP_GNUC && \
266 !(EIGEN_COMP_CLANG || EIGEN_COMP_ICC || EIGEN_COMP_CLANGICC || EIGEN_COMP_MINGW || EIGEN_COMP_PGI || \
267 EIGEN_COMP_NVHPC || EIGEN_COMP_IBM || EIGEN_COMP_ARM || EIGEN_COMP_EMSCRIPTEN || EIGEN_COMP_FCC || \
268 EIGEN_COMP_CLANGFCC || EIGEN_COMP_CPE || EIGEN_COMP_CLANGCPE || EIGEN_COMP_LCC)
269#define EIGEN_COMP_GNUC_STRICT 1
270#else
271#define EIGEN_COMP_GNUC_STRICT 0
272#endif
273
274// GCC, and compilers that pretend to be it, have different version schemes, so this only makes sense to use with the
275// real GCC.
276#if EIGEN_COMP_GNUC_STRICT
277#define EIGEN_GNUC_STRICT_AT_LEAST(x, y, z) \
278 ((__GNUC__ > x) || (__GNUC__ == x && __GNUC_MINOR__ > y) || \
279 (__GNUC__ == x && __GNUC_MINOR__ == y && __GNUC_PATCHLEVEL__ >= z))
280#define EIGEN_GNUC_STRICT_LESS_THAN(x, y, z) \
281 ((__GNUC__ < x) || (__GNUC__ == x && __GNUC_MINOR__ < y) || \
282 (__GNUC__ == x && __GNUC_MINOR__ == y && __GNUC_PATCHLEVEL__ < z))
283#else
284#define EIGEN_GNUC_STRICT_AT_LEAST(x, y, z) 0
285#define EIGEN_GNUC_STRICT_LESS_THAN(x, y, z) 0
286#endif
287
288// Work around GCC PR tree-optimization/92420, which miscompiles some packetized complex arithmetic under -ffast-math.
289// The bug was introduced by GCC r238039, fixed on the GCC 8 branch by
290// https://gcc.gnu.org/g:785eda9390473e42f0e0b7199c42032a0432de68 and on the GCC 9 branch by
291// https://gcc.gnu.org/g:2d8ea3a0a6095a56b7c59c50b1068d602cde934a.
292// See also GitLab issues #1839 and #1840.
293#if defined(__FAST_MATH__) && EIGEN_COMP_GNUC_STRICT && EIGEN_GNUC_STRICT_AT_LEAST(7, 0, 0) && \
294 (EIGEN_GNUC_STRICT_LESS_THAN(8, 4, 0) || \
295 (EIGEN_GNUC_STRICT_AT_LEAST(9, 0, 0) && EIGEN_GNUC_STRICT_LESS_THAN(9, 3, 0)))
296#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_BUG 1
297// Disable the affected loop vectorizer around the complex packet helpers.
298#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_WORKAROUND_PUSH \
299 _Pragma("GCC push_options") _Pragma("GCC optimize(\"no-tree-loop-vectorize\")")
300#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_WORKAROUND_POP _Pragma("GCC pop_options")
301#else
302#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_BUG 0
303#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_WORKAROUND_PUSH
304#define EIGEN_GCC_FAST_MATH_COMPLEX_VECTORIZE_WORKAROUND_POP
305#endif
306
309#if EIGEN_COMP_CLANG && !(EIGEN_COMP_CLANGAPPLE || EIGEN_COMP_CLANGICC || EIGEN_COMP_CLANGFCC || EIGEN_COMP_CLANGCPE)
310#define EIGEN_COMP_CLANG_STRICT 1
311#else
312#define EIGEN_COMP_CLANG_STRICT 0
313#endif
314
315// Clang, and compilers forked from it, have different version schemes, so this only makes sense to use with the real
316// Clang.
317#if EIGEN_COMP_CLANG_STRICT
318#define EIGEN_CLANG_STRICT_AT_LEAST(x, y, z) \
319 ((__clang_major__ > x) || (__clang_major__ == x && __clang_minor__ > y) || \
320 (__clang_major__ == x && __clang_minor__ == y && __clang_patchlevel__ >= z))
321#define EIGEN_CLANG_STRICT_LESS_THAN(x, y, z) \
322 ((__clang_major__ < x) || (__clang_major__ == x && __clang_minor__ < y) || \
323 (__clang_major__ == x && __clang_minor__ == y && __clang_patchlevel__ < z))
324#else
325#define EIGEN_CLANG_STRICT_AT_LEAST(x, y, z) 0
326#define EIGEN_CLANG_STRICT_LESS_THAN(x, y, z) 0
327#endif
328
329//------------------------------------------------------------------------------------------
330// Architecture identification, EIGEN_ARCH_*
331//------------------------------------------------------------------------------------------
332
333#if defined(__x86_64__) || (defined(_M_X64) && !defined(_M_ARM64EC)) || defined(__amd64)
334#define EIGEN_ARCH_x86_64 1
335#else
336#define EIGEN_ARCH_x86_64 0
337#endif
338
339#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__i386)
340#define EIGEN_ARCH_i386 1
341#else
342#define EIGEN_ARCH_i386 0
343#endif
344
345#if EIGEN_ARCH_x86_64 || EIGEN_ARCH_i386
346#define EIGEN_ARCH_i386_OR_x86_64 1
347#else
348#define EIGEN_ARCH_i386_OR_x86_64 0
349#endif
350
352#if defined(__arm__)
353#define EIGEN_ARCH_ARM 1
354#else
355#define EIGEN_ARCH_ARM 0
356#endif
357
359#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
360#define EIGEN_ARCH_ARM64 1
361#else
362#define EIGEN_ARCH_ARM64 0
363#endif
364
366#if EIGEN_ARCH_ARM || EIGEN_ARCH_ARM64
367#define EIGEN_ARCH_ARM_OR_ARM64 1
368#else
369#define EIGEN_ARCH_ARM_OR_ARM64 0
370#endif
371
373#if EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_ARCH) && __ARM_ARCH >= 8
374#define EIGEN_ARCH_ARMV8 1
375#else
376#define EIGEN_ARCH_ARMV8 0
377#endif
378
381#ifndef EIGEN_HAS_ARM64_FP16
382// NOTE: Older versions of Clang miscompile `__fp16` implicit conversions to `float`
383// on ARMv7 targets: <https://gitlab.com/libeigen/eigen/-/merge_requests/2273#note_3400347860>.
384#if EIGEN_ARCH_ARMV8 && defined(__ARM_FP16_FORMAT_IEEE)
385#define EIGEN_HAS_ARM64_FP16 1
386#else
387#define EIGEN_HAS_ARM64_FP16 0
388#endif
389#endif
390
392#if defined(__mips__) || defined(__mips)
393#define EIGEN_ARCH_MIPS 1
394#else
395#define EIGEN_ARCH_MIPS 0
396#endif
397
399#if defined(__loongarch64)
400#define EIGEN_ARCH_LOONGARCH64 1
401#else
402#define EIGEN_ARCH_LOONGARCH64 0
403#endif
404
406#if defined(__sparc__) || defined(__sparc)
407#define EIGEN_ARCH_SPARC 1
408#else
409#define EIGEN_ARCH_SPARC 0
410#endif
411
413#if defined(__ia64__)
414#define EIGEN_ARCH_IA64 1
415#else
416#define EIGEN_ARCH_IA64 0
417#endif
418
420#if defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC) || defined(__POWERPC__)
421#define EIGEN_ARCH_PPC 1
422#else
423#define EIGEN_ARCH_PPC 0
424#endif
425
427#if defined(__riscv)
428#define EIGEN_ARCH_RISCV 1
429#else
430#define EIGEN_ARCH_RISCV 0
431#endif
432
433//------------------------------------------------------------------------------------------
434// Operating system identification, EIGEN_OS_*
435//------------------------------------------------------------------------------------------
436
438#if defined(__unix__) || defined(__unix)
439#define EIGEN_OS_UNIX 1
440#else
441#define EIGEN_OS_UNIX 0
442#endif
443
445#if defined(__linux__)
446#define EIGEN_OS_LINUX 1
447#else
448#define EIGEN_OS_LINUX 0
449#endif
450
452// note: ANDROID is defined when using ndk_build, __ANDROID__ is defined when using a standalone toolchain.
453#if defined(__ANDROID__) || defined(ANDROID)
454#define EIGEN_OS_ANDROID 1
455
456// Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
457// <android/ndk-version.h>. Include it when available so NDK-version-specific
458// workarounds can use these macros.
459#if defined __has_include
460#if __has_include(<android/ndk-version.h>)
461#include <android/ndk-version.h>
462#endif
463#endif
464
465#else
466#define EIGEN_OS_ANDROID 0
467#endif
468
470#if defined(__gnu_linux__) && !(EIGEN_OS_ANDROID)
471#define EIGEN_OS_GNULINUX 1
472#else
473#define EIGEN_OS_GNULINUX 0
474#endif
475
477#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
478#define EIGEN_OS_BSD 1
479#else
480#define EIGEN_OS_BSD 0
481#endif
482
484#if defined(__APPLE__)
485#define EIGEN_OS_MAC 1
486#else
487#define EIGEN_OS_MAC 0
488#endif
489
491#if defined(__QNX__)
492#define EIGEN_OS_QNX 1
493#else
494#define EIGEN_OS_QNX 0
495#endif
496
498#if defined(_WIN32)
499#define EIGEN_OS_WIN 1
500#else
501#define EIGEN_OS_WIN 0
502#endif
503
505#if defined(_WIN64)
506#define EIGEN_OS_WIN64 1
507#else
508#define EIGEN_OS_WIN64 0
509#endif
510
512#if defined(_WIN32_WCE)
513#define EIGEN_OS_WINCE 1
514#else
515#define EIGEN_OS_WINCE 0
516#endif
517
519#if defined(__CYGWIN__)
520#define EIGEN_OS_CYGWIN 1
521#else
522#define EIGEN_OS_CYGWIN 0
523#endif
524
526#if EIGEN_OS_WIN && !(EIGEN_OS_WINCE || EIGEN_OS_CYGWIN)
527#define EIGEN_OS_WIN_STRICT 1
528#else
529#define EIGEN_OS_WIN_STRICT 0
530#endif
531
533// compiler solaris __SUNPRO_C
534// version studio
535// 5.7 10 0x570
536// 5.8 11 0x580
537// 5.9 12 0x590
538// 5.10 12.1 0x5100
539// 5.11 12.2 0x5110
540// 5.12 12.3 0x5120
541#if (defined(sun) || defined(__sun)) && !(defined(__SVR4) || defined(__svr4__))
542#define EIGEN_OS_SUN __SUNPRO_C
543#else
544#define EIGEN_OS_SUN 0
545#endif
546
548#if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__))
549#define EIGEN_OS_SOLARIS 1
550#else
551#define EIGEN_OS_SOLARIS 0
552#endif
553
554//------------------------------------------------------------------------------------------
555// Detect GPU compilers and architectures
556//------------------------------------------------------------------------------------------
557
558// NVCC is not supported as the target platform for HIPCC
559// Note that this also makes EIGEN_CUDACC and EIGEN_HIPCC mutually exclusive
560#if defined(__NVCC__) && defined(__HIPCC__)
561#error "NVCC as the target platform for HIPCC is currently not supported."
562#endif
563
564// SYCL CUDA kernels still need CUDA scalar math unless Eigen's SYCL backend is selected.
565#if defined(__CUDACC__) && !defined(EIGEN_NO_CUDA) && (!defined(__SYCL_DEVICE_ONLY__) || !defined(EIGEN_USE_SYCL))
566// Means the compiler is either nvcc or clang with CUDA enabled
567#define EIGEN_CUDACC __CUDACC__
568#endif
569
570#if defined(__CUDA_ARCH__) && !defined(EIGEN_NO_CUDA) && \
571 (!defined(__SYCL_DEVICE_ONLY__) || (defined(__CUDACC__) && !defined(EIGEN_USE_SYCL)))
572// Means we are generating code for the device
573#define EIGEN_CUDA_ARCH __CUDA_ARCH__
574#endif
575
576#if defined(EIGEN_CUDACC)
577#include <cuda.h>
578#define EIGEN_CUDA_SDK_VER (CUDA_VERSION * 10)
579#else
580#define EIGEN_CUDA_SDK_VER 0
581#endif
582
583// CUDA 11.8 is the oldest toolkit in GPU CI (it supports the sm_89 runners), not a new packet-intrinsic requirement.
584#if defined(EIGEN_CUDACC) && EIGEN_CUDA_SDK_VER > 0 && EIGEN_CUDA_SDK_VER < 110800
585#error "Eigen requires CUDA 11.8 or later."
586#endif
587
588// Guard the CUDA device pass with a clear error when targeting architectures
589// older than Maxwell (sm_50).
590#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH < 500
591#error "Eigen requires CUDA compute capability >= 5.0 (sm_50). Compile with -arch=sm_50 or higher."
592#endif
593
594#if defined(__HIPCC__) && !defined(EIGEN_NO_HIP) && !defined(__SYCL_DEVICE_ONLY__)
595// Means the compiler is HIPCC (analogous to EIGEN_CUDACC, but for HIP)
596#define EIGEN_HIPCC __HIPCC__
597
598// We need to include hip_runtime.h here because it pulls in
599// ++ hip_common.h which contains the define for __HIP_DEVICE_COMPILE__
600// ++ host_defines.h which contains the defines for the __host__ and __device__ macros
601#include <hip/hip_runtime.h>
602
603// Eigen requires ROCm/HIP >= 5.6 (GFX906 minimum architecture).
604// This floor exists to allow simplifying shared CUDA/HIP preprocessor guards —
605// all __HIP_ARCH_HAS_WARP_SHUFFLE__, __HIP_ARCH_HAS_FP16__, etc. are always true on GFX906+.
606#if defined(HIP_VERSION_MAJOR) && (HIP_VERSION_MAJOR < 5 || (HIP_VERSION_MAJOR == 5 && HIP_VERSION_MINOR < 6))
607#error "Eigen requires ROCm/HIP >= 5.6."
608#endif
609
610#if defined(__HIP_DEVICE_COMPILE__) && !defined(__SYCL_DEVICE_ONLY__)
611// analogous to EIGEN_CUDA_ARCH, but for HIP
612#define EIGEN_HIP_DEVICE_COMPILE __HIP_DEVICE_COMPILE__
613#endif
614
615#endif
616
617// Launch-bounds attribute under either GPU compiler, nothing elsewhere. Eigen's
618// kernels declare 1024 (EIGEN_HIP_LAUNCH_BOUNDS_1024 is the older spelling):
619// hipcc defaults to 256 and refuses larger blocks at launch, and nvcc without a
620// bound may allocate registers so that a 1024-thread launch fails with
621// cudaErrorLaunchOutOfResources (the 3D convolution kernel does).
622#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
623#define EIGEN_GPU_LAUNCH_BOUNDS(n) __launch_bounds__(n)
624#else
625#define EIGEN_GPU_LAUNCH_BOUNDS(n)
626#endif
627#if !defined(EIGEN_HIP_LAUNCH_BOUNDS_1024)
628#define EIGEN_HIP_LAUNCH_BOUNDS_1024 EIGEN_GPU_LAUNCH_BOUNDS(1024)
629#endif
630
631// Unify CUDA/HIPCC
632
633#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
634//
635// If either EIGEN_CUDACC or EIGEN_HIPCC is defined, then define EIGEN_GPUCC
636//
637#define EIGEN_GPUCC
638// NOTE: Some platforms (e.g. SPIRV) artificially set the CUDA SDK version to 0,
639// and don't support FP16, so we need to check the version number here. Every real toolkit is past the CUDA 11.8
640// floor checked above, so this only distinguishes "has a version" from "reports none".
641#if defined(EIGEN_CUDACC) && EIGEN_CUDA_SDK_VER > 0
642#define EIGEN_HAS_CUDA_FP16 1
643#elif defined(EIGEN_HIPCC)
644#define EIGEN_HAS_HIP_FP16 1
645#endif
646#if defined(EIGEN_HAS_CUDA_FP16) || defined(EIGEN_HAS_HIP_FP16)
647#define EIGEN_HAS_GPU_FP16 1
648#endif
649//
650// EIGEN_HIPCC implies the HIP compiler and is used to tweak Eigen code for use in HIP kernels
651// EIGEN_CUDACC implies the CUDA compiler and is used to tweak Eigen code for use in CUDA kernels
652//
653// In most cases the same tweaks are required to the Eigen code to enable in both the HIP and CUDA kernels.
654// For those cases, the corresponding code should be guarded with
655// #if defined(EIGEN_GPUCC)
656// instead of
657// #if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
658//
659// For cases where the tweak is specific to HIP, the code should be guarded with
660// #if defined(EIGEN_HIPCC)
661//
662// For cases where the tweak is specific to CUDA, the code should be guarded with
663// #if defined(EIGEN_CUDACC)
664//
665#endif
666
667#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
668//
669// If either EIGEN_CUDA_ARCH or EIGEN_HIP_DEVICE_COMPILE is defined, then define EIGEN_GPU_COMPILE_PHASE
670//
671#define EIGEN_GPU_COMPILE_PHASE
672//
673// GPU compilers (HIPCC, NVCC) typically do two passes over the source code,
674// + one to compile the source for the "host" (ie CPU)
675// + another to compile the source for the "device" (ie. GPU)
676//
677// Code that needs to enabled only during the either the "host" or "device" compilation phase
678// needs to be guarded with a macro that indicates the current compilation phase
679//
680// EIGEN_HIP_DEVICE_COMPILE implies the device compilation phase in HIP
681// EIGEN_CUDA_ARCH implies the device compilation phase in CUDA
682//
683// In most cases, the "host" / "device" specific code is the same for both HIP and CUDA
684// For those cases, the code should be guarded with
685// #if defined(EIGEN_GPU_COMPILE_PHASE)
686// instead of
687// #if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE)
688//
689// For cases where the tweak is specific to HIP, the code should be guarded with
690// #if defined(EIGEN_HIP_DEVICE_COMPILE)
691//
692// For cases where the tweak is specific to CUDA, the code should be guarded with
693// #if defined(EIGEN_CUDA_ARCH)
694//
695#endif
696
699#if EIGEN_ARCH_ARM_OR_ARM64
700#ifndef EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
701// Clang only supports FP16 on aarch64, and not all intrinsics are available
702// on A32 anyways even in GCC (e.g. vdiv_f16, vsqrt_f16).
703#if EIGEN_ARCH_ARM64 && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && !defined(EIGEN_GPU_COMPILE_PHASE)
704#define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 1
705#else
706#define EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC 0
707#endif
708#endif
709#endif
710
713#if EIGEN_ARCH_ARM_OR_ARM64
714#ifndef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
715// Clang only supports FP16 on aarch64, and not all intrinsics are available
716// on A32 anyways, even in GCC (e.g. vceqh_f16).
717#if EIGEN_ARCH_ARM64 && defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC) && !defined(EIGEN_GPU_COMPILE_PHASE)
718#define EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC 1
719#endif
720#endif
721#endif
722
723#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__)
724// Eigen's SYCL dispatch flag. SYCL_DEVICE_ONLY is kept for users, but AdaptiveCpp's headers also define it.
725#define EIGEN_SYCL_DEVICE_ONLY
726#ifndef SYCL_DEVICE_ONLY
727#define SYCL_DEVICE_ONLY
728#endif
729#endif
730
731// Under fast-math flags (-ffinite-math-only in particular), clang attaches the
732// `nofpclass(nan inf)` attribute to every function argument and return value of floating-point
733// (vector) type. A value that is a compile-time constant of NaN or infinity class -- e.g. the
734// all-ones bitmasks of ptrue and peven_mask, or the infinity/NaN constants guarding special
735// cases -- provably violates that attribute and is folded to poison, silently deleting the code
736// that consumes it. This barrier makes such a constant unprovable, at the cost of a stack
737// store/load pair where it is materialized. It uses a memory operand so that it works for any
738// packet type, including aggregates, and expands to nothing outside affected builds.
739#if EIGEN_COMP_CLANG && defined(__FINITE_MATH_ONLY__) && __FINITE_MATH_ONLY__ && !defined(EIGEN_GPU_COMPILE_PHASE) && \
740 !defined(__SYCL_DEVICE_ONLY__)
741#define EIGEN_FAST_MATH_CONSTANT_BARRIER(X) __asm__("" : "+m"(X))
742#else
743#define EIGEN_FAST_MATH_CONSTANT_BARRIER(X)
744#endif
745
746//------------------------------------------------------------------------------------------
747// Detect Compiler/Architecture/OS specific features
748//------------------------------------------------------------------------------------------
749
750// Cross compiler wrapper around LLVM's __has_builtin
751#ifdef __has_builtin
752#define EIGEN_HAS_BUILTIN(x) __has_builtin(x)
753#else
754#define EIGEN_HAS_BUILTIN(x) 0
755#endif
756
757// Cross compiler wrapper around LLVM's __has_attribute
758#ifdef __has_attribute
759#define EIGEN_HAS_ATTRIBUTE(x) __has_attribute(x)
760#else
761#define EIGEN_HAS_ATTRIBUTE(x) 0
762#endif
763
764// A Clang feature extension to determine compiler features.
765// We use it to determine 'cxx_rvalue_references'
766#ifndef __has_feature
767#define __has_feature(x) 0
768#endif
769
770// The macro EIGEN_CPLUSPLUS is a replacement for __cplusplus/_MSVC_LANG that
771// works for both platforms, indicating the C++ standard version number.
772//
773// With MSVC, without defining /Zc:__cplusplus, the __cplusplus macro will
774// report 199711L regardless of the language standard specified via /std.
775// We need to rely on _MSVC_LANG instead where available. Older MSVC versions
776// supported by Eigen do not define _MSVC_LANG, so use Eigen's minimum standard.
777#if EIGEN_COMP_MSVC_LANG > 0
778#define EIGEN_CPLUSPLUS EIGEN_COMP_MSVC_LANG
779#elif EIGEN_COMP_MSVC
780#define EIGEN_CPLUSPLUS 201402L
781#elif defined(__cplusplus)
782#define EIGEN_CPLUSPLUS __cplusplus
783#else
784#define EIGEN_CPLUSPLUS 0
785#endif
786
787// The macro EIGEN_COMP_CXXVER defines the c++ version expected by the compiler.
788// For instance, if compiling with gcc and -std=c++17, then EIGEN_COMP_CXXVER
789// is defined to 17.
790#if EIGEN_CPLUSPLUS >= 202002L
791#define EIGEN_COMP_CXXVER 20
792#elif EIGEN_CPLUSPLUS >= 201703L
793#define EIGEN_COMP_CXXVER 17
794#elif EIGEN_CPLUSPLUS >= 201402L
795#define EIGEN_COMP_CXXVER 14
796#else
797#define EIGEN_COMP_CXXVER 0
798#endif
799
800// The macros EIGEN_HAS_CXX?? defines a rough estimate of available c++ features
801// but in practice we should not rely on them but rather on the availability of
802// individual features as defined later.
803// This is why there is no EIGEN_HAS_CXX17.
804#if EIGEN_MAX_CPP_VER < 14 || EIGEN_COMP_CXXVER < 14 || (EIGEN_COMP_MSVC_STRICT && EIGEN_COMP_MSVC < 1910) || \
805 (EIGEN_COMP_ICC && EIGEN_COMP_ICC < 1700) || (EIGEN_COMP_CLANG_STRICT && EIGEN_COMP_CLANG < 390) || \
806 (EIGEN_COMP_CLANGAPPLE && EIGEN_COMP_CLANGAPPLE < 9000000) || (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC < 510)
807#error Eigen requires at least c++14 support.
808#endif
809
810// Deprecated compatibility macro. Eigen requires C++14 and no longer uses this
811// token internally, but keep it defined so downstream #if EIGEN_HAS_C99_MATH
812// checks do not trip -Wundef.
813#ifndef EIGEN_HAS_C99_MATH
814#define EIGEN_HAS_C99_MATH 1
815#endif
816
817// Does the compiler support std::hash?
818#ifndef EIGEN_HAS_STD_HASH
819// The std::hash struct is not labelled as a __device__ function and is not
820// constexpr, so cannot be used on device.
821#if !defined(EIGEN_GPU_COMPILE_PHASE)
822#define EIGEN_HAS_STD_HASH 1
823#else
824#define EIGEN_HAS_STD_HASH 0
825#endif
826#endif // EIGEN_HAS_STD_HASH
827
828#ifndef EIGEN_HAS_STD_INVOKE_RESULT
829#if EIGEN_MAX_CPP_VER >= 17 && EIGEN_COMP_CXXVER >= 17
830#define EIGEN_HAS_STD_INVOKE_RESULT 1
831#else
832#define EIGEN_HAS_STD_INVOKE_RESULT 0
833#endif
834#endif
835
836#define EIGEN_CONSTEXPR constexpr
837
838// NOTE: the required Apple's clang version is very conservative
839// and it could be that XCode 9 works just fine.
840// NOTE: the MSVC version is based on https://en.cppreference.com/w/cpp/compiler_support
841// and not tested.
842// NOTE: Intel C++ Compiler Classic (icc) Version 19.0 and later supports dynamic allocation
843// for over-aligned data, but not in a manner that is compatible with Eigen.
844// See https://gitlab.com/libeigen/eigen/-/issues/2575
845// Does the compiler support C++17 if constexpr?
846#ifndef EIGEN_HAS_CXX17_IFCONSTEXPR
847#if EIGEN_MAX_CPP_VER >= 17 && EIGEN_COMP_CXXVER >= 17 && \
848 ((EIGEN_COMP_MSVC >= 1911) || (EIGEN_GNUC_STRICT_AT_LEAST(7, 0, 0)) || EIGEN_COMP_CLANG_STRICT || \
849 (EIGEN_COMP_CLANGAPPLE && EIGEN_COMP_CLANGAPPLE >= 10000000))
850#define EIGEN_HAS_CXX17_IFCONSTEXPR 1
851#endif
852#endif
853
854#ifndef EIGEN_HAS_CXX17_OVERALIGN
855#if EIGEN_MAX_CPP_VER >= 17 && EIGEN_COMP_CXXVER >= 17 && \
856 ((EIGEN_COMP_MSVC >= 1912) || (EIGEN_GNUC_STRICT_AT_LEAST(7, 0, 0)) || (EIGEN_CLANG_STRICT_AT_LEAST(5, 0, 0)) || \
857 (EIGEN_COMP_CLANGAPPLE && EIGEN_COMP_CLANGAPPLE >= 10000000)) && \
858 !EIGEN_COMP_ICC
859#define EIGEN_HAS_CXX17_OVERALIGN 1
860#else
861#define EIGEN_HAS_CXX17_OVERALIGN 0
862#endif
863#endif
864
865#if defined(EIGEN_CUDACC)
866// Enable device-side constexpr when the toolchain supports relaxed constexpr rules.
867#if defined(__NVCC__)
868// nvcc considers constexpr functions as __host__ __device__ with the option --expt-relaxed-constexpr
869#ifdef __CUDACC_RELAXED_CONSTEXPR__
870#define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
871#endif
872#elif defined(__clang__) && defined(__CUDA__) && __has_feature(cxx_relaxed_constexpr)
873// clang++ always considers constexpr functions as implicitly __host__ __device__
874#define EIGEN_CONSTEXPR_ARE_DEVICE_FUNC
875#endif
876#endif
877
878// Does the compiler support the __int128 and __uint128_t extensions for 128-bit
879// integer arithmetic?
880//
881// Clang and GCC define __SIZEOF_INT128__ when these extensions are supported,
882// but we avoid using them in certain cases:
883//
884// * Building using Clang for Windows, where the Clang runtime library has
885// 128-bit support only on LP64 architectures, but Windows is LLP64.
886#ifndef EIGEN_HAS_BUILTIN_INT128
887#if defined(__SIZEOF_INT128__) && !(EIGEN_OS_WIN && EIGEN_COMP_CLANG)
888#define EIGEN_HAS_BUILTIN_INT128 1
889#else
890#define EIGEN_HAS_BUILTIN_INT128 0
891#endif
892#endif
893
894// Does the compiler support vector types?
895#if EIGEN_HAS_ATTRIBUTE(ext_vector_type) && EIGEN_HAS_BUILTIN(__builtin_vectorelements)
896#define EIGEN_ARCH_VECTOR_EXTENSIONS 1
897#else
898#define EIGEN_ARCH_VECTOR_EXTENSIONS 0
899#endif
900
901// Multidimensional subscript operator feature test
902#if defined(__cpp_multidimensional_subscript) && __cpp_multidimensional_subscript >= 202110L
903#define EIGEN_MULTIDIMENSIONAL_SUBSCRIPT
904#endif
905
906//------------------------------------------------------------------------------------------
907// Preprocessor programming helpers
908//------------------------------------------------------------------------------------------
909
910// This macro can be used to prevent from macro expansion, e.g.:
911// std::max EIGEN_NOT_A_MACRO(a,b)
912#define EIGEN_NOT_A_MACRO
913
914#define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
915
916// concatenate two tokens
917#define EIGEN_CAT2(a, b) a##b
918#define EIGEN_CAT(a, b) EIGEN_CAT2(a, b)
919
920#define EIGEN_COMMA ,
921
922// convert a token to a string
923#define EIGEN_MAKESTRING2(a) #a
924#define EIGEN_MAKESTRING(a) EIGEN_MAKESTRING2(a)
925
926// EIGEN_STRONG_INLINE is a stronger version of the inline, using __forceinline on MSVC,
927// but it still doesn't use GCC's always_inline. This is useful in (common) situations where MSVC needs forceinline
928// but GCC is still doing fine with just inline.
929#ifndef EIGEN_STRONG_INLINE
930#if (EIGEN_COMP_MSVC || EIGEN_COMP_ICC) && !defined(EIGEN_GPUCC)
931#define EIGEN_STRONG_INLINE __forceinline
932#else
933#define EIGEN_STRONG_INLINE inline
934#endif
935#endif
936
937// EIGEN_ALWAYS_INLINE is the strongest default inline hint. It makes the function inline and, where supported,
938// adds attributes to maximize inlining. This should only be used when really necessary: in particular, the
939// __attribute__((always_inline)) used on GCC is often unnecessary and can severely harm compile times.
940#ifndef EIGEN_ALWAYS_INLINE
941#if EIGEN_COMP_GNUC && !defined(EIGEN_SYCL_DEVICE_ONLY)
942#define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) inline
943#else
944#define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
945#endif
946#endif
947
948// EIGEN_LAMBDA_ALWAYS_INLINE forces inlining of lambda functions.
949// On GCC/Clang, __attribute__((always_inline)) works on lambdas.
950// On MSVC, [[msvc::forceinline]] cannot be applied to generic lambdas
951// (those with auto parameters), so we leave it empty and rely on the
952// optimizer to inline small lambda bodies at /O2.
953#ifndef EIGEN_LAMBDA_ALWAYS_INLINE
954#if EIGEN_COMP_GNUC && !defined(EIGEN_SYCL_DEVICE_ONLY)
955#define EIGEN_LAMBDA_ALWAYS_INLINE __attribute__((always_inline))
956#else
957#define EIGEN_LAMBDA_ALWAYS_INLINE
958#endif
959#endif
960
961// GCC 15.1 and 15.2 SLP-vectorize some code wrongly; GCC 15.3 and 16 are correct. One defect is GCC PR
962// tree-optimization/124802, fixed for 15.3 by https://gcc.gnu.org/g:8d8e8cd6fbed9029e996a8d7298aa82fd453345e: with FMA,
963// the lanes {re, im, re, im} of one complex product re = a0*b0 - a1*b1, im = a0*b1 + a1*b0 come out as
964// {p0*p0 - p1, ...}, p0 = a0*b0, p1 = a1*b1. MinGW's GCC 15.2 miscompiles the TRMV of #3214 too, but
965// EIGEN_COMP_GNUC_STRICT leaves MinGW out.
966#if (EIGEN_COMP_GNUC_STRICT || (EIGEN_COMP_MINGW && !EIGEN_COMP_CLANG)) && EIGEN_COMP_GNUC >= 1500 && \
967 EIGEN_COMP_GNUC < 1530
968#define EIGEN_GCC15_SLP_BUG 1
969#else
970#define EIGEN_GCC15_SLP_BUG 0
971#endif
972
973#ifndef EIGEN_DONT_INLINE
974#if EIGEN_COMP_GNUC
975#define EIGEN_DONT_INLINE __attribute__((noinline))
976#elif EIGEN_COMP_MSVC
977#define EIGEN_DONT_INLINE __declspec(noinline)
978#else
979#define EIGEN_DONT_INLINE
980#endif
981#endif
982
983#if EIGEN_COMP_GNUC
984#define EIGEN_PERMISSIVE_EXPR __extension__
985#else
986#define EIGEN_PERMISSIVE_EXPR
987#endif
988
989// GPU stuff
990
991// Disable some features when compiling with GPU compilers (SYCL/HIPCC)
992#if defined(__SYCL_DEVICE_ONLY__) || defined(EIGEN_HIP_DEVICE_COMPILE)
993// Do not try asserts on device code
994#ifndef EIGEN_NO_DEBUG
995#define EIGEN_NO_DEBUG
996#endif
997
998#ifdef EIGEN_INTERNAL_DEBUGGING
999#undef EIGEN_INTERNAL_DEBUGGING
1000#endif
1001#endif
1002
1003// No exceptions on device.
1004#if defined(__SYCL_DEVICE_ONLY__) || defined(EIGEN_GPU_COMPILE_PHASE)
1005#ifdef EIGEN_EXCEPTIONS
1006#undef EIGEN_EXCEPTIONS
1007#endif
1008#endif
1009
1010#if defined(EIGEN_SYCL_DEVICE_ONLY) && !defined(EIGEN_GPUCC)
1011#ifndef EIGEN_DONT_VECTORIZE
1012#define EIGEN_DONT_VECTORIZE
1013#endif
1014#define EIGEN_DEVICE_FUNC __attribute__((flatten)) __attribute__((always_inline))
1015// All functions callable from CUDA/HIP code must be qualified with __device__
1016#elif defined(EIGEN_GPUCC)
1017#define EIGEN_DEVICE_FUNC __host__ __device__
1018#else
1019#define EIGEN_DEVICE_FUNC
1020#endif
1021
1022// this macro allows to get rid of linking errors about multiply defined functions.
1023// - static is not very good because it prevents definitions from different object files to be merged.
1024// So static causes the resulting linked executable to be bloated with multiple copies of the same function.
1025// - inline is not perfect either as it unwantedly hints the compiler toward inlining the function.
1026#define EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
1027#define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC inline
1028
1029#ifdef NDEBUG
1030#ifndef EIGEN_NO_DEBUG
1031#define EIGEN_NO_DEBUG
1032#endif
1033#endif
1034
1035// eigen_assert can be overridden
1036#ifndef eigen_assert
1037#define eigen_assert(x) eigen_plain_assert(x)
1038#endif
1039
1040#ifdef EIGEN_INTERNAL_DEBUGGING
1041#define eigen_internal_assert(x) eigen_assert(x)
1042#else
1043#define eigen_internal_assert(x) ((void)0)
1044#endif
1045
1046#if defined(EIGEN_NO_DEBUG) || (defined(EIGEN_GPU_COMPILE_PHASE) && defined(EIGEN_NO_DEBUG_GPU))
1047#define EIGEN_ONLY_USED_FOR_DEBUG(x) EIGEN_UNUSED_VARIABLE(x)
1048#else
1049#define EIGEN_ONLY_USED_FOR_DEBUG(x)
1050#endif
1051
1052#ifndef EIGEN_NO_DEPRECATED_WARNING
1053#if EIGEN_COMP_GNUC
1054#define EIGEN_DEPRECATED __attribute__((deprecated))
1055#elif EIGEN_COMP_MSVC
1056#define EIGEN_DEPRECATED __declspec(deprecated)
1057#else
1058#define EIGEN_DEPRECATED
1059#endif
1060#else
1061#define EIGEN_DEPRECATED
1062#endif
1063
1064#ifndef EIGEN_NO_DEPRECATED_WARNING
1065#if EIGEN_COMP_GNUC
1066#define EIGEN_DEPRECATED_WITH_REASON(message) __attribute__((deprecated(message)))
1067#elif EIGEN_COMP_MSVC
1068#define EIGEN_DEPRECATED_WITH_REASON(message) __declspec(deprecated(message))
1069#else
1070#define EIGEN_DEPRECATED_WITH_REASON(message)
1071#endif
1072#else
1073#define EIGEN_DEPRECATED_WITH_REASON(message)
1074#endif
1075
1076// Deprecated no-op macro. Was a workaround for GCC 4.3 empty struct issues, removed in Eigen 5.0.
1077// Defined here for backward compatibility with downstream code that still references it.
1078#define EIGEN_EMPTY_STRUCT_CTOR(X)
1079
1080#if EIGEN_COMP_GNUC
1081#define EIGEN_UNUSED __attribute__((unused))
1082#else
1083#define EIGEN_UNUSED
1084#endif
1085
1086#if EIGEN_COMP_GNUC
1087#define EIGEN_PRAGMA(tokens) _Pragma(#tokens)
1088#define EIGEN_DIAGNOSTICS(tokens) EIGEN_PRAGMA(GCC diagnostic tokens)
1089#define EIGEN_DIAGNOSTICS_OFF(msc, gcc) EIGEN_DIAGNOSTICS(gcc)
1090#elif EIGEN_COMP_MSVC
1091#define EIGEN_PRAGMA(tokens) __pragma(tokens)
1092#define EIGEN_DIAGNOSTICS(tokens) EIGEN_PRAGMA(warning(tokens))
1093#define EIGEN_DIAGNOSTICS_OFF(msc, gcc) EIGEN_DIAGNOSTICS(msc)
1094#else
1095#define EIGEN_PRAGMA(tokens)
1096#define EIGEN_DIAGNOSTICS(tokens)
1097#define EIGEN_DIAGNOSTICS_OFF(msc, gcc)
1098#endif
1099
1100#define EIGEN_DISABLE_DEPRECATED_WARNING EIGEN_DIAGNOSTICS_OFF(disable : 4996, ignored "-Wdeprecated-declarations")
1101
1102// Suppresses 'unused variable' warnings.
1103namespace Eigen {
1104namespace internal {
1105template <typename T>
1106EIGEN_DEVICE_FUNC constexpr void ignore_unused_variable(const T&) {}
1107} // namespace internal
1108} // namespace Eigen
1109#define EIGEN_UNUSED_VARIABLE(var) Eigen::internal::ignore_unused_variable(var)
1110
1111#if !defined(EIGEN_ASM_COMMENT)
1112#if EIGEN_COMP_GNUC && (EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_RISCV)
1113#define EIGEN_ASM_COMMENT(X) __asm__("#" X)
1114#else
1115#define EIGEN_ASM_COMMENT(X)
1116#endif
1117#endif
1118
1119// Acts as a barrier preventing operations involving `X` from crossing. This
1120// occurs, for example, in the fast rounding trick where a magic constant is
1121// added then subtracted, which is otherwise compiled away with -ffast-math.
1122//
1123// See bug 1674
1124#if defined(EIGEN_GPU_COMPILE_PHASE)
1125#define EIGEN_OPTIMIZATION_BARRIER(X)
1126#endif
1127
1128#if !defined(EIGEN_OPTIMIZATION_BARRIER)
1129// Implement the barrier on GNUC compilers or clang-cl.
1130#if EIGEN_COMP_GNUC || (defined(__clang__) && defined(_MSC_VER))
1131// According to https://gcc.gnu.org/onlinedocs/gcc/Constraints.html:
1132// X: Any operand whatsoever.
1133// r: A register operand is allowed provided that it is in a general
1134// register.
1135// g: Any register, memory or immediate integer operand is allowed, except
1136// for registers that are not general registers.
1137// w: (AArch32/AArch64) Floating point register, Advanced SIMD vector
1138// register or SVE vector register.
1139// x: (SSE) Any SSE register.
1140// (AArch64) Like w, but restricted to registers 0 to 15 inclusive.
1141// v: (PowerPC) An Altivec vector register.
1142// (x86) Any EVEX-encodable SSE register, including registers 16-31.
1143// wa:(PowerPC) A VSX register.
1144//
1145// "X" (uppercase) should work for all cases, though this seems to fail for
1146// some versions of GCC for arm/aarch64 with
1147// "error: inconsistent operand constraints in an 'asm'"
1148// Clang x86_64/arm/aarch64 seems to require "g" to support both scalars and
1149// vectors, otherwise
1150// "error: non-trivial scalar-to-vector conversion, possible invalid
1151// constraint for vector type"
1152//
1153// GCC for ppc64le generates an internal compiler error with x/X/g.
1154// GCC for AVX generates an internal compiler error with X.
1155//
1156// Tested on icc/gcc/clang for sse, avx, avx2, avx512dq
1157// gcc for arm, aarch64,
1158// gcc for ppc64le,
1159// both vectors and scalars.
1160//
1161// GCC (including MinGW) and Clang on x86, Arm and PPC pass class, union,
1162// complex and array operands through memory. Elsewhere, apply the barrier to
1163// the underlying plain type of std::complex<T>, Eigen::half or Eigen::bfloat16.
1164#if (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MINGW) && \
1165 (EIGEN_ARCH_PPC || EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_i386_OR_x86_64)
1166namespace Eigen {
1167namespace internal {
1168// Macros.h precedes Meta.h and <type_traits>. Operands are classified without cv-qualifiers: __builtin_classify_type
1169// does not evaluate its operand, but GCC rejects a volatile one in a constant expression.
1170template <typename T>
1171struct optimization_barrier_unqualified {
1172 using type = T;
1173};
1174template <typename T>
1175struct optimization_barrier_unqualified<const T> {
1176 using type = T;
1177};
1178template <typename T>
1179struct optimization_barrier_unqualified<volatile T> {
1180 using type = T;
1181};
1182template <typename T>
1183struct optimization_barrier_unqualified<const volatile T> {
1184 using type = T;
1185};
1186// Aggregates go to memory. GCC rejects register and general constraints for a struct of three doubles or a double[8]
1187// on every target, and for an int[4] or a struct of two doubles on 32-bit Arm; on PPC, complex<float> comes back
1188// corrupted at -O3 even with "m" added as an alternative. A memory operand hides the object's own bytes, not the
1189// storage it points to.
1190template <typename T>
1191struct optimization_barrier_in_memory {
1192 // 9 = complex, 12 = class, 13 = union. Arrays decay to pointers here and are matched below.
1193 static constexpr int kTypeClass = __builtin_classify_type(*static_cast<T*>(nullptr));
1194 static constexpr bool value = kTypeClass == 9 || kTypeClass == 12 || kTypeClass == 13;
1195};
1196template <typename T, decltype(sizeof(0)) N>
1197struct optimization_barrier_in_memory<T[N]> {
1198 static constexpr bool value = true;
1199};
1200} // namespace internal
1201} // namespace Eigen
1202#endif
1203#if EIGEN_ARCH_PPC && EIGEN_COMP_GNUC_STRICT
1204// These register alternatives are broken on Clang. Packet4f is loaded into a single register rather than a vector,
1205// zeroing out some entries, and integer types generate a compile error.
1206#if EIGEN_OS_MAC
1207// General, Altivec for Apple (VSX were added in ISA v2.06):
1208#define EIGEN_PPC_OPTIMIZATION_BARRIER_REGISTERS "+r,v"
1209#else
1210// General, Altivec, VSX otherwise:
1211#define EIGEN_PPC_OPTIMIZATION_BARRIER_REGISTERS "+r,v,wa"
1212#endif
1213namespace Eigen {
1214namespace internal {
1215// The two constraints need separate instantiations because GCC rejects an impossible constraint even on a branch not
1216// taken.
1217template <bool InMemory>
1218struct ppc_optimization_barrier_impl {
1219 template <typename T>
1220 static EIGEN_ALWAYS_INLINE void run(T& x) {
1221 __asm__("" : EIGEN_PPC_OPTIMIZATION_BARRIER_REGISTERS(x));
1222 }
1223};
1224template <>
1225struct ppc_optimization_barrier_impl<true> {
1226 template <typename T>
1227 static EIGEN_ALWAYS_INLINE void run(T& x) {
1228 __asm__("" : "+m"(x));
1229 }
1230};
1231template <typename T>
1232EIGEN_ALWAYS_INLINE void ppc_optimization_barrier(T& x) {
1233 using Operand = typename optimization_barrier_unqualified<T>::type;
1234 ppc_optimization_barrier_impl<optimization_barrier_in_memory<Operand>::value>::run(x);
1235}
1236} // namespace internal
1237} // namespace Eigen
1238#undef EIGEN_PPC_OPTIMIZATION_BARRIER_REGISTERS
1239#define EIGEN_OPTIMIZATION_BARRIER(X) Eigen::internal::ppc_optimization_barrier(X);
1240#elif EIGEN_ARCH_PPC && EIGEN_COMP_CLANG
1241// Clang's PPC backend does not accept one register constraint covering all scalar and vector operands. In particular,
1242// "wa" crashes the backend for scalar integers narrower than 64 bits.
1243#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+m"(X));
1244#elif (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MINGW) && \
1245 (EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_i386_OR_x86_64)
1246// Clang chooses memory for mixed general/vector constraints. Use a register-only constraint for float, double,
1247// and builtin vectors that fit in one enabled register, and memory for aggregates. Other operands retain the
1248// general/memory alternatives.
1249#if EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_FP)
1250#define EIGEN_BARRIER_GENERAL_CONSTRAINT "+g,w"
1251#define EIGEN_BARRIER_REGISTER_CONSTRAINT "+w"
1252#elif EIGEN_ARCH_ARM_OR_ARM64
1253// Arm without VFP or NEON: "w" will not compile, and no operand takes the register path.
1254#define EIGEN_BARRIER_GENERAL_CONSTRAINT "+g"
1255#define EIGEN_BARRIER_REGISTER_CONSTRAINT "+g"
1256#else
1257#define EIGEN_BARRIER_GENERAL_CONSTRAINT "+g,x"
1258#ifdef __AVX512F__
1259// Unlike "x", "v" also allows registers 16-31.
1260#define EIGEN_BARRIER_REGISTER_CONSTRAINT "+v"
1261#else
1262#define EIGEN_BARRIER_REGISTER_CONSTRAINT "+x"
1263#endif
1264#endif
1265#if EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_NEON)
1266#define EIGEN_BARRIER_VECTOR_BYTES 16
1267#elif EIGEN_ARCH_i386_OR_x86_64 && defined(__AVX512F__)
1268#define EIGEN_BARRIER_VECTOR_BYTES 64
1269#elif EIGEN_ARCH_i386_OR_x86_64 && defined(__AVX__)
1270#define EIGEN_BARRIER_VECTOR_BYTES 32
1271#elif EIGEN_ARCH_i386_OR_x86_64 && defined(__SSE2__)
1272#define EIGEN_BARRIER_VECTOR_BYTES 16
1273#else
1274#define EIGEN_BARRIER_VECTOR_BYTES 0
1275#endif
1276// The SME kernels use the barrier in streaming functions with ZA state. GCC refuses to inline a helper without these
1277// attributes there, and Clang 23 calls it out of line, switching streaming mode and lazily saving ZA around each call.
1278// Clang 20 and later have __arm_agnostic; for GCC, __arm_streaming_compatible suffices.
1279#if EIGEN_ARCH_ARM64 && defined(__ARM_FEATURE_SME)
1280#define EIGEN_BARRIER_SME_ATTRIBUTES __arm_streaming_compatible
1281#if EIGEN_COMP_CLANG
1282#if !__is_identifier(__arm_agnostic)
1283#undef EIGEN_BARRIER_SME_ATTRIBUTES
1284#define EIGEN_BARRIER_SME_ATTRIBUTES __arm_streaming_compatible __arm_agnostic("sme_za_state")
1285#endif
1286#endif
1287#else
1288#define EIGEN_BARRIER_SME_ATTRIBUTES
1289#endif
1290namespace Eigen {
1291namespace internal {
1292// GCC before 14 classifies builtin vectors as -1; newer GCC and Clang use 19. nullptr_t also has category -1 and is
1293// excluded below. Scalars have other categories. Sizeless SVE types have no sizeof and keep the general constraint.
1294template <typename T, typename = void>
1295struct optimization_barrier_in_register {
1296 static constexpr bool value = false;
1297};
1298template <typename T>
1299struct optimization_barrier_in_register<T, decltype(void(sizeof(T)))> {
1300 static constexpr int kTypeClass = __builtin_classify_type(*static_cast<T*>(nullptr));
1301 static constexpr bool value = (kTypeClass == -1 || kTypeClass == 19) && sizeof(T) <= EIGEN_BARRIER_VECTOR_BYTES;
1302};
1303template <>
1304struct optimization_barrier_in_register<decltype(nullptr)> {
1305 static constexpr bool value = false;
1306};
1307#if (EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_FP) && (__ARM_FP & 4)) || (EIGEN_ARCH_i386_OR_x86_64 && defined(__SSE2__))
1308template <>
1309struct optimization_barrier_in_register<float> {
1310 static constexpr bool value = true;
1311};
1312#endif
1313#if (EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_FP) && (__ARM_FP & 8)) || (EIGEN_ARCH_i386_OR_x86_64 && defined(__SSE2__))
1314template <>
1315struct optimization_barrier_in_register<double> {
1316 static constexpr bool value = true;
1317};
1318#endif
1319enum class optimization_barrier_operand_kind { General, Register, Memory };
1320template <optimization_barrier_operand_kind Kind>
1321struct optimization_barrier_impl {
1322 template <typename T>
1323 static EIGEN_ALWAYS_INLINE void run(T& x) EIGEN_BARRIER_SME_ATTRIBUTES {
1324 __asm__("" : EIGEN_BARRIER_GENERAL_CONSTRAINT(x));
1325 }
1326};
1327template <>
1328struct optimization_barrier_impl<optimization_barrier_operand_kind::Register> {
1329 template <typename T>
1330 static EIGEN_ALWAYS_INLINE void run(T& x) EIGEN_BARRIER_SME_ATTRIBUTES {
1331 __asm__("" : EIGEN_BARRIER_REGISTER_CONSTRAINT(x));
1332 }
1333};
1334template <>
1335struct optimization_barrier_impl<optimization_barrier_operand_kind::Memory> {
1336 template <typename T>
1337 static EIGEN_ALWAYS_INLINE void run(T& x) EIGEN_BARRIER_SME_ATTRIBUTES {
1338 __asm__("" : "+m"(x));
1339 }
1340};
1341template <typename T>
1342EIGEN_ALWAYS_INLINE void optimization_barrier(T& x) EIGEN_BARRIER_SME_ATTRIBUTES {
1343 using Operand = typename optimization_barrier_unqualified<T>::type;
1344 constexpr optimization_barrier_operand_kind kKind =
1345 optimization_barrier_in_memory<Operand>::value ? optimization_barrier_operand_kind::Memory
1346 : optimization_barrier_in_register<Operand>::value ? optimization_barrier_operand_kind::Register
1347 : optimization_barrier_operand_kind::General;
1348 optimization_barrier_impl<kKind>::run(x);
1349}
1350} // namespace internal
1351} // namespace Eigen
1352#undef EIGEN_BARRIER_GENERAL_CONSTRAINT
1353#undef EIGEN_BARRIER_REGISTER_CONSTRAINT
1354#undef EIGEN_BARRIER_VECTOR_BYTES
1355#undef EIGEN_BARRIER_SME_ATTRIBUTES
1356#define EIGEN_OPTIMIZATION_BARRIER(X) Eigen::internal::optimization_barrier(X);
1357#elif EIGEN_ARCH_ARM_OR_ARM64
1358#ifdef __ARM_FP
1359#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,w"(X));
1360#else
1361// Arm without VFP or NEON.
1362// "w" constraint will not compile.
1363#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g"(X));
1364#endif
1365#elif EIGEN_ARCH_i386_OR_x86_64 && EIGEN_COMP_NVHPC
1366// nvc++ rejects a long double asm operand under every constraint, so its bytes go through memory instead.
1367namespace Eigen {
1368namespace internal {
1369template <typename T>
1370EIGEN_ALWAYS_INLINE void nvhpc_optimization_barrier(T& x) {
1371 __asm__("" : "+g,x"(x));
1372}
1373EIGEN_ALWAYS_INLINE void nvhpc_optimization_barrier(long double& x) {
1374 __asm__("" : "+m"(*reinterpret_cast<unsigned char(*)[sizeof(long double)]>(&x)));
1375}
1376} // namespace internal
1377} // namespace Eigen
1378#define EIGEN_OPTIMIZATION_BARRIER(X) Eigen::internal::nvhpc_optimization_barrier(X);
1379#elif EIGEN_ARCH_i386_OR_x86_64
1380// General, SSE.
1381#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,x"(X));
1382#elif !defined(__SYCL_DEVICE_ONLY__)
1383// Other architectures: a memory operand needs no target-specific register class.
1384#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+m"(X));
1385#else
1386#define EIGEN_OPTIMIZATION_BARRIER(X)
1387#endif
1388#elif EIGEN_COMP_MSVC && defined(_M_FP_FAST)
1389// MSVC has no inline asm on x64 or Arm64, and /fp:fast folds across an empty barrier, e.g. x - q*c1 - q*c2 into
1390// x - q*(c1 + c2). Reloading x from an address OR-ed with a volatile zero hides its value from the optimizer at the
1391// cost of a store and a store-forwarded load.
1392namespace Eigen {
1393namespace internal {
1394template <typename Dummy = void>
1395struct msvc_optimization_barrier_zero {
1396 static volatile decltype(sizeof(0)) value;
1397};
1398template <typename Dummy>
1399volatile decltype(sizeof(0)) msvc_optimization_barrier_zero<Dummy>::value = 0;
1400template <typename T>
1401EIGEN_ALWAYS_INLINE void msvc_optimization_barrier(T& x) {
1402 x = *reinterpret_cast<T*>(reinterpret_cast<decltype(sizeof(0))>(&x) | msvc_optimization_barrier_zero<>::value);
1403}
1404template <typename T, decltype(sizeof(0)) N>
1405EIGEN_ALWAYS_INLINE void msvc_optimization_barrier(T (&x)[N]) {
1406 for (auto& element : x) msvc_optimization_barrier(element);
1407}
1408} // namespace internal
1409} // namespace Eigen
1410#define EIGEN_OPTIMIZATION_BARRIER(X) Eigen::internal::msvc_optimization_barrier(X);
1411#else
1412// Not implemented for other compilers.
1413#define EIGEN_OPTIMIZATION_BARRIER(X)
1414#endif
1415#endif
1416
1417namespace Eigen {
1418namespace internal {
1419// A volatile asm that the optimizer must execute exactly where it is written, so a value passed through it is defined
1420// only on its branch, and an operation that consumes it stays there instead of being evaluated speculatively.
1421// EIGEN_OPTIMIZATION_BARRIER is not volatile and can move across branches.
1422template <typename T>
1423EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void volatile_barrier(T& x) {
1424 EIGEN_UNUSED_VARIABLE(x);
1425#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(__SYCL_DEVICE_ONLY__) && \
1426 (EIGEN_COMP_GNUC || (defined(__clang__) && defined(_MSC_VER)))
1427 __asm__ __volatile__("" : "+m"(x));
1428#endif
1429}
1430#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(__SYCL_DEVICE_ONLY__) && \
1431 (EIGEN_COMP_GNUC || (defined(__clang__) && defined(_MSC_VER)))
1432#if EIGEN_ARCH_i386_OR_x86_64 && EIGEN_COMP_NVHPC
1433// nvc++ rejects a long double asm operand under every constraint, so its bytes go through memory instead.
1434EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void volatile_barrier(long double& x) {
1435 __asm__ __volatile__("" : "+m"(*reinterpret_cast<unsigned char(*)[sizeof(long double)]>(&x)));
1436}
1437#endif
1438#if EIGEN_ARCH_ARM_OR_ARM64 && defined(__ARM_FP)
1439#define EIGEN_FP_REGISTER_CONSTRAINT "+w"
1440#elif EIGEN_ARCH_i386_OR_x86_64 && defined(__SSE2__)
1441#define EIGEN_FP_REGISTER_CONSTRAINT "+x"
1442#endif
1443#ifdef EIGEN_FP_REGISTER_CONSTRAINT
1444EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void volatile_barrier(float& x) {
1445 __asm__ __volatile__("" : EIGEN_FP_REGISTER_CONSTRAINT(x));
1446}
1447EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE void volatile_barrier(double& x) {
1448 __asm__ __volatile__("" : EIGEN_FP_REGISTER_CONSTRAINT(x));
1449}
1450#undef EIGEN_FP_REGISTER_CONSTRAINT
1451#endif
1452#endif
1453} // namespace internal
1454} // namespace Eigen
1455
1456#if EIGEN_COMP_MSVC
1457// NOTE MSVC often gives C4127 warnings with compiletime if statements. See bug 1362.
1458// This workaround suppresses MSVC C4127 warnings for compile-time conditionals.
1459#define EIGEN_CONST_CONDITIONAL(cond) (void)0, cond
1460#else
1461#define EIGEN_CONST_CONDITIONAL(cond) cond
1462#endif
1463
1464#ifdef EIGEN_DONT_USE_RESTRICT_KEYWORD
1465#define EIGEN_RESTRICT
1466#endif
1467#ifndef EIGEN_RESTRICT
1468#define EIGEN_RESTRICT __restrict
1469#endif
1470
1471#ifndef EIGEN_DEFAULT_IO_FORMAT
1472#ifdef EIGEN_MAKING_DOCS
1473// format used in Eigen's documentation
1474// needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
1475#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(3, 0, " ", "\n", "", "")
1476#else
1477#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat()
1478#endif
1479#endif
1480
1481// just an empty macro !
1482#define EIGEN_EMPTY
1483
1484// When compiling CUDA/HIP device code with NVCC or HIPCC
1485// pull in math functions from the global namespace.
1486// In host mode, and when device code is compiled with clang,
1487// use the std versions.
1488#if (defined(EIGEN_CUDA_ARCH) && defined(__NVCC__)) || defined(EIGEN_HIP_DEVICE_COMPILE)
1489#define EIGEN_USING_STD(FUNC) using ::FUNC;
1490#else
1491#define EIGEN_USING_STD(FUNC) using std::FUNC;
1492#endif
1493
1494#define EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1495 using Base::operator=; \
1496 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Derived& other) { \
1497 Base::operator=(other); \
1498 return *this; \
1499 }
1500
1506#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) EIGEN_DEVICE_FUNC CLASS(const CLASS&) = default;
1507
1513#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
1514 EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
1515 EIGEN_DEFAULT_COPY_CONSTRUCTOR(Derived)
1516
1522#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \
1523 EIGEN_DEVICE_FUNC Derived() = default; \
1524 EIGEN_DEVICE_FUNC ~Derived() = default;
1525
1533
1534#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
1535 using Scalar = typename Eigen::internal::traits<Derived>::Scalar; \
1537 using RealScalar = \
1538 typename Eigen::NumTraits<Scalar>::Real; \
1541 using CoeffReturnType = \
1542 typename Base::CoeffReturnType; \
1546 using Nested = typename Eigen::internal::ref_selector<Derived>::type; \
1547 using StorageKind = typename Eigen::internal::traits<Derived>::StorageKind; \
1548 using StorageIndex = typename Eigen::internal::traits<Derived>::StorageIndex; \
1549 enum CompileTimeTraits { \
1550 RowsAtCompileTime = Eigen::internal::traits<Derived>::RowsAtCompileTime, \
1551 ColsAtCompileTime = Eigen::internal::traits<Derived>::ColsAtCompileTime, \
1552 Flags = Eigen::internal::traits<Derived>::Flags, \
1553 SizeAtCompileTime = Base::SizeAtCompileTime, \
1554 MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
1555 IsVectorAtCompileTime = Base::IsVectorAtCompileTime \
1556 }; \
1557 using Base::derived; \
1558 using Base::const_cast_derived;
1559
1560// FIXME Maybe the EIGEN_DENSE_PUBLIC_INTERFACE could be removed as importing PacketScalar is rarely needed
1561#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
1562 EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \
1563 using PacketScalar = typename Base::PacketScalar;
1564
1565#if EIGEN_HAS_BUILTIN(__builtin_expect) || EIGEN_COMP_GNUC
1566#define EIGEN_PREDICT_FALSE(x) (__builtin_expect(x, false))
1567#define EIGEN_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
1568#else
1569#define EIGEN_PREDICT_FALSE(x) (x)
1570#define EIGEN_PREDICT_TRUE(x) (x)
1571#endif
1572
1573#define EIGEN_MAKE_CWISE_UNARY_OP(METHOD, FUNCTOR, RETURN_TYPE) \
1574 using RETURN_TYPE = CwiseUnaryOp<FUNCTOR<Scalar>, const Derived>; \
1575 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const RETURN_TYPE METHOD() const { return RETURN_TYPE(derived()); }
1576
1577// the expression type of a standard coefficient wise binary operation
1578#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS, RHS, FUNCTOR) \
1579 CwiseBinaryOp<FUNCTOR<typename internal::traits<LHS>::Scalar, typename internal::traits<RHS>::Scalar>, const LHS, \
1580 const RHS>
1581
1582#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD, FUNCTOR) \
1583 template <typename OtherDerived> \
1584 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE( \
1585 Derived, OtherDerived, FUNCTOR)(METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { \
1586 return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived, OtherDerived, FUNCTOR)(derived(), other.derived()); \
1587 }
1588
1589#define EIGEN_SCALAR_BINARY_SUPPORTED(FUNCTOR, TYPEA, TYPEB) \
1590 (Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<TYPEA, TYPEB, FUNCTOR<TYPEA, TYPEB> > >::value)
1591
1592#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, FUNCTOR) \
1593 CwiseBinaryOp<FUNCTOR<typename internal::traits<EXPR>::Scalar, SCALAR>, const EXPR, \
1594 const typename internal::plain_constant_type<EXPR, SCALAR>::type>
1595
1596#define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR, EXPR, FUNCTOR) \
1597 CwiseBinaryOp<FUNCTOR<SCALAR, typename internal::traits<EXPR>::Scalar>, \
1598 const typename internal::plain_constant_type<EXPR, SCALAR>::type, const EXPR>
1599
1600#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD, FUNCTOR) \
1601 template <typename T> \
1602 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE( \
1603 Derived, \
1604 typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED( \
1605 FUNCTOR, Scalar, T)>::type, \
1606 FUNCTOR)(METHOD)(const T& scalar) const { \
1607 using PromotedT = \
1608 typename internal::promote_scalar_arg<Scalar, T, EIGEN_SCALAR_BINARY_SUPPORTED(FUNCTOR, Scalar, T)>::type; \
1609 return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, PromotedT, FUNCTOR)( \
1610 derived(), typename internal::plain_constant_type<Derived, PromotedT>::type( \
1611 derived().rows(), derived().cols(), internal::scalar_constant_op<PromotedT>(scalar))); \
1612 }
1613
1614#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD, FUNCTOR) \
1615 template <typename T> \
1616 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE friend const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE( \
1617 typename internal::promote_scalar_arg<Scalar EIGEN_COMMA T EIGEN_COMMA EIGEN_SCALAR_BINARY_SUPPORTED( \
1618 FUNCTOR, T, Scalar)>::type, \
1619 Derived, FUNCTOR)(METHOD)(const T& scalar, const StorageBaseType& matrix) { \
1620 using PromotedT = \
1621 typename internal::promote_scalar_arg<Scalar, T, EIGEN_SCALAR_BINARY_SUPPORTED(FUNCTOR, T, Scalar)>::type; \
1622 return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedT, Derived, FUNCTOR)( \
1623 typename internal::plain_constant_type<Derived, PromotedT>::type( \
1624 matrix.derived().rows(), matrix.derived().cols(), internal::scalar_constant_op<PromotedT>(scalar)), \
1625 matrix.derived()); \
1626 }
1627
1628#define EIGEN_MAKE_SCALAR_BINARY_OP(METHOD, FUNCTOR) \
1629 EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD, FUNCTOR) \
1630 EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD, FUNCTOR)
1631
1632#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(EIGEN_CUDA_ARCH) && !defined(EIGEN_EXCEPTIONS) && \
1633 !defined(EIGEN_USE_SYCL) && !defined(EIGEN_HIP_DEVICE_COMPILE)
1634#define EIGEN_EXCEPTIONS
1635#endif
1636
1637#ifdef EIGEN_EXCEPTIONS
1638#define EIGEN_THROW_X(X) throw X
1639#define EIGEN_THROW throw
1640#define EIGEN_TRY try
1641#define EIGEN_CATCH(X) catch (X)
1642#else
1643#if defined(EIGEN_CUDA_ARCH)
1644#define EIGEN_THROW_X(X) asm("trap;")
1645#define EIGEN_THROW asm("trap;")
1646#elif defined(EIGEN_HIP_DEVICE_COMPILE)
1647#define EIGEN_THROW_X(X) asm("s_trap 0")
1648#define EIGEN_THROW asm("s_trap 0")
1649#else
1650#define EIGEN_THROW_X(X) std::abort()
1651#define EIGEN_THROW std::abort()
1652#endif
1653#define EIGEN_TRY if (true)
1654#define EIGEN_CATCH(X) else
1655#endif
1656
1657// The all function is used to enable a variadic version of eigen_assert which can take a parameter pack as its input.
1658namespace Eigen {
1659namespace internal {
1660
1661EIGEN_DEVICE_FUNC constexpr bool all() { return true; }
1662
1663template <typename T, typename... Ts>
1664EIGEN_DEVICE_FUNC constexpr bool all(T t, Ts... ts) {
1665 return t && all(ts...);
1666}
1667
1668} // namespace internal
1669} // namespace Eigen
1670
1671// provide override and final specifiers if they are available:
1672#define EIGEN_OVERRIDE override
1673#define EIGEN_FINAL final
1674
1675// Wrapping #pragma unroll in a macro since it is required for SYCL
1676#if defined(__SYCL_DEVICE_ONLY__)
1677#if defined(_MSC_VER)
1678#define EIGEN_UNROLL_LOOP __pragma(unroll)
1679#else
1680#define EIGEN_UNROLL_LOOP _Pragma("unroll")
1681#endif
1682#else
1683#define EIGEN_UNROLL_LOOP
1684#endif
1685
1686// Notice: Use this macro with caution. The code in the if body should still
1687// compile with C++14.
1688#if defined(EIGEN_HAS_CXX17_IFCONSTEXPR)
1689#define EIGEN_IF_CONSTEXPR(...) if constexpr (__VA_ARGS__)
1690#else
1691#define EIGEN_IF_CONSTEXPR(...) if (__VA_ARGS__)
1692#endif
1693
1694#endif // EIGEN_MACROS_H