Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions quaddtype/numpy_quaddtype/src/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,15 @@ static PyMethodDef QuadPrecision_methods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

static PyObject *
QuadPrecision_get_dtype(QuadPrecisionObject *self, void *NPY_UNUSED(closure))
{
QuadPrecDTypeObject *dtype = new_quaddtype_instance(self->backend);
return (PyObject *)dtype;
}

static PyGetSetDef QuadPrecision_getset[] = {
{"dtype", (getter)QuadPrecision_get_dtype, NULL, "Data type descriptor for this scalar", NULL},
{"real", (getter)QuadPrecision_get_real, NULL, "Real part of the scalar", NULL},
{"imag", (getter)QuadPrecision_get_imag, NULL, "Imaginary part of the scalar (always 0 for real types)", NULL},
{NULL} /* Sentinel */
Expand Down
17 changes: 16 additions & 1 deletion quaddtype/tests/test_quaddtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4292,4 +4292,19 @@ def test_as_integer_ratio_compatibility_with_float(self, value):
# The ratios should be equal
quad_ratio = quad_num / quad_denom
float_ratio = float_num / float_denom
assert abs(quad_ratio - float_ratio) < 1e-15
assert abs(quad_ratio - float_ratio) < 1e-15

def test_quadprecision_scalar_dtype_expose():
quad_ld = QuadPrecision("1e100", backend="longdouble")
quad_sleef = QuadPrecision("1e100", backend="sleef")
assert quad_ld.dtype == QuadPrecDType(backend='longdouble')
assert np.dtype(quad_ld) == QuadPrecDType(backend='longdouble')

#todo: Uncomment them when 232 is merged
# assert quad_ld.dtype.backend == 1
# assert np.dtype(quad_ld).backend == 1

assert quad_sleef.dtype == QuadPrecDType(backend='sleef')
assert np.dtype(quad_sleef) == QuadPrecDType(backend='sleef')
# assert quad_sleef.dtype.backend == 0
# assert np.dtype(quad_sleef).backend == 0