summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorNathan Goldbaum <nathan.goldbaum@gmail.com>2023-02-09 14:19:39 -0700
committerNathan Goldbaum <nathan.goldbaum@gmail.com>2023-02-16 11:09:19 -0700
commit39d88df7c961f4d3bbd978c944673d3a9e9e12f4 (patch)
tree882f0b4ddfaa905c5cbb9039c4f2725f4142e16b /numpy/core/src
parent891ab8ee00755a539bd118b1bbe4e0a237a2d844 (diff)
downloadnumpy-39d88df7c961f4d3bbd978c944673d3a9e9e12f4.tar.gz
ENH: add _is_numeric attribute for DType classes
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/multiarray/dtypemeta.c10
-rw-r--r--numpy/core/src/multiarray/dtypemeta.h6
-rw-r--r--numpy/core/src/umath/_scaled_float_dtype.c2
3 files changed, 14 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/dtypemeta.c b/numpy/core/src/multiarray/dtypemeta.c
index 437319b3b..f268ba2cb 100644
--- a/numpy/core/src/multiarray/dtypemeta.c
+++ b/numpy/core/src/multiarray/dtypemeta.c
@@ -899,6 +899,10 @@ dtypemeta_wrap_legacy_descriptor(PyArray_Descr *descr)
}
}
+ if (PyTypeNum_ISNUMBER(descr->type_num)) {
+ dtype_class->flags |= NPY_DT_NUMERIC;
+ }
+
if (_PyArray_MapPyTypeToDType(dtype_class, descr->typeobj,
PyTypeNum_ISUSERDEF(dtype_class->type_num)) < 0) {
Py_DECREF(dtype_class);
@@ -927,6 +931,11 @@ dtypemeta_get_parametric(PyArray_DTypeMeta *self) {
return PyBool_FromLong(NPY_DT_is_parametric(self));
}
+static PyObject *
+dtypemeta_get_is_numeric(PyArray_DTypeMeta *self) {
+ return PyBool_FromLong(NPY_DT_is_numeric(self));
+}
+
/*
* Simple exposed information, defined for each DType (class).
*/
@@ -934,6 +943,7 @@ static PyGetSetDef dtypemeta_getset[] = {
{"_abstract", (getter)dtypemeta_get_abstract, NULL, NULL, NULL},
{"_legacy", (getter)dtypemeta_get_legacy, NULL, NULL, NULL},
{"_parametric", (getter)dtypemeta_get_parametric, NULL, NULL, NULL},
+ {"_is_numeric", (getter)dtypemeta_get_is_numeric, NULL, NULL, NULL},
{NULL, NULL, NULL, NULL, NULL}
};
diff --git a/numpy/core/src/multiarray/dtypemeta.h b/numpy/core/src/multiarray/dtypemeta.h
index db16fe04b..8ca2e26d4 100644
--- a/numpy/core/src/multiarray/dtypemeta.h
+++ b/numpy/core/src/multiarray/dtypemeta.h
@@ -7,10 +7,9 @@ extern "C" {
#include "numpy/_dtype_api.h"
-/* DType flags, currently private, since we may just expose functions */
+/* DType flags, currently private, since we may just expose functions
+ Other publicly visible flags are in _dtype_api.h */
#define NPY_DT_LEGACY 1 << 0
-#define NPY_DT_ABSTRACT 1 << 1
-#define NPY_DT_PARAMETRIC 1 << 2
typedef struct {
@@ -53,6 +52,7 @@ typedef struct {
#define NPY_DT_is_legacy(dtype) (((dtype)->flags & NPY_DT_LEGACY) != 0)
#define NPY_DT_is_abstract(dtype) (((dtype)->flags & NPY_DT_ABSTRACT) != 0)
#define NPY_DT_is_parametric(dtype) (((dtype)->flags & NPY_DT_PARAMETRIC) != 0)
+#define NPY_DT_is_numeric(dtype) (((dtype)->flags & NPY_DT_NUMERIC) != 0)
#define NPY_DT_is_user_defined(dtype) (((dtype)->type_num == -1))
/*
diff --git a/numpy/core/src/umath/_scaled_float_dtype.c b/numpy/core/src/umath/_scaled_float_dtype.c
index 9bcac8114..c26ace9f1 100644
--- a/numpy/core/src/umath/_scaled_float_dtype.c
+++ b/numpy/core/src/umath/_scaled_float_dtype.c
@@ -248,7 +248,7 @@ static PyArray_DTypeMeta PyArray_SFloatDType = {{{
}},
.type_num = -1,
.scalar_type = NULL,
- .flags = NPY_DT_PARAMETRIC,
+ .flags = NPY_DT_PARAMETRIC | NPY_DT_NUMERIC,
.dt_slots = &sfloat_slots,
};