Open
Description
binops correctly raise when the user tries to mix int, float, and bool dtypes, and in general in all use cases that the Type Promotion Rules declare as "undefined behaviour".
__setitem__
however quietly casts the rhs to the dtype of the input.
>>> import array_api_strict as xp
>>> a = xp.asarray([1,2])
>>> b = xp.asarray(3.5)
>>> xp.maximum(a, b)
TypeError: array_api_strict.int64 and array_api_strict.float64 cannot be type promoted together
>>> xp.maximum(a, 3.5)
TypeError: Python float scalars can only be promoted with floating-point arrays.
>>> a[0] = b # No error
>>> a[1] = 4.5 # No error
>>> a
Out[12]: Array([3, 4], dtype=array_api_strict.int64)
__iadd__
et al behave as expected:
>>> a += b
TypeError: Cannot perform __iadd__ with dtypes array_api_strict.uint8 and array_api_strict.int64
>>> a += 4.5
TypeError: Python float scalars can only be promoted with floating-point arrays.
Metadata
Metadata
Assignees
Labels
No labels