You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Additionally, there's no APIs in the specification for checking dtypes, i.e. something like np.issubdtype that is somewhat commonly used in code that would look something like:
cc @jakirkham as I believe this pattern is used quite a bit in Dask which would presumably want to be able to target arbitrary array objects under the hood
Data types (“dtypes”) are objects that can be used as dtype specifiers in functions and methods (e.g., zeros((2, 3), dtype=float32) ). A conforming implementation may add methods or attributes to data type objects; however, these methods and attributes are not included in this specification.
(I had thought that somewhere it was required that dtype objects be comparable by ==, but I don't see that there presently)
I will point out that if you only care about the dtypes in the spec, there are a finite number of them, so you can use
(I had thought that somewhere it was required that dtype objects be comparable by ==, but I don't see that there presently)
Sounds like something we should add.
By the way, did we specify that dtype objects are singletons so that they can also be checked via isinstance(x, float32)? It's probably a sane design that has been adopted in several libraries (eg: NumPy, CuPy), but still worth shouting out loud.
The docs weren't clear to me, but I didn't interpret those as singletons and instead thought that it was just guidance on what data types need to be supported by the standard.
The dtype names need to be part of the namespace. Otherwise passing dtype=float64 and so on won't be possible. If that isn't clear, we should fix it.
Sounds like something we should add. By the way, did we specify that dtype objects are singletons so that they can also be checked via isinstance(x, float32)? It's probably a sane design that has been adopted in several libraries (eg: NumPy, CuPy), but still worth shouting out loud.
isinstance(x, float32) implies that x is a scalar, which we do not have in the spec (isinstance(np.array([1.], dtype=np.float64), np.float64) gives False).
isinstance(x, float32) implies that x is a scalar, which we do not have in the spec (isinstance(np.array([1.], dtype=np.float64), np.float64) gives False).
@asmeurer I think you misread. If I wanna do isinstance(x, float32) on x, it must be a dtype object like float32, float64, etc. It doesn't make sense to check if an array is an instance of a dtype.
Data types ("dtypes") are objects that can be used as `dtype` specifiers in functions and methods (e.g., `zeros((2, 3), dtype=float32)`). A conforming implementation may add methods or attributes to data type objects; however, these methods and attributes are not included in this specification.
so for now I think it is a no-go to check dtype.type. We need either the equal check (==) or something equivalent added or the standard revised I think.
All the discussion is happening in gh-425 and this is basically a duplicate issue, so I'll close this again. And we'll try to finalize gh-425 very soon.
Activity
jakirkham commentedon Mar 25, 2021
With NumPy, one can do this. However I don't think the
dtypespec includestypeor the ability to make this kind of check AFAICTasmeurer commentedon Apr 1, 2021
https://data-apis.org/array-api/latest/API_specification/data_types.html says
(I had thought that somewhere it was required that dtype objects be comparable by
==, but I don't see that there presently)I will point out that if you only care about the dtypes in the spec, there are a finite number of them, so you can use
leofang commentedon Apr 1, 2021
Sounds like something we should add.
By the way, did we specify that dtype objects are singletons so that they can also be checked via
isinstance(x, float32)? It's probably a sane design that has been adopted in several libraries (eg: NumPy, CuPy), but still worth shouting out loud.kkraus14 commentedon Apr 2, 2021
The docs weren't clear to me, but I didn't interpret those as singletons and instead thought that it was just guidance on what data types need to be supported by the standard.
asmeurer commentedon Apr 2, 2021
The dtype names need to be part of the namespace. Otherwise passing
dtype=float64and so on won't be possible. If that isn't clear, we should fix it.isinstance(x, float32) implies that x is a scalar, which we do not have in the spec (
isinstance(np.array([1.], dtype=np.float64), np.float64)gives False).jakirkham commentedon Apr 2, 2021
FWIW
numbersobjects areABC's so we can just callregisteron each subclass to addfloat32andfloat64if subclassing is not an optionleofang commentedon Apr 2, 2021
@asmeurer I think you misread. If I wanna do
isinstance(x, float32)onx, it must be a dtype object likefloat32,float64, etc. It doesn't make sense to check if an array is an instance of a dtype.jakirkham commentedon Apr 2, 2021
Right this is also why in the OP it mentions that with NumPy, we need to
dtype.typetoday. There's no equivalent of this in the spec AFAICTleofang commentedon Apr 3, 2021
So IIUC the current standard does not specify what property or method a dtype object needs to implement:
array-api/spec/API_specification/data_types.md
Line 74 in 0941067
so for now I think it is a no-go to check
dtype.type. We need either the equal check (==) or something equivalent added or the standard revised I think.leofang commentedon Apr 3, 2021
(And also it doesn't seem that subclassing is an option, depending on how one interprets the standard.)
kgryte commentedon May 5, 2022
Reopening this issue as relevant to the proposal in #425.
rgommers commentedon Sep 20, 2022
All the discussion is happening in gh-425 and this is basically a duplicate issue, so I'll close this again. And we'll try to finalize gh-425 very soon.