From 5cf262c7620b64e0b8f454b2f9a8d4d2bf33b3a0 Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 11 Jan 2023 15:27:09 -0500 Subject: [PATCH] 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_);