File tree Expand file tree Collapse file tree 4 files changed +42
-58
lines changed
Expand file tree Collapse file tree 4 files changed +42
-58
lines changed Original file line number Diff line number Diff line change 2525#include "markers.h"
2626#include "decoder.h"
2727#include "python_funcs.h"
28- #include "numpy_compat.h"
2928
3029/******************************************************************************/
3130
Original file line number Diff line number Diff line change 2626#include "markers.h"
2727#include "encoder.h"
2828#include "python_funcs.h"
29- #include "numpy_compat.h"
3029
3130/******************************************************************************/
3231
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2020#define PY_ARRAY_UNIQUE_SYMBOL bjdata_numpy_array
2121#define NPY_NO_DEPRECATED_API 0
2222#include <numpy/arrayobject.h>
23+ #include <numpy/ndarraytypes.h>
2324
2425#if defined (__cplusplus )
2526extern "C" {
@@ -86,6 +87,47 @@ extern "C" {
8687
8788#endif
8889
90+ #if NPY_ABI_VERSION < 0x02000000
91+ /*
92+ * NumPy 1.x: Direct struct member access
93+ */
94+ #define DESCR_ELSIZE (d ) (((PyArray_Descr*)(d))->elsize)
95+ #define DESCR_TYPE_NUM (d ) (((PyArray_Descr*)(d))->type_num)
96+ #else
97+ /*
98+ * NumPy 2.x: Use Python attribute access to avoid API linkage issues
99+ * This is slightly slower but guaranteed to work.
100+ */
101+ static inline npy_intp _descr_elsize_compat (PyArray_Descr * d ) {
102+ npy_intp result = 0 ;
103+ PyObject * val = PyObject_GetAttrString ((PyObject * )d , "itemsize" );
104+
105+ if (val ) {
106+ result = PyLong_AsSsize_t (val );
107+ Py_DECREF (val );
108+ }
109+
110+ PyErr_Clear ();
111+ return result ;
112+ }
113+
114+ static inline int _descr_type_num_compat (PyArray_Descr * d ) {
115+ int result = 0 ;
116+ PyObject * val = PyObject_GetAttrString ((PyObject * )d , "num" );
117+
118+ if (val ) {
119+ result = (int )PyLong_AsLong (val );
120+ Py_DECREF (val );
121+ }
122+
123+ PyErr_Clear ();
124+ return result ;
125+ }
126+
127+ #define DESCR_ELSIZE (d ) _descr_elsize_compat((PyArray_Descr*)(d))
128+ #define DESCR_TYPE_NUM (d ) _descr_type_num_compat((PyArray_Descr*)(d))
129+ #endif
130+
89131#if defined (__cplusplus )
90132 }
91133#endif
You can’t perform that action at this time.
0 commit comments