From 991c4b12002bef8b49be8debdb88f5d124a84734 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Thu, 27 Jul 2023 14:49:25 +0200 Subject: [PATCH] Add complex compat header --- numpy/core/include/meson.build | 1 + .../core/include/numpy/npy_2_complexcompat.h | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 numpy/core/include/numpy/npy_2_complexcompat.h diff --git a/numpy/core/include/meson.build b/numpy/core/include/meson.build index 3051e6d8d7dc..808451104b01 100644 --- a/numpy/core/include/meson.build +++ b/numpy/core/include/meson.build @@ -8,6 +8,7 @@ installed_headers = [ 'numpy/ndarrayobject.h', 'numpy/ndarraytypes.h', 'numpy/npy_1_7_deprecated_api.h', + 'numpy/npy_2_complexcompat.h', 'numpy/npy_3kcompat.h', 'numpy/npy_common.h', 'numpy/npy_cpu.h', diff --git a/numpy/core/include/numpy/npy_2_complexcompat.h b/numpy/core/include/numpy/npy_2_complexcompat.h new file mode 100644 index 000000000000..0765243e21e8 --- /dev/null +++ b/numpy/core/include/numpy/npy_2_complexcompat.h @@ -0,0 +1,27 @@ +/* This header is designed to be copy-pasted into downstream packages, since it provides + a compatibility layer between the old C struct complex types and the new native C99 + complex types. */ +#ifndef NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPLEXCOMPAT_H_ +#define NUMPY_CORE_INCLUDE_NUMPY_NPY_2_COMPLEXCOMPAT_H_ + +#include + +#if (defined(NPY_TARGET_VERSION) && NPY_TARGET_VERSION >= 0x00000012) || (NPY_FEATURE_VERSION >= 0x00000012) /* Numpy 2.0 */ +#include + +#define NPY_CSETREALF(c, r) npy_csetrealf(c, r) +#define NPY_CSETIMAGF(c, i) npy_csetimagf(c, i) +#define NPY_CSETREAL(c, r) npy_csetreal(c, r) +#define NPY_CSETIMAG(c, i) npy_csetimag(c, i) +#define NPY_CSETREALL(c, r) npy_csetreall(c, r) +#define NPY_CSETIMAGL(c, i) npy_csetimagl(c, i) +#else +#define NPY_CSETREALF(c, r) (c)->real = (r) +#define NPY_CSETIMAGF(c, i) (c)->imag = (i) +#define NPY_CSETREAL(c, r) (c)->real = (r) +#define NPY_CSETIMAG(c, i) (c)->imag = (i) +#define NPY_CSETREALL(c, r) (c)->real = (r) +#define NPY_CSETIMAGL(c, i) (c)->imag = (i) +#endif + +#endif