Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around const qualification of UFunc inner loops #223

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/numpy_quaternion.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

#define NPY_NO_DEPRECATED_API NPY_API_VERSION

// Numpy 1.19 changed UFuncGenericFunction to use const `dimensions` and `steps` pointers.
// Supposedly, this should only generate warnings, but this is now the cause of errors
// in CI, so I'm fixing it for real. The API version at which this change was made is at
// https://github.com/numpy/numpy/blob/e75214c1bc34903e6fe0f643dae8ada02529c0d5/numpy/core/meson.build#L41C3-L41C13
#if C_API_VERSION >= 0x0000000d
#define NPY_INTP_CONST npy_intp const
#else
#define NPY_INTP_CONST npy_intp
#endif

#include <Python.h>
#include <numpy/arrayobject.h>
#include <numpy/npy_math.h>
Expand Down Expand Up @@ -1129,8 +1139,8 @@ static void register_cast_function(int sourceType, int destType, PyArray_VectorU
// numpy array of quaternions.
#define UNARY_GEN_UFUNC(ufunc_name, func_name, ret_type) \
static void \
quaternion_##ufunc_name##_ufunc(char** args, npy_intp* dimensions, \
npy_intp* steps, void* NPY_UNUSED(data)) { \
quaternion_##ufunc_name##_ufunc(char** args, NPY_INTP_CONST* dimensions, \
NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) { \
/* fprintf (stderr, "file %s, line %d, quaternion_%s_ufunc.\n", __FILE__, __LINE__, #ufunc_name); */ \
char *ip1 = args[0], *op1 = args[1]; \
npy_intp is1 = steps[0], os1 = steps[1]; \
Expand Down Expand Up @@ -1170,7 +1180,7 @@ UNARY_UFUNC(parity_conjugate, quaternion)
UNARY_UFUNC(parity_symmetric_part, quaternion)
UNARY_UFUNC(parity_antisymmetric_part, quaternion)
static void
quaternion_positive_ufunc(char** args, npy_intp* dimensions, npy_intp* steps, void* NPY_UNUSED(data)) {
quaternion_positive_ufunc(char** args, NPY_INTP_CONST* dimensions, NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) {
char *ip1 = args[0], *op1 = args[1];
npy_intp is1 = steps[0], os1 = steps[1];
npy_intp n = dimensions[0];
Expand All @@ -1186,8 +1196,8 @@ quaternion_positive_ufunc(char** args, npy_intp* dimensions, npy_intp* steps, vo
// numpy array of quaternions.
#define BINARY_GEN_UFUNC(ufunc_name, func_name, arg_type1, arg_type2, ret_type) \
static void \
quaternion_##ufunc_name##_ufunc(char** args, npy_intp* dimensions, \
npy_intp* steps, void* NPY_UNUSED(data)) { \
quaternion_##ufunc_name##_ufunc(char** args, NPY_INTP_CONST* dimensions, \
NPY_INTP_CONST* steps, void* NPY_UNUSED(data)) { \
/* fprintf (stderr, "file %s, line %d, quaternion_%s_ufunc.\n", __FILE__, __LINE__, #ufunc_name); */ \
char *ip1 = args[0], *ip2 = args[1], *op1 = args[2]; \
npy_intp is1 = steps[0], is2 = steps[1], os1 = steps[2]; \
Expand Down
Loading