29
29
#include < utility>
30
30
#include < vector>
31
31
32
- #if defined(PYBIND11_NUMPY_1_ONLY) && !defined(PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED)
33
- # error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included.
34
- #endif
35
-
36
32
/* This will be true on all flat address space platforms and allows us to reduce the
37
33
whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size
38
34
and dimension types (e.g. shape, strides, indexing), instead of inflicting this
@@ -80,7 +76,6 @@ struct PyArrayDescr1_Proxy {
80
76
PyObject *names;
81
77
};
82
78
83
- #ifndef PYBIND11_NUMPY_1_ONLY
84
79
struct PyArrayDescr_Proxy {
85
80
PyObject_HEAD
86
81
PyObject *typeobj;
@@ -91,10 +86,6 @@ struct PyArrayDescr_Proxy {
91
86
int type_num;
92
87
/* Additional fields are NumPy version specific. */
93
88
};
94
- #else
95
- /* NumPy 1.x only, we can expose all fields */
96
- using PyArrayDescr_Proxy = PyArrayDescr1_Proxy;
97
- #endif
98
89
99
90
/* NumPy 2 proxy, including legacy fields */
100
91
struct PyArrayDescr2_Proxy {
@@ -179,14 +170,6 @@ PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name
179
170
object numpy_version = numpy_lib.attr (" NumpyVersion" )(version_string);
180
171
int major_version = numpy_version.attr (" major" ).cast <int >();
181
172
182
- #ifdef PYBIND11_NUMPY_1_ONLY
183
- if (major_version >= 2 ) {
184
- throw std::runtime_error (
185
- " This extension was built with PYBIND11_NUMPY_1_ONLY defined, "
186
- " but NumPy 2 is used in this process. For NumPy2 compatibility, "
187
- " this extension needs to be rebuilt without the PYBIND11_NUMPY_1_ONLY define." );
188
- }
189
- #endif
190
173
/* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially
191
174
became a private module. */
192
175
std::string numpy_core_path = major_version >= 2 ? " numpy._core" : " numpy.core" ;
@@ -300,16 +283,6 @@ struct npy_api {
300
283
PyObject *(*PyArray_FromAny_)(PyObject *, PyObject *, int , int , int , PyObject *);
301
284
int (*PyArray_DescrConverter_)(PyObject *, PyObject **);
302
285
bool (*PyArray_EquivTypes_)(PyObject *, PyObject *);
303
- #ifdef PYBIND11_NUMPY_1_ONLY
304
- int (*PyArray_GetArrayParamsFromObject_)(PyObject *,
305
- PyObject *,
306
- unsigned char ,
307
- PyObject **,
308
- int *,
309
- Py_intptr_t *,
310
- PyObject **,
311
- PyObject *);
312
- #endif
313
286
PyObject *(*PyArray_Squeeze_)(PyObject *);
314
287
// Unused. Not removed because that affects ABI of the class.
315
288
int (*PyArray_SetBaseObject_)(PyObject *, PyObject *);
@@ -337,9 +310,6 @@ struct npy_api {
337
310
API_PyArray_View = 137 ,
338
311
API_PyArray_DescrConverter = 174 ,
339
312
API_PyArray_EquivTypes = 182 ,
340
- #ifdef PYBIND11_NUMPY_1_ONLY
341
- API_PyArray_GetArrayParamsFromObject = 278 ,
342
- #endif
343
313
API_PyArray_SetBaseObject = 282
344
314
};
345
315
@@ -374,9 +344,6 @@ struct npy_api {
374
344
DECL_NPY_API (PyArray_View);
375
345
DECL_NPY_API (PyArray_DescrConverter);
376
346
DECL_NPY_API (PyArray_EquivTypes);
377
- #ifdef PYBIND11_NUMPY_1_ONLY
378
- DECL_NPY_API (PyArray_GetArrayParamsFromObject);
379
- #endif
380
347
DECL_NPY_API (PyArray_SetBaseObject);
381
348
382
349
#undef DECL_NPY_API
@@ -760,21 +727,14 @@ class dtype : public object {
760
727
}
761
728
762
729
// / Size of the data type in bytes.
763
- #ifdef PYBIND11_NUMPY_1_ONLY
764
- ssize_t itemsize () const { return detail::array_descriptor_proxy (m_ptr)->elsize ; }
765
- #else
766
730
ssize_t itemsize () const {
767
731
if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
768
732
return detail::array_descriptor1_proxy (m_ptr)->elsize ;
769
733
}
770
734
return detail::array_descriptor2_proxy (m_ptr)->elsize ;
771
735
}
772
- #endif
773
736
774
737
// / Returns true for structured data types.
775
- #ifdef PYBIND11_NUMPY_1_ONLY
776
- bool has_fields () const { return detail::array_descriptor_proxy (m_ptr)->names != nullptr ; }
777
- #else
778
738
bool has_fields () const {
779
739
if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
780
740
return detail::array_descriptor1_proxy (m_ptr)->names != nullptr ;
@@ -785,7 +745,6 @@ class dtype : public object {
785
745
}
786
746
return proxy->names != nullptr ;
787
747
}
788
- #endif
789
748
790
749
// / Single-character code for dtype's kind.
791
750
// / For example, floating point types are 'f' and integral types are 'i'.
@@ -824,29 +783,21 @@ class dtype : public object {
824
783
// / Single character for byteorder
825
784
char byteorder () const { return detail::array_descriptor_proxy (m_ptr)->byteorder ; }
826
785
827
- // / Alignment of the data type
828
- #ifdef PYBIND11_NUMPY_1_ONLY
829
- int alignment () const { return detail::array_descriptor_proxy (m_ptr)->alignment ; }
830
- #else
786
+ // / Alignment of the data type
831
787
ssize_t alignment () const {
832
788
if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
833
789
return detail::array_descriptor1_proxy (m_ptr)->alignment ;
834
790
}
835
791
return detail::array_descriptor2_proxy (m_ptr)->alignment ;
836
792
}
837
- #endif
838
793
839
- // / Flags for the array descriptor
840
- #ifdef PYBIND11_NUMPY_1_ONLY
841
- char flags () const { return detail::array_descriptor_proxy (m_ptr)->flags ; }
842
- #else
794
+ // / Flags for the array descriptor
843
795
std::uint64_t flags () const {
844
796
if (detail::npy_api::get ().PyArray_RUNTIME_VERSION_ < 0x12 ) {
845
797
return (unsigned char ) detail::array_descriptor1_proxy (m_ptr)->flags ;
846
798
}
847
799
return detail::array_descriptor2_proxy (m_ptr)->flags ;
848
800
}
849
- #endif
850
801
851
802
private:
852
803
static object &_dtype_from_pep3118 () {
0 commit comments