Skip to content

Commit

Permalink
Add support for copysign to the specification
Browse files Browse the repository at this point in the history
PR-URL: 	#693
  • Loading branch information
kgryte authored Oct 18, 2023
1 parent 8c42f02 commit 03886d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/draft/API_specification/elementwise_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Objects in API
bitwise_xor
ceil
conj
copysign
cos
cosh
divide
Expand Down
42 changes: 42 additions & 0 deletions src/array_api_stubs/_draft/elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bitwise_xor",
"ceil",
"conj",
"copysign",
"cos",
"cosh",
"divide",
Expand Down Expand Up @@ -804,6 +805,47 @@ def conj(x: array, /) -> array:
"""


def copysign(x1: array, x2: array, /) -> array:
r"""
Composes a floating-point value with the magnitude of ``x1_i`` and the sign of ``x2_i`` for each element of the input array ``x1``.
Parameters
----------
x1: array
input array containing magnitudes. Should have a real-valued floating-point data type.
x2: array
input array whose sign bits are applied to the magnitudes of ``x1``. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued floating-point data type.
Returns
-------
out: array
an array containing the element-wise results. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
Notes
-----
**Special cases**
For real-valued floating-point operands, let ``|x|`` be the absolute value, and if ``x1_i`` is not ``NaN``,
- If ``x2_i`` is less than ``0``, the result is ``-|x1_i|``.
- If ``x2_i`` is ``-0``, the result is ``-|x1_i|``.
- If ``x2_i`` is ``+0``, the result is ``|x1_i|``.
- If ``x2_i`` is greater than ``0``, the result is ``|x1_i|``.
- If ``x2_i`` is ``NaN`` and the sign bit of ``x2_i`` is ``1``, the result is ``-|x1_i|``.
- If ``x2_i`` is ``NaN`` and the sign bit of ``x2_i`` is ``0``, the result is ``|x1_i|``.
If ``x1_i`` is ``NaN``,
- If ``x2_i`` is less than ``0``, the result is ``NaN`` with a sign bit of ``1``.
- If ``x2_i`` is ``-0``, the result is ``NaN`` with a sign bit of ``1``.
- If ``x2_i`` is ``+0``, the result is ``NaN`` with a sign bit of ``0``.
- If ``x2_i`` is greater than ``0``, the result is ``NaN`` with a sign bit of ``0``.
- If ``x2_i`` is ``NaN`` and the sign bit of ``x2_i`` is ``1``, the result is ``NaN`` with a sign bit of ``1``.
- If ``x2_i`` is ``NaN`` and the sign bit of ``x2_i`` is ``0``, the result is ``NaN`` with a sign bit of ``0``.
"""


def cos(x: array, /) -> array:
r"""
Calculates an implementation-dependent approximation to the cosine for each element ``x_i`` of the input array ``x``.
Expand Down

0 comments on commit 03886d6

Please sign in to comment.