Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion array_api_strict/_elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,7 @@ def sign(x: Array, /) -> Array:
raise TypeError("Only numeric dtypes are allowed in sign")
# Special treatment to work around non-compliant NumPy 1.x behaviour
if x.dtype in _complex_floating_dtypes:
return x/abs(x)
_x = x._array
_result = _x / np.abs(np.where(_x != 0, _x, np.asarray(1.0, dtype=_x.dtype)))
return Array._new(_result, device=x.device)
return Array._new(np.sign(x._array), device=x.device)
Loading