From 5cf262c7620b64e0b8f454b2f9a8d4d2bf33b3a0 Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 15:27:09 -0500 Subject: [PATCH 1/8] numpy in a new world --- include/pybind11/numpy.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 8f072af26..4fb8ad3a7 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -25,6 +25,15 @@ #include #include #include +#include + + +#if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant +typedef SSIZE_T ssize_t; +#endif + /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size @@ -622,6 +631,15 @@ public: /// Flags for the array descriptor char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; } + /// NumPy array type char + char type() const { return detail::array_descriptor_proxy(m_ptr)->type; } + + /// NumPy array type num + int type_num() const { return detail::array_descriptor_proxy(m_ptr)->type_num; } + + /// NumPy array element size + int elsize() const { return detail::array_descriptor_proxy(m_ptr)->elsize; } + private: static object _dtype_from_pep3118() { static PyObject *obj = module_::import("numpy.core._internal") @@ -824,6 +842,9 @@ public: /// Return the NumPy array flags int flags() const { return detail::array_proxy(m_ptr)->flags; } + /// Mutable NumPy array flags + int& flags() { return detail::array_proxy(m_ptr)->flags; } + /// If set, the array is writeable (otherwise the buffer is read-only) bool writeable() const { return detail::check_flags(m_ptr, detail::npy_api::NPY_ARRAY_WRITEABLE_); From 3f0f27fc12018e761f133fb7510c94b79802004f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Jan 2023 21:03:55 +0000 Subject: [PATCH 2/8] style: pre-commit fixes --- include/pybind11/numpy.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 4fb8ad3a7..67d786770 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,16 +26,13 @@ #include #include #include -#include - #if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant +# pragma warning(push) +# pragma warning(disable : 4127) // warning C4127: Conditional expression is constant typedef SSIZE_T ssize_t; #endif - /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this @@ -843,7 +841,7 @@ public: int flags() const { return detail::array_proxy(m_ptr)->flags; } /// Mutable NumPy array flags - int& flags() { return detail::array_proxy(m_ptr)->flags; } + int &flags() { return detail::array_proxy(m_ptr)->flags; } /// If set, the array is writeable (otherwise the buffer is read-only) bool writeable() const { From 142ae7e1242af521cd578202bfba29c255aa2abf Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 17:04:29 -0500 Subject: [PATCH 3/8] Update numpy.h rm old code from npe --- include/pybind11/numpy.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 67d786770..1b1d7e099 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -27,12 +27,6 @@ #include #include -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4127) // warning C4127: Conditional expression is constant -typedef SSIZE_T ssize_t; -#endif - /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this From 6b0a4e8510e2df118f866f35e933c7ec6f3fb2a8 Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 17:04:51 -0500 Subject: [PATCH 4/8] Update numpy.h --- include/pybind11/numpy.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 1b1d7e099..5b9855294 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include From 9ef681765d7c29d7e91641aa41378bdf7f5a224a Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 15:27:09 -0500 Subject: [PATCH 5/8] numpy in a new world --- include/pybind11/numpy.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 36077ec04..1d011b11a 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -25,6 +25,15 @@ #include #include #include +#include + + +#if defined(_MSC_VER) +# pragma warning(push) +# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant +typedef SSIZE_T ssize_t; +#endif + /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size @@ -624,6 +633,15 @@ public: /// Flags for the array descriptor char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; } + /// NumPy array type char + char type() const { return detail::array_descriptor_proxy(m_ptr)->type; } + + /// NumPy array type num + int type_num() const { return detail::array_descriptor_proxy(m_ptr)->type_num; } + + /// NumPy array element size + int elsize() const { return detail::array_descriptor_proxy(m_ptr)->elsize; } + private: static object _dtype_from_pep3118() { static PyObject *obj = module_::import("numpy.core._internal") @@ -826,6 +844,9 @@ public: /// Return the NumPy array flags int flags() const { return detail::array_proxy(m_ptr)->flags; } + /// Mutable NumPy array flags + int& flags() { return detail::array_proxy(m_ptr)->flags; } + /// If set, the array is writeable (otherwise the buffer is read-only) bool writeable() const { return detail::check_flags(m_ptr, detail::npy_api::NPY_ARRAY_WRITEABLE_); From 49668e5e57da39e4c91689cdf41f41be46b0258f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Jan 2023 21:03:55 +0000 Subject: [PATCH 6/8] style: pre-commit fixes --- include/pybind11/numpy.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 1d011b11a..2d52e3b14 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,16 +26,13 @@ #include #include #include -#include - #if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant +# pragma warning(push) +# pragma warning(disable : 4127) // warning C4127: Conditional expression is constant typedef SSIZE_T ssize_t; #endif - /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this @@ -845,7 +843,7 @@ public: int flags() const { return detail::array_proxy(m_ptr)->flags; } /// Mutable NumPy array flags - int& flags() { return detail::array_proxy(m_ptr)->flags; } + int &flags() { return detail::array_proxy(m_ptr)->flags; } /// If set, the array is writeable (otherwise the buffer is read-only) bool writeable() const { From 7a78222b69e8f7fee0f9d9006c745ba03340bc76 Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 17:04:29 -0500 Subject: [PATCH 7/8] Update numpy.h rm old code from npe --- include/pybind11/numpy.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 2d52e3b14..b3888d3ca 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -27,12 +27,6 @@ #include #include -#if defined(_MSC_VER) -# pragma warning(push) -# pragma warning(disable : 4127) // warning C4127: Conditional expression is constant -typedef SSIZE_T ssize_t; -#endif - /* This will be true on all flat address space platforms and allows us to reduce the whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size and dimension types (e.g. shape, strides, indexing), instead of inflicting this From f6fc661a5ed6c760d1e30f24316073e354cdc39d Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 17:04:51 -0500 Subject: [PATCH 8/8] Update numpy.h --- include/pybind11/numpy.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index b3888d3ca..5ec9aca47 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include