@@ -20,7 +20,7 @@ extern "C" {
2020#include " casts.h"
2121#include " dtype.h"
2222
23- #define NUM_CASTS 29 // 14 to_casts + 14 from_casts + 1 quad_to_quad
23+ #define NUM_CASTS 30 // 14 to_casts + 14 from_casts + 1 quad_to_quad + 1 void_to_quad
2424
2525static NPY_CASTING
2626quad_to_quad_resolve_descriptors (PyObject *NPY_UNUSED (self),
@@ -717,6 +717,26 @@ add_cast_to(PyArray_DTypeMeta *from)
717717 add_spec (spec);
718718}
719719
720+ static NPY_CASTING
721+ void_to_quad_resolve_descriptors (PyObject *NPY_UNUSED (self), PyArray_DTypeMeta *dtypes[2],
722+ PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2],
723+ npy_intp *view_offset)
724+ {
725+ PyErr_SetString (PyExc_TypeError,
726+ " Cannot cast void dtype to QuadPrecDType. "
727+ " Void arrays contain arbitrary binary data that cannot be meaningfully converted to quad-precision floats." );
728+ return (NPY_CASTING)-1 ;
729+ }
730+
731+ static int
732+ void_to_quad_strided_loop (PyArrayMethod_Context *context, char *const data[],
733+ npy_intp const dimensions[], npy_intp const strides[],
734+ void *NPY_UNUSED (auxdata))
735+ {
736+ PyErr_SetString (PyExc_RuntimeError, " void_to_quad_strided_loop should not be called" );
737+ return -1 ;
738+ }
739+
720740PyArrayMethod_Spec **
721741init_casts_internal (void )
722742{
@@ -739,6 +759,24 @@ init_casts_internal(void)
739759
740760 add_spec (quad2quad_spec);
741761
762+ PyArray_DTypeMeta **void_dtypes = new PyArray_DTypeMeta *[2 ]{&PyArray_VoidDType, &QuadPrecDType};
763+ PyType_Slot *void_slots = new PyType_Slot[]{
764+ {NPY_METH_resolve_descriptors, (void *)&void_to_quad_resolve_descriptors},
765+ {NPY_METH_strided_loop, (void *)&void_to_quad_strided_loop},
766+ {NPY_METH_unaligned_strided_loop, (void *)&void_to_quad_strided_loop},
767+ {0 , nullptr }};
768+
769+ PyArrayMethod_Spec *void_spec = new PyArrayMethod_Spec{
770+ .name = " cast_Void_to_QuadPrec_ERROR" ,
771+ .nin = 1 ,
772+ .nout = 1 ,
773+ .casting = NPY_UNSAFE_CASTING,
774+ .flags = NPY_METH_SUPPORTS_UNALIGNED,
775+ .dtypes = void_dtypes,
776+ .slots = void_slots,
777+ };
778+ add_spec (void_spec);
779+
742780 add_cast_to<npy_bool>(&PyArray_BoolDType);
743781 add_cast_to<npy_byte>(&PyArray_ByteDType);
744782 add_cast_to<npy_short>(&PyArray_ShortDType);
0 commit comments