Skip to content

Commit fd937bb

Browse files
numpy: More faithfully reflect npy_common.h aliases
1 parent 82953f8 commit fd937bb

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

include/pybind11/numpy.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@ struct npy_api {
145145
NPY_UINT8_ = NPY_UBYTE_,
146146
NPY_INT16_ = NPY_SHORT_,
147147
NPY_UINT16_ = NPY_USHORT_,
148-
NPY_INT32_ = platform_lookup<std::int32_t, short, int, long>({{
149-
NPY_SHORT_, NPY_INT_, NPY_LONG_}}),
150-
NPY_UINT32_ = platform_lookup<std::uint32_t, unsigned short, unsigned int, unsigned long>({{
151-
NPY_USHORT_, NPY_UINT_, NPY_ULONG_}}),
152-
NPY_INT64_ = platform_lookup<std::int64_t, int, long, long long>({{
153-
NPY_INT_, NPY_LONG_, NPY_LONGLONG_}}),
154-
NPY_UINT64_ = platform_lookup<std::uint64_t, unsigned int, unsigned long, unsigned long long>({{
155-
NPY_UINT_, NPY_ULONG_, NPY_ULONGLONG_}}),
148+
// `npy_common.h` defines the integer aliases. In order, it checks:
149+
// NPY_BITSOF_LONG, NPY_BITSOF_LONGLONG, NPY_BITSOF_INT, NPY_BITSOF_SHORT, NPY_BITSOF_CHAR
150+
// and assigns the alias to the first matching size, so we should check in this order.
151+
NPY_INT32_ = platform_lookup<std::int32_t, long, int, short>({{
152+
NPY_LONG_, NPY_INT_, NPY_SHORT_}}),
153+
NPY_UINT32_ = platform_lookup<std::uint32_t, unsigned long, unsigned int, unsigned short>({{
154+
NPY_ULONG_, NPY_UINT_, NPY_USHORT_}}),
155+
NPY_INT64_ = platform_lookup<std::int64_t, long, long long, int>({{
156+
NPY_LONG_, NPY_LONGLONG_, NPY_INT_}}),
157+
NPY_UINT64_ = platform_lookup<std::uint64_t, unsigned long, unsigned long long, unsigned int>({{
158+
NPY_ULONG_, NPY_ULONGLONG_, NPY_UINT_}}),
156159
};
157160

158161
typedef struct {

0 commit comments

Comments
 (0)