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
Should asarray() allow arbitrary casting between dtypes if you call asarray(x, dtype=dtype)? It isn't really clear in the spec if, e.g., asarray(x, dtype=bool) should be required to work if x is an integer or float array, or asarray(x, dtype=float64) if x is integer, and so on. My feeling is that it definitely should work if dtype is a promotable type from x.dtype, but I don't know if casts that aren't required to promote should also be required to work.
I guess there's actually three levels of dtype casting:
Promotable casting (x.dtype can be promoted to dtype in the type promotion table
Same-kind casting (x.dtype is the same kind as dtype but may be a downcast, like int64 -> int8 or uint64 -> int64)
Cross-kind casting (x.dtype and dtype are different kinds (integer, floating-point, boolean, eventually complex)).
Presumably at the very least promotion should be allowed, otherwise the dtype parameter is useless, especially for the *_like functions. The other two involve losing information for some values (except for bool -> other).
@asmeurer I am not seeing how the *_like functions are affected by cross-kind casting, as discussed in this issue. Maybe I am missing something, but the *_like functions don't perform casting; the data of the input array is not touched.
Activity
rgommers commentedon Sep 14, 2021
I'd expect this to work, because it's explicit. Unless there's an obvious alternative, like
x.astype()(which we don't have).asmeurer commentedon Sep 17, 2021
This is also relevant for the
*_likecreation functions, which all accept adtypeparameter. https://data-apis.org/array-api/latest/API_specification/creation_functions.htmlasmeurer commentedon Sep 17, 2021
I guess there's actually three levels of dtype casting:
x.dtypecan be promoted todtypein the type promotion tablex.dtypeis the same kind asdtypebut may be a downcast, like int64 -> int8 or uint64 -> int64)x.dtypeanddtypeare different kinds (integer, floating-point, boolean, eventually complex)).Presumably at the very least promotion should be allowed, otherwise the dtype parameter is useless, especially for the
*_likefunctions. The other two involve losing information for some values (except for bool -> other).kgryte commentedon Sep 18, 2021
@asmeurer I am not seeing how the
*_likefunctions are affected by cross-kind casting, as discussed in this issue. Maybe I am missing something, but the*_likefunctions don't perform casting; the data of the input array is not touched.asmeurer commentedon Sep 20, 2021
Oh yeah you are right about the _like functions (those always confuse me tbh because they seem rather pointless, but that's neither here nor there).