@@ -176,38 +176,6 @@ quadprec_default_descr(PyArray_DTypeMeta *cls)
176
176
return (PyArray_Descr * )temp ;
177
177
}
178
178
179
- static PyObject *
180
- quad_finfo (PyArray_Descr * descr , NPY_DTYPE_INFO_TYPE info_type )
181
- {
182
-
183
- // Handle the different info types
184
- switch (info_type ) {
185
- case NPY_DTYPE_INFO_FLOAT :
186
- {
187
- PyObject * finfo_dict = PyDict_New ();
188
- if (!finfo_dict ) return NULL ;
189
-
190
- PyDict_SetItemString (finfo_dict , "precision" , PyLong_FromLong (34 ));
191
- PyDict_SetItemString (finfo_dict , "bits" , PyLong_FromLong (128 ));
192
- // more fields
193
- return finfo_dict ;
194
- }
195
- case NPY_DTYPE_INFO_INTEGER :
196
- // Not implemented yet, could add iinfo support later
197
- PyErr_SetString (PyExc_NotImplementedError ,
198
- "Integer info not implemented for this dtype" );
199
- return NULL ;
200
- case NPY_DTYPE_INFO_GENERIC :
201
- // Not implemented yet, could add generic info later
202
- PyErr_SetString (PyExc_NotImplementedError ,
203
- "Generic info not implemented for this dtype" );
204
- return NULL ;
205
- default :
206
- PyErr_SetString (PyExc_ValueError , "Unknown dtype info type" );
207
- return NULL ;
208
- }
209
- }
210
-
211
179
static PyType_Slot QuadPrecDType_Slots [] = {
212
180
{NPY_DT_ensure_canonical , & ensure_canonical },
213
181
{NPY_DT_common_instance , & common_instance },
@@ -217,7 +185,6 @@ static PyType_Slot QuadPrecDType_Slots[] = {
217
185
{NPY_DT_getitem , & quadprec_getitem },
218
186
{NPY_DT_default_descr , & quadprec_default_descr },
219
187
{NPY_DT_PyArray_ArrFuncs_dotfunc , NULL },
220
- {NPY_DT_get_dtype_info , & quad_finfo },
221
188
{0 , NULL }};
222
189
223
190
static PyObject *
@@ -257,13 +224,42 @@ QuadPrecDType_str(QuadPrecDTypeObject *self)
257
224
return PyUnicode_FromFormat ("QuadPrecDType(backend='%s')" , backend_str );
258
225
}
259
226
227
+ static PyObject *
228
+ QuadPrecDType_finfo (QuadPrecDTypeObject * self , PyObject * args )
229
+ {
230
+ PyObject * numpy_quaddtype_module = PyImport_ImportModule ("numpy_quaddtype" );
231
+ if (numpy_quaddtype_module == NULL ) {
232
+ return NULL ;
233
+ }
234
+
235
+ PyObject * finfo_class = PyObject_GetAttrString (numpy_quaddtype_module , "QuadPrecFinfo" );
236
+ Py_DECREF (numpy_quaddtype_module );
237
+
238
+ if (finfo_class == NULL ) {
239
+ PyErr_SetString (PyExc_AttributeError , "Could not find QuadPrecFinfo class in numpy_quaddtype module." );
240
+ return NULL ;
241
+ }
242
+
243
+ PyObject * finfo_instance = PyObject_CallNoArgs (finfo_class );
244
+ Py_DECREF (finfo_class );
245
+
246
+ return finfo_instance ;
247
+ }
248
+
249
+ static PyMethodDef QuadPrecDType_methods [] = {
250
+ {"finfo" , (PyCFunction )QuadPrecDType_finfo , METH_NOARGS ,
251
+ "Return floating-point information for this QuadPrecDType" },
252
+ {NULL , NULL , 0 , NULL }
253
+ };
254
+
260
255
PyArray_DTypeMeta QuadPrecDType = {
261
256
{{
262
257
PyVarObject_HEAD_INIT (NULL , 0 ).tp_name = "numpy_quaddtype.QuadPrecDType" ,
263
258
.tp_basicsize = sizeof (QuadPrecDTypeObject ),
264
259
.tp_new = QuadPrecDType_new ,
265
260
.tp_repr = (reprfunc )QuadPrecDType_repr ,
266
261
.tp_str = (reprfunc )QuadPrecDType_str ,
262
+ .tp_methods = QuadPrecDType_methods ,
267
263
}},
268
264
};
269
265
0 commit comments