Skip to content

Commit e7143dd

Browse files
committed
ensure numpy>2.3 used in 'nightly', add sanity check for setting NPY_TARGET_VERSION from command line
1 parent b35756a commit e7143dd

File tree

12 files changed

+102
-27
lines changed

12 files changed

+102
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
working-directory: quaddtype
7676
run: |
7777
if [ "${{ matrix.numpy-version }}" == "nightly" ]; then
78-
extra_args=-Csetup-args="-Dcpp_args=-DNPY_TARGET_VERSION=NPY_2_4_API_VERSION"
78+
extra_args="-Csetup-args=-Dcpp_args=-DNPY_TARGET_VERSION=NPY_2_4_API_VERSION --no-build-isolation"
7979
fi
8080
export LDFLAGS="-fopenmp"
8181
python -m pip install $extra_args . -v

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ extern "C" {
2323
#include "casts.h"
2424
#include "dtype.h"
2525

26+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
27+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
28+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
29+
#endif
30+
2631
#define NUM_CASTS 34 // 16 to_casts + 16 from_casts + 1 quad_to_quad + 1 void_to_quad
2732

2833
static NPY_CASTING

quaddtype/numpy_quaddtype/src/dragon4.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ This code was extracted from NumPy and the original author was Allan Haldane(@ah
33
Modifications are specific to support the SLEEF_QUAD
44
*/
55

6+
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
7+
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
8+
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
9+
#ifndef NPY_TARGET_VERSION
10+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
11+
#endif
12+
#define NO_IMPORT_ARRAY
13+
#define NO_IMPORT_UFUNC
14+
15+
616
#include <numpy/npy_common.h>
717
#include <math.h>
818
#include <stdio.h>
@@ -14,17 +24,16 @@ Modifications are specific to support the SLEEF_QUAD
1424
#include "quaddtype_config.h"
1525

1626

17-
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
18-
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
19-
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
20-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
21-
#define NO_IMPORT_ARRAY
22-
#define NO_IMPORT_UFUNC
23-
2427
#include "dragon4.h"
2528
#include "dtype.h"
2629
#include "scalar.h"
2730

31+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
32+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
33+
#warning "NPY_FEATURE_VERSION is NPY_TOSTRING(NPY_FEATURE_VERSION)"
34+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
35+
#endif
36+
2837

2938
#ifdef __cplusplus
3039
#define NPY_TLS thread_local
@@ -2044,4 +2053,4 @@ Dragon4_Scientific(PyObject *obj, DigitMode digit_mode, int precision, int min_d
20442053
}
20452054

20462055
return NULL;
2047-
}
2056+
}

quaddtype/numpy_quaddtype/src/dtype.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
66
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
77
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
8-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
8+
#ifndef NPY_TARGET_VERSION
9+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
10+
#endif
911
#define NO_IMPORT_ARRAY
1012
#define NO_IMPORT_UFUNC
1113
#include "numpy/arrayobject.h"
@@ -17,6 +19,11 @@
1719
#include "dtype.h"
1820
#include "dragon4.h"
1921

22+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
23+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
24+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
25+
#endif
26+
2027
static inline int
2128
quad_load(void *x, char *data_ptr, QuadBackendType backend)
2229
{
@@ -263,4 +270,4 @@ init_quadprec_dtype(void)
263270
free_casts();
264271

265272
return 0;
266-
}
273+
}

quaddtype/numpy_quaddtype/src/quaddtype_main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
77
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
88
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
9-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
10-
9+
#ifndef NPY_TARGET_VERSION
10+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
11+
#endif
1112
#include "numpy/arrayobject.h"
1213
#include "numpy/dtype_api.h"
1314
#include "numpy/ufuncobject.h"
@@ -19,6 +20,11 @@
1920
#include "quadblas_interface.h"
2021
#include "float.h"
2122

23+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
24+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
25+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
26+
#endif
27+
2228
static PyObject *
2329
py_is_longdouble_128(PyObject *self, PyObject *args)
2430
{
@@ -177,4 +183,4 @@ PyInit__quaddtype_main(void)
177183
error:
178184
Py_XDECREF(m);
179185
return NULL;
180-
}
186+
}

quaddtype/numpy_quaddtype/src/scalar_ops.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
22
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
3-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
3+
#ifndef NPY_TARGET_VERSION
4+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
5+
#endif
46
#define NO_IMPORT_ARRAY
57

