-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: add a canonical way to determine if dtype is integer, floating point or complex #17325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In my mind, we already have canonical spellings for these and they are:
Perhaps these spellings are too long, but "provide a convenient spelling" is different to "provide a canonical one".
While I would not recommend using this approach of listing the types, the safe spelling is
|
There's a number of issues with that:
I'm not too interested in arguing about the semantics of "canonical", so let me just say: there is no good way of doing this currently - should we add |
My leaning is towards making the documentation much clearer for Also, we already have IMO, introducing more functions will make things more confusing not less. |
Oh yes, that doesn't help, more weird and badly documented functions:(
|
It looks like this we probably should deprecate one or of the other of these. |
Deprecating And hide some of the other weird stuff like |
You can distinguish integers from floating point immediately using |
My mid-term goal would be that we do have an inexact DType, to be just a bit clearer than the That does not actually touch I do not think we have API equivalent to pythons
Admittingly, it currently works with |
On a semi related topic, is it possible to enumerate all the inexact types somehow? Is there a list somewhere? |
|
Are typecodes that the machine doesn't support eliminated from that list? |
There is no such thing as an unsupported type, only aliased names that exist on some but not all platforms. |
The very first example from the first post:
is apparently incorrect:
It should've been
Also, |
FWIW, when implementing special functions, I find Footnotes
|
* replace `*sctype*` NumPy usage per numpy/numpy#23999 and NEP52 in preparation for NumPy 2.0 * there seem to be straightforward replacements that still pass the testsuite in all cases * `git grep -E -i "sctype"` is clean on this branch (only present in comments for clarity where needed) * there may be better canonical ways to do some of these things in the future, though considerable confusion remains per numpy/numpy#17325 * `UMFPACK`-related changes were not tested locally (wasn't particularly friendly for PyPI-based setup/venv) [skip circle]
* replace `*sctype*` NumPy usage per numpy/numpy#23999 and NEP52 in preparation for NumPy 2.0 * there seem to be straightforward replacements that still pass the testsuite in all cases * `git grep -E -i "sctype"` is clean on this branch (only present in comments for clarity where needed) * there may be better canonical ways to do some of these things in the future, though considerable confusion remains per numpy/numpy#17325 * `UMFPACK`-related changes were not tested locally (wasn't particularly friendly for PyPI-based setup/venv) [skip circle]
For 2.0 we deprecated or removed Thanks all! |
further info: numpy/numpy#17325 nipy/nibabel#1250
further info: numpy/numpy#17325 nipy/nibabel#1250
further info: numpy/numpy#17325 nipy/nibabel#1250
further info: numpy/numpy#17325 nipy/nibabel#1250
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:
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:The trouble is that we have extended precision dtypes, and only one of
float96
orfloat128
will actually exist (the other one will raise anAttributeError
, 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 itfloating
orfloating_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
andis_complex
.Thoughts?
The text was updated successfully, but these errors were encountered: