Skip to content

Commit

Permalink
ENH: allow python scalars in binary elementwise functions
Browse files Browse the repository at this point in the history
Allow func(array, scalar) and func(scalar, array), raise on
func(scalar, scalar) if API_VERSION>=2024.12

cross-ref data-apis/array-api#807

To make sure it is all uniform,

1. Generate all binary "ufuncs" in a uniform way, with a decorator
2. Make binary "ufuncs" follow the same logic of the binary operators
3. Reuse the test loop of Array.__binop__ for binary "ufuncs"
4. (minor) in tests, reuse canonical names for dtype categories
   ("integer or boolean" vs "integer_or_boolean")
  • Loading branch information
ev-br committed Nov 30, 2024
1 parent d086c61 commit f705419
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 512 deletions.
2 changes: 2 additions & 0 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def _check_device(self, other):
elif isinstance(other, Array):
if self.device != other.device:
raise ValueError(f"Arrays from two different devices ({self.device} and {other.device}) can not be combined.")
else:
raise TypeError(f"Cannot combine an Array with {type(other)}.")

# Helper function to match the type promotion rules in the spec
def _promote_scalar(self, scalar):
Expand Down
Loading

0 comments on commit f705419

Please sign in to comment.