Skip to content

Commit 04c24d7

Browse files
committed
Add copysign
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).
1 parent 77e6177 commit 04c24d7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

array_api_strict/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
ceil,
140140
clip,
141141
conj,
142+
copysign,
142143
cos,
143144
cosh,
144145
divide,
@@ -202,6 +203,7 @@
202203
"ceil",
203204
"clip",
204205
"conj",
206+
"copysign",
205207
"cos",
206208
"cosh",
207209
"divide",

array_api_strict/_elementwise_functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ def conj(x: Array, /) -> Array:
319319
raise TypeError("Only complex floating-point dtypes are allowed in conj")
320320
return Array._new(np.conj(x))
321321

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

323333
def cos(x: Array, /) -> Array:
324334
"""

0 commit comments

Comments
 (0)