array-api
array-api copied to clipboard
result_type() for mixed arrays/Python scalars
The array API's type promotion rules support mixed scalar/array operations, e.g., 1 + xp.arange(3)
.
For Xarray, we would like to be able to figure out the resulting dtype from this sort of operation before actually doing it (https://github.com/pydata/xarray/pull/8946).
Ideally, we could use xp.result_type()
for this purpose, but as documented result_type only supports arrays and dtype objects. Could we potentially extend result_type
to also handle Python scalars? It is worth noting that this already works today in NumPy, e.g.,
>>> np.result_type(1, np.arange(3))
dtype('int64')