@@ -20,7 +20,7 @@ extern "C" {
20
20
#include " casts.h"
21
21
#include " dtype.h"
22
22
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
24
24
25
25
static NPY_CASTING
26
26
quad_to_quad_resolve_descriptors (PyObject *NPY_UNUSED (self),
@@ -717,6 +717,26 @@ add_cast_to(PyArray_DTypeMeta *from)
717
717
add_spec (spec);
718
718
}
719
719
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
+
720
740
PyArrayMethod_Spec **
721
741
init_casts_internal (void )
722
742
{
@@ -739,6 +759,24 @@ init_casts_internal(void)
739
759
740
760
add_spec (quad2quad_spec);
741
761
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
+
742
780
add_cast_to<npy_bool>(&PyArray_BoolDType);
743
781
add_cast_to<npy_byte>(&PyArray_ByteDType);
744
782
add_cast_to<npy_short>(&PyArray_ShortDType);
0 commit comments