From 74b027e5862dd2488f56ccba0d3268f7e11744f3 Mon Sep 17 00:00:00 2001 From: sun1638650145 <1638650145@qq.com> Date: Thu, 9 Dec 2021 17:54:07 +0800 Subject: [PATCH] Strictly defined integer. --- docs/advanced/pycpp/numpy.rst | 10 +++++----- include/pybind11/numpy.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/advanced/pycpp/numpy.rst b/docs/advanced/pycpp/numpy.rst index bccbc5f84..e49cafcfe 100644 --- a/docs/advanced/pycpp/numpy.rst +++ b/docs/advanced/pycpp/numpy.rst @@ -261,16 +261,16 @@ them mapping to respective C++ counterparts. .. note:: - This is a strict type, it will only allow input arguments of the specified - NumPy type and nothing else (e.g., ``py::numpy_scalar`` will not - accept built-in ``int`` or any other type for that matter). + This is a strict type, it will only allows to specify NumPy type as input + arguments, and does not allow other types of input parameters (e.g., + ``py::numpy_scalar`` will not accept Python's builtin ``int`` ). .. note:: Native C types are mapped to NumPy types in a platform specific way: for instance, ``char`` may be mapped to either ``np.int8`` or ``np.uint8`` - depending on the platform. If you want to ensure specific NumPy types, - it is recommended to use fixed-width aliases from ````. + and ``long`` may use 4 or 8 bytes depending on the platform. Unless you + clearly understand the difference and your needs, please use ````. Vectorizing functions ===================== diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 11237a95f..6240df2b2 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -322,16 +322,16 @@ DECL_NPY_SCALAR(signed char, NPY_BYTE); DECL_NPY_SCALAR(unsigned char, NPY_UBYTE); // signed integer types -DECL_NPY_SCALAR(short, NPY_SHORT); -DECL_NPY_SCALAR(int, NPY_INT); +DECL_NPY_SCALAR(std::int16_t, NPY_SHORT); +DECL_NPY_SCALAR(std::int32_t, NPY_INT); +DECL_NPY_SCALAR(std::int64_t, NPY_LONG); DECL_NPY_SCALAR(long, NPY_LONG); -DECL_NPY_SCALAR(long long, NPY_LONGLONG); // unsigned integer types -DECL_NPY_SCALAR(unsigned short, NPY_USHORT); -DECL_NPY_SCALAR(unsigned int, NPY_UINT); +DECL_NPY_SCALAR(std::uint16_t, NPY_USHORT); +DECL_NPY_SCALAR(std::uint32_t, NPY_UINT); +DECL_NPY_SCALAR(std::uint64_t, NPY_ULONG); DECL_NPY_SCALAR(unsigned long, NPY_ULONG); -DECL_NPY_SCALAR(unsigned long long, NPY_ULONGLONG); // floating point types DECL_NPY_SCALAR(float, NPY_FLOAT);