Skip to content

Commit 0a425d1

Browse files
authored
docs: clarify clip behavior when arguments have different data types
PR-URL: data-apis#896 Closes: data-apis#811 Ref: data-apis#814 (comment) Ref: data-apis#807 Reviewed-by: Ralf Gommers <ralf.gommers@gmail.com>
1 parent cfa91d3 commit 0a425d1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/array_api_stubs/_2023_12/elementwise_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,9 @@ def clip(
791791
x: array
792792
input array. Should have a real-valued data type.
793793
min: Optional[Union[int, float, array]]
794-
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``.
794+
lower-bound of the range to which to clamp. If ``None``, no lower bound must be applied. Must be compatible with ``x`` and ``max`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
795795
max: Optional[Union[int, float, array]]
796-
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``.
796+
upper-bound of the range to which to clamp. If ``None``, no upper bound must be applied. Must be compatible with ``x`` and ``min`` (see :ref:`broadcasting`). Should have a real-valued data type. Default: ``None``.
797797
798798
Returns
799799
-------

src/array_api_stubs/_draft/elementwise_functions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,22 +824,24 @@ 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`` and ``max`` (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`` and ``min`` (see :ref:`broadcasting`). Should have the same data type as ``x``. Default: ``None``.
830830
831831
Returns
832832
-------
833833
out: array
834-
an array containing element-wise results. The returned array must have the same data type as ``x``.
834+
an array containing element-wise results. The returned array should have the same data type as ``x``.
835835
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.
839840
- If both ``min`` and ``max`` are ``None``, the elements of the returned array must equal the respective elements in ``x``.
840841
- If a broadcasted element in ``min`` is greater than a corresponding broadcasted element in ``max``, behavior is unspecified and thus implementation-dependent.
842+
- For scalar ``min`` and/or ``max``, the scalar values should follow type promotion rules for operations involving arrays and scalar operands (see :ref:`type-promotion`). Hence, 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.
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 either ``min`` or ``max`` is an array having a different data type than ``x``, behavior is unspecified and thus implementation-dependent.
843845
844846
**Special cases**
845847

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy