Skip to content

Commit

Permalink
Add copysign
Browse files Browse the repository at this point in the history
copysign is not tested yet by the test suite, but the standard does not appear
to deviate from NumPy (except in the restriction to floating-point dtypes).
  • Loading branch information
asmeurer committed Apr 19, 2024
1 parent 77e6177 commit 04c24d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions array_api_strict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
ceil,
clip,
conj,
copysign,
cos,
cosh,
divide,
Expand Down Expand Up @@ -202,6 +203,7 @@
"ceil",
"clip",
"conj",
"copysign",
"cos",
"cosh",
"divide",
Expand Down
10 changes: 10 additions & 0 deletions array_api_strict/_elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ def conj(x: Array, /) -> Array:
raise TypeError("Only complex floating-point dtypes are allowed in conj")
return Array._new(np.conj(x))

@requires_api_version('2023.12')
def copysign(x1: Array, x2: Array, /) -> Array:
"""
Array API compatible wrapper for :py:func:`np.copysign <numpy.copysign>`.
See its docstring for more information.
"""
if x1.dtype not in _real_numeric_dtypes or x2.dtype not in _real_numeric_dtypes:
raise TypeError("Only real numeric dtypes are allowed in copysign")
return Array._new(np.copysign(x1._array, x2._array))

def cos(x: Array, /) -> Array:
"""
Expand Down

0 comments on commit 04c24d7

Please sign in to comment.