Description
There is currently no good way (AFAIK) to figure out if the dtype of an array is integer, floating point or complex. Right now one of these is the most common probably:
x.dtype.kind in np.typecodes["AllFloat"]
np.issubdtype(x.dtype, np.floating)
Both are pretty awful.
A naive way to write code in the absence of something like is_floating_point
/is_integer
/is_complex
would be:
x.dtype in (np.float16, np.float32, np.float64)
The trouble is that we have extended precision dtypes, and only one of float96
or float128
will actually exist (the other one will raise an AttributeError
, also annoying and a frequent source of bugs).
Adding a set of functions is_floating_point
/is_integer
/is_complex
(whether with or without an underscore in the name, or naming it floating
or floating_point
) seems like a good idea to me.
In other libraries: TensorFlow doesn't seem to have any API for this, PyTorch has is_floating_point
and is_complex
.
Thoughts?