68
extern "C" {
@@ -18,6 +20,11 @@ extern "C" {
1820
#include "scalar_ops.h"
1921
#include "quad_common.h"
2022

23+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
24+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
25+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
26+
#endif
27+
2128
template <unary_op_quad_def sleef_op, unary_op_longdouble_def longdouble_op>
2229
static PyObject *
2330
quad_unary_func(QuadPrecisionObject *self)
@@ -240,4 +247,4 @@ PyNumberMethods quad_as_scalar = {
240247
.nb_int = (unaryfunc)QuadPrecision_int,
241248
.nb_float = (unaryfunc)QuadPrecision_float,
242249
.nb_true_divide = (binaryfunc)quad_binary_func<quad_div, ld_div>,
243-
};
250+
};

quaddtype/numpy_quaddtype/src/umath/binary_ops.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
22
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
33
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
4-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
4+
#ifndef NPY_TARGET_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
6+
#endif
57
#define NO_IMPORT_ARRAY
68
#define NO_IMPORT_UFUNC
79

@@ -21,6 +23,11 @@
2123
#include "promoters.hpp"
2224
#include "binary_ops.h"
2325

26+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
27+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
28+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
29+
#endif
30+
2431
static NPY_CASTING
2532
quad_binary_op_resolve_descriptors(PyObject *self, PyArray_DTypeMeta *const dtypes[],
2633
PyArray_Descr *const given_descrs[],
@@ -241,4 +248,4 @@ init_quad_binary_ops(PyObject *numpy)
241248
return -1;
242249
}
243250
return 0;
244-
}
251+
}

quaddtype/numpy_quaddtype/src/umath/comparison_ops.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
22
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
33
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
4-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
4+
#ifndef NPY_TARGET_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
6+
#endif
57
#define NO_IMPORT_ARRAY
68
#define NO_IMPORT_UFUNC
79

@@ -23,6 +25,10 @@
2325
#include "binary_ops.h"
2426
#include "comparison_ops.h"
2527

28+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
29+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
30+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
31+
#endif
2632

2733
static NPY_CASTING
2834
quad_comparison_op_resolve_descriptors(PyObject *self, PyArray_DTypeMeta *const dtypes[],
@@ -241,4 +247,4 @@ init_quad_comps(PyObject *numpy)
241247
}
242248

243249
return 0;
244-
}
250+
}

quaddtype/numpy_quaddtype/src/umath/matmul.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
22
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
33
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
4-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
4+
#ifndef NPY_TARGET_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
6+
#endif
57
#define NO_IMPORT_ARRAY
68
#define NO_IMPORT_UFUNC
79

@@ -24,6 +26,11 @@ extern "C" {
2426
#include "promoters.hpp"
2527
#include "../quadblas_interface.h"
2628

29+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
30+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
31+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
32+
#endif
33+
2734
static NPY_CASTING
2835
quad_matmul_resolve_descriptors(PyObject *self, PyArray_DTypeMeta *const dtypes[],
2936
PyArray_Descr *const given_descrs[], PyArray_Descr *loop_descrs[],
@@ -452,4 +459,4 @@ init_matmul_ops(PyObject *numpy)
452459
Py_DECREF(ufunc);
453460

454461
return 0;
455-
}
462+
}

quaddtype/numpy_quaddtype/src/umath/umath.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
22
#define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
33
#define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
4-
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
4+
#ifndef NPY_TARGET_VERSION
5+
#define NPY_TARGET_VERSION NPY_2_0_API_VERSION
6+
#endif
57
#define NO_IMPORT_ARRAY
68
#define NO_IMPORT_UFUNC
79

@@ -25,6 +27,11 @@ extern "C" {
2527
#include "comparison_ops.h"
2628
#include "matmul.h"
2729

30+
#if NPY_FEATURE_VERSION < NPY_2_0_API_VERSION
31+
#warning "Is NPY_TARGET_VERSION set too high for this numpy installation?"
32+
#error "NPY_FEATURE_VERSION too low, must be > NPY_2_0_API_VERSION"
33+
#endif
34+
2835
// helper debugging function
2936
static const char *
3037
get_dtype_name(PyArray_DTypeMeta *dtype)
@@ -119,4 +126,4 @@ init_quad_umath(void)
119126
err:
120127
Py_DECREF(numpy);
121128
return -1;
122-
}
129+
}

0 commit comments

Comments
 (0)