Skip to content

Commit cf3131d

Browse files
committed
docs: clarify clip behavior when arguments have different data types
Ref: data-apis#814 (comment)
1 parent f73baff commit cf3131d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/array_api_stubs/_draft/elementwise_functions.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ def clip(
824824
x: array
825825
input array. Should have a real-valued data type.
826826
min: Optional[Union[int, float, array]]
827-
lower-bound of the range to which to clamp. If ``None``, no lower bound must be applied. Must be compatible with ``x`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
827+
lower-bound of the range to which to clamp. If ``None``, no lower bound must be applied. Must be compatible with ``x`` (see :ref:`broadcasting`). Should have the same data type as ``x``. Default: ``None``.
828828
max: Optional[Union[int, float, array]]
829-
upper-bound of the range to which to clamp. If ``None``, no upper bound must be applied. Must be compatible with ``x`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
829+
upper-bound of the range to which to clamp. If ``None``, no upper bound must be applied. Must be compatible with ``x`` (see :ref:`broadcasting`). Should have the same data type as ``x``. Default: ``None``.
830830
831831
Returns
832832
-------
@@ -836,10 +836,12 @@ def clip(
836836
Notes
837837
-----
838838
839+
- This function is conceptually equivalent to ``maximum(minimum(x, max), min)`` when ``x``, ``min``, and ``max`` have the same data type.
840+
- For scalar ``min`` and/or ``max``, the scalar values must be converted to zero-dimensional arrays having the same data type as ``x`` prior to broadcasting.
839841
- If both ``min`` and ``max`` are ``None``, the elements of the returned array must equal the respective elements in ``x``.
840842
- If a broadcasted element in ``min`` is greater than a corresponding broadcasted element in ``max``, behavior is unspecified and thus implementation-dependent.
841843
- If ``x`` has an integral data type and a broadcasted element in ``min`` or ``max`` is outside the bounds of the data type of ``x``, behavior is unspecified and thus implementation-dependent.
842-
- 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.
844+
- If ``x`` and either ``min`` or ``max`` have different data types and/or data type kinds (e.g., integer versus floating-point), behavior is unspecified and thus implementation-dependent.
843845
844846
**Special cases**
845847

0 commit comments

Comments
 (0)