Skip to content

Commit 3d0ebed

Browse files
authored
Merge pull request #147 from SwayamInSync/main
2 parents 77d4406 + 03b4ecb commit 3d0ebed

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" {
2121
#include "casts.h"
2222
#include "dtype.h"
2323

24-
#define NUM_CASTS 33 // 16 to_casts + 16 from_casts + 1 quad_to_quad
24+
#define NUM_CASTS 34 // 16 to_casts + 16 from_casts + 1 quad_to_quad + 1 void_to_quad
2525

2626
static NPY_CASTING
2727
quad_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self),
@@ -151,6 +151,27 @@ quad_to_quad_strided_loop_aligned(PyArrayMethod_Context *context, char *const da
151151
return 0;
152152
}
153153

154+
155+
static NPY_CASTING
156+
void_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self), PyArray_DTypeMeta *dtypes[2],
157+
PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2],
158+
npy_intp *view_offset)
159+
{
160+
PyErr_SetString(PyExc_TypeError,
161+
"Void to QuadPrecision cast is not implemented");
162+
return (NPY_CASTING)-1;
163+
}
164+
165+
static int
166+
void_to_quad_strided_loop(PyArrayMethod_Context *context, char *const data[],
167+
npy_intp const dimensions[], npy_intp const strides[],
168+
void *NPY_UNUSED(auxdata))
169+
{
170+
PyErr_SetString(PyExc_RuntimeError, "void_to_quad_strided_loop should not be called");
171+
return -1;
172+
}
173+
174+
154175
// Tag dispatching to ensure npy_bool/npy_ubyte and npy_half/npy_ushort do not alias in templates
155176
// see e.g. https://stackoverflow.com/q/32522279
156177
struct spec_npy_bool {};
@@ -805,6 +826,24 @@ init_casts_internal(void)
805826

806827
add_spec(quad2quad_spec);
807828

829+
PyArray_DTypeMeta **void_dtypes = new PyArray_DTypeMeta *[2]{&PyArray_VoidDType, &QuadPrecDType};
830+
PyType_Slot *void_slots = new PyType_Slot[]{
831+
{NPY_METH_resolve_descriptors, (void *)&void_to_quad_resolve_descriptors},
832+
{NPY_METH_strided_loop, (void *)&void_to_quad_strided_loop},
833+
{NPY_METH_unaligned_strided_loop, (void *)&void_to_quad_strided_loop},
834+
{0, nullptr}};
835+
836+
PyArrayMethod_Spec *void_spec = new PyArrayMethod_Spec{
837+
.name = "cast_Void_to_QuadPrec_ERROR",
838+
.nin = 1,
839+
.nout = 1,
840+
.casting = NPY_UNSAFE_CASTING,
841+
.flags = NPY_METH_SUPPORTS_UNALIGNED,
842+
.dtypes = void_dtypes,
843+
.slots = void_slots,
844+
};
845+
add_spec(void_spec);
846+
808847
add_cast_to<spec_npy_bool>(&PyArray_BoolDType);
809848
add_cast_to<npy_byte>(&PyArray_ByteDType);
810849
add_cast_to<npy_ubyte>(&PyArray_UByteDType);

quaddtype/reinstall.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if [ -d "build/" ]; then
88
rm -rf subprojects/sleef
99
fi
1010

11-
11+
export CFLAGS="-g -O0"
12+
export CXXFLAGS="-g -O0"
1213
python -m pip uninstall -y numpy_quaddtype
1314
python -m pip install . -v

quaddtype/tests/test_quaddtype.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ def test_supported_astype(dtype):
6666
@pytest.mark.parametrize("dtype", ["S10", "U10", "T", "V10", "datetime64[ms]", "timedelta64[ms]"])
6767
def test_unsupported_astype(dtype):
6868
if dtype == "V10":
69-
pytest.xfail("casts to and from V10 segfault")
70-
71-
with pytest.raises(TypeError, match="cast"):
72-
np.array(1, dtype=dtype).astype(QuadPrecDType, casting="unsafe")
69+
with pytest.raises(TypeError, match="cast"):
70+
np.ones((3, 3), dtype="V10").astype(QuadPrecDType, casting="unsafe")
71+
else:
72+
with pytest.raises(TypeError, match="cast"):
73+
np.array(1, dtype=dtype).astype(QuadPrecDType, casting="unsafe")
7374

74-
with pytest.raises(TypeError, match="cast"):
75-
np.array(QuadPrecision(1)).astype(dtype, casting="unsafe")
75+
with pytest.raises(TypeError, match="cast"):
76+
np.array(QuadPrecision(1)).astype(dtype, casting="unsafe")
7677

7778

7879
def test_basic_equality():

0 commit comments

Comments
 (0)