Skip to content

Commit 24846e0

Browse files
committed
fix + tests
1 parent 13d62b1 commit 24846e0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,15 @@ static PyMethodDef QuadPrecision_methods[] = {
605605
{NULL, NULL, 0, NULL} /* Sentinel */
606606
};
607607

608+
static PyObject *
609+
QuadPrecision_get_dtype(QuadPrecisionObject *self, void *NPY_UNUSED(closure))
610+
{
611+
QuadPrecDTypeObject *dtype = new_quaddtype_instance(self->backend);
612+
return (PyObject *)dtype;
613+
}
614+
608615
static PyGetSetDef QuadPrecision_getset[] = {
616+
{"dtype", (getter)QuadPrecision_get_dtype, NULL, "Data type descriptor for this scalar", NULL},
609617
{"real", (getter)QuadPrecision_get_real, NULL, "Real part of the scalar", NULL},
610618
{"imag", (getter)QuadPrecision_get_imag, NULL, "Imaginary part of the scalar (always 0 for real types)", NULL},
611619
{NULL} /* Sentinel */

quaddtype/tests/test_quaddtype.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4292,4 +4292,19 @@ def test_as_integer_ratio_compatibility_with_float(self, value):
42924292
# The ratios should be equal
42934293
quad_ratio = quad_num / quad_denom
42944294
float_ratio = float_num / float_denom
4295-
assert abs(quad_ratio - float_ratio) < 1e-15
4295+
assert abs(quad_ratio - float_ratio) < 1e-15
4296+
4297+
def test_quadprecision_scalar_dtype_expose():
4298+
quad_ld = QuadPrecision("1e100", backend="longdouble")
4299+
quad_sleef = QuadPrecision("1e100", backend="sleef")
4300+
assert quad_ld.dtype == QuadPrecDType(backend='longdouble')
4301+
assert np.dtype(quad_ld) == QuadPrecDType(backend='longdouble')
4302+
4303+
#todo: Uncomment them when 232 is merged
4304+
# assert quad_ld.dtype.backend == 1
4305+
# assert np.dtype(quad_ld).backend == 1
4306+
4307+
assert quad_sleef.dtype == QuadPrecDType(backend='sleef')
4308+
assert np.dtype(quad_sleef) == QuadPrecDType(backend='sleef')
4309+
# assert quad_sleef.dtype.backend == 0
4310+
# assert np.dtype(quad_sleef).backend == 0

0 commit comments

Comments
 (0)