Skip to content

Commit 9131f14

Browse files
committed
updating branch
1 parent 74b2815 commit 9131f14

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {};
@@ -783,26 +804,6 @@ add_cast_to(PyArray_DTypeMeta *from)
783804
add_spec(spec);
784805
}
785806

786-
static NPY_CASTING
787-
void_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self), PyArray_DTypeMeta *dtypes[2],
788-
PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2],
789-
npy_intp *view_offset)
790-
{
791-
PyErr_SetString(PyExc_TypeError,
792-
"Cannot cast void dtype to QuadPrecDType. "
793-
"Void arrays contain arbitrary binary data that cannot be meaningfully converted to quad-precision floats.");
794-
return (NPY_CASTING)-1;
795-
}
796-
797-
static int
798-
void_to_quad_strided_loop(PyArrayMethod_Context *context, char *const data[],
799-
npy_intp const dimensions[], npy_intp const strides[],
800-
void *NPY_UNUSED(auxdata))
801-
{
802-
PyErr_SetString(PyExc_RuntimeError, "void_to_quad_strided_loop should not be called");
803-
return -1;
804-
}
805-
806807
PyArrayMethod_Spec **
807808
init_casts_internal(void)
808809
{
@@ -843,7 +844,6 @@ init_casts_internal(void)
843844
};
844845
add_spec(void_spec);
845846

846-
add_cast_to<npy_bool>(&PyArray_BoolDType);
847847
add_cast_to<spec_npy_bool>(&PyArray_BoolDType);
848848
add_cast_to<npy_byte>(&PyArray_ByteDType);
849849
add_cast_to<npy_ubyte>(&PyArray_UByteDType);

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)