Skip to content

Commit 2a86270

Browse files
authored
Merge pull request numpy#19564 from seberg/scaled_float_DType
TST: Add "Scaled float" custom DType for testng
2 parents 6df7113 + d7af853 commit 2a86270

File tree

6 files changed

+601
-1
lines changed

6 files changed

+601
-1
lines changed

numpy/core/arrayprint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ def _get_format_function(data, **options):
420420
dtype_ = data.dtype
421421
dtypeobj = dtype_.type
422422
formatdict = _get_formatdict(data, **options)
423-
if issubclass(dtypeobj, _nt.bool_):
423+
if dtypeobj is None:
424+
return formatdict["numpystr"]()
425+
elif issubclass(dtypeobj, _nt.bool_):
424426
return formatdict['bool']()
425427
elif issubclass(dtypeobj, _nt.integer):
426428
if issubclass(dtypeobj, _nt.timedelta64):
@@ -1408,6 +1410,9 @@ def dtype_short_repr(dtype):
14081410
>>> dt = np.int64([1, 2]).dtype
14091411
>>> assert eval(dtype_short_repr(dt)) == dt
14101412
"""
1413+
if type(dtype).__repr__ != np.dtype.__repr__:
1414+
# TODO: Custom repr for user DTypes, logic should likely move.
1415+
return repr(dtype)
14111416
if dtype.names is not None:
14121417
# structured dtypes give a list or tuple repr
14131418
return str(dtype)

numpy/core/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ def generate_umath_c(ext, build_dir):
933933
join('src', 'umath', 'scalarmath.c.src'),
934934
join('src', 'umath', 'ufunc_type_resolution.c'),
935935
join('src', 'umath', 'override.c'),
936+
# For testing. Eventually, should use public API and be separate:
937+
join('src', 'umath', '_scaled_float_dtype.c'),
936938
]
937939

938940
umath_deps = [

numpy/core/src/common/umathmodule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "__umath_generated.c"
22
#include "__ufunc_api.c"
33

4+
NPY_NO_EXPORT PyObject *
5+
get_sfloat_dtype(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(args));
6+
47
PyObject * add_newdoc_ufunc(PyObject *NPY_UNUSED(dummy), PyObject *args);
58
PyObject * ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUSED(kwds));
69
int initumath(PyObject *m);

numpy/core/src/multiarray/multiarraymodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,8 @@ static struct PyMethodDef array_module_methods[] = {
44304430
METH_VARARGS, NULL},
44314431
{"_add_newdoc_ufunc", (PyCFunction)add_newdoc_ufunc,
44324432
METH_VARARGS, NULL},
4433+
{"_get_sfloat_dtype",
4434+
get_sfloat_dtype, METH_NOARGS, NULL},
44334435
{"_set_madvise_hugepage", (PyCFunction)_set_madvise_hugepage,
44344436
METH_O, NULL},
44354437
{"_reload_guard", (PyCFunction)_reload_guard,

0 commit comments

Comments
 (0)