Skip to content

Commit

Permalink
Fix compiler warning and improve NumPy 1.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenBaert committed Nov 3, 2024
1 parent bf9c0ba commit 7cb5799
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/test_numpy_dtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ template <typename T>
py::array_t<T> dispatch_array_increment(py::array_t<T> arr) {
py::array_t<T> res(arr.shape(0));
for (py::ssize_t i = 0; i < arr.shape(0); ++i) {
res.mutable_at(i) = arr.at(i) + 1;
res.mutable_at(i) = T(arr.at(i) + 1);
}
return res;
}
Expand Down
28 changes: 14 additions & 14 deletions tests/test_numpy_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,20 @@ def test_dtype(simple_dtype):
assert a == b

arr = np.array([4, 84, 21, 36])
assert (m.test_dtype_switch(arr.astype(np.byte)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.ubyte)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.short)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.ushort)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.intc)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.uintc)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.intp)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.uintp)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.long)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.ulong)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.longlong)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.ulonglong)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.float32)) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype(np.float64)) == arr + 1).all()
# Note: "ulong" does not work in NumPy 1.x, so we use "L"
assert (m.test_dtype_switch(arr.astype("byte")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("ubyte")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("short")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("ushort")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("intc")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("uintc")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("long")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("L")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("longlong")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("ulonglong")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("single")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("double")) == arr + 1).all()
assert (m.test_dtype_switch(arr.astype("longdouble")) == arr + 1).all()


def test_recarray(simple_dtype, packed_dtype):
Expand Down

0 comments on commit 7cb5799

Please sign in to comment.