Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions quaddtype/numpy_quaddtype/src/casts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ init_casts_internal(void)
.nin = 1,
.nout = 1,
.casting = NPY_UNSAFE_CASTING,
.flags = NPY_METH_SUPPORTS_UNALIGNED,
.flags = static_cast<NPY_ARRAYMETHOD_FLAGS>(NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI),
.dtypes = unicode_to_quad_dtypes,
.slots = unicode_to_quad_slots,
};
Expand All @@ -1340,7 +1340,7 @@ init_casts_internal(void)
.nin = 1,
.nout = 1,
.casting = NPY_UNSAFE_CASTING,
.flags = NPY_METH_SUPPORTS_UNALIGNED,
.flags = static_cast<NPY_ARRAYMETHOD_FLAGS>(NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI),
.dtypes = quad_to_unicode_dtypes,
.slots = quad_to_unicode_slots,
};
Expand All @@ -1359,7 +1359,7 @@ init_casts_internal(void)
.nin = 1,
.nout = 1,
.casting = NPY_UNSAFE_CASTING,
.flags = NPY_METH_SUPPORTS_UNALIGNED,
.flags = static_cast<NPY_ARRAYMETHOD_FLAGS>(NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI),
.dtypes = bytes_to_quad_dtypes,
.slots = bytes_to_quad_slots,
};
Expand All @@ -1378,7 +1378,7 @@ init_casts_internal(void)
.nin = 1,
.nout = 1,
.casting = NPY_UNSAFE_CASTING,
.flags = NPY_METH_SUPPORTS_UNALIGNED,
.flags = static_cast<NPY_ARRAYMETHOD_FLAGS>(NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI),
.dtypes = quad_to_bytes_dtypes,
.slots = quad_to_bytes_slots,
};
Expand Down
12 changes: 12 additions & 0 deletions quaddtype/tests/test_quaddtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,18 @@ def test_empty_bytes_raises_error(self):
with pytest.raises(ValueError):
bytes_array.astype(QuadPrecDType())

@pytest.mark.parametrize('dtype', ['S50', 'U50'])
@pytest.mark.parametrize('size', [500, 1000, 10000])
def test_large_array_casting(self, dtype, size):
"""Test long array casting won't lead segfault, GIL enabled"""
arr = np.arange(size).astype(np.float32).astype(dtype)
quad_arr = arr.astype(QuadPrecDType())
assert quad_arr.dtype == QuadPrecDType()
assert quad_arr.size == size

# check roundtrip
roundtrip = quad_arr.astype(dtype)
np.testing.assert_array_equal(arr, roundtrip)

class TestStringParsingEdgeCases:
"""Test edge cases in NumPyOS_ascii_strtoq string parsing"""
Expand Down