Skip to content

Commit

Permalink
Add clip to the specification
Browse files Browse the repository at this point in the history
PR-URL: 	#715
  • Loading branch information
kgryte authored Jan 22, 2024
1 parent 7a56675 commit 6e320d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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 @@ -33,6 +33,7 @@ Objects in API
bitwise_right_shift
bitwise_xor
ceil
clip
conj
copysign
cos
Expand Down
35 changes: 34 additions & 1 deletion src/array_api_stubs/_draft/elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bitwise_right_shift",
"bitwise_xor",
"ceil",
"clip",
"conj",
"copysign",
"cos",
Expand Down Expand Up @@ -65,7 +66,7 @@
]


from ._types import array
from ._types import Optional, Union, array


def abs(x: array, /) -> array:
Expand Down Expand Up @@ -775,6 +776,38 @@ def ceil(x: array, /) -> array:
"""


def clip(
x: array,
/,
min: Optional[Union[int, float, array]] = None,
max: Optional[Union[int, float, array]] = None,
) -> array:
r"""
Clamps each element ``x_i`` of the input array ``x`` to the range ``[min, max]``.
Parameters
----------
x: array
input array. Should have a real-valued data type.
min: Optional[Union[int, float, array]]
lower-bound of the range to which to clamp. If ``None``, no lower bound must be applied. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
max: Optional[Union[int, float, array]]
upper-bound of the range to which to clamp. If ``None``, no upper bound must be applied. Must be compatible with ``x1`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
Returns
-------
out: array
an array containing element-wise results. The returned array must have the same data type as ``x``.
Notes
-----
- If both ``min`` and ``max`` are ``None``, the elements of the returned array must equal the respective elements in ``x``.
- If a broadcasted element in ``min`` is greater than a corresponding broadcasted element in ``max``, behavior is unspecified and thus implementation-dependent.
- If ``x`` and either ``min`` or ``max`` have different data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.
"""


def conj(x: array, /) -> array:
"""
Returns the complex conjugate for each element ``x_i`` of the input array ``x``.
Expand Down

0 comments on commit 6e320d0

Please sign in to comment.