From 8a82093d410785b73d8960ea5c3fe7a3ed46728a Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:00:00 -0700 Subject: [PATCH 01/11] Add argmax signature --- spec/API_specification/searching_functions.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/API_specification/searching_functions.md diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md new file mode 100644 index 000000000..3f593aa98 --- /dev/null +++ b/spec/API_specification/searching_functions.md @@ -0,0 +1,34 @@ +# Searching Functions + +> Array API specification for sorting functions. +A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions. + +- Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order. +- Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments. +- Unless stated otherwise, functions must support the data types defined in :ref:`data-types`. + + + +### # argmax(x, /, *, axis=None, keepdims=False) + +Returns the indices of the maximum values along a specified axis. When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned. + +#### Parameters + +- **x**: _<array>_ + + - input array. + +- **axis**: _int_ + + - axis along which to search. If `None`, the function must return the index of the maximum value of the flattened array. Default: `None`. + +- **keepdims**: _bool_ + + - If `True`, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if `False`, the reduced axes (dimensions) must not be included in the result. Default: `False`. + +#### Returns + +- **out**: _<array>_ + + - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the maximum value; otherwise, a non-zero-dimensional array containing the indices of the maximum values. \ No newline at end of file From 3e924dc344e72a94d63ca9575bbca90d09e5a628 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:00:16 -0700 Subject: [PATCH 02/11] Update index --- spec/API_specification/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/API_specification/index.rst b/spec/API_specification/index.rst index c256627b6..50921696b 100644 --- a/spec/API_specification/index.rst +++ b/spec/API_specification/index.rst @@ -13,3 +13,4 @@ API specification broadcasting out_keyword elementwise_functions + searching_functions \ No newline at end of file From eab18305de59112da7a52c62667e244f119f1db2 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:01:00 -0700 Subject: [PATCH 03/11] Add argmin signature --- spec/API_specification/searching_functions.md | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index 3f593aa98..a5061f125 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -31,4 +31,28 @@ Returns the indices of the maximum values along a specified axis. When the maxim - **out**: _<array>_ - - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the maximum value; otherwise, a non-zero-dimensional array containing the indices of the maximum values. \ No newline at end of file + - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the maximum value; otherwise, a non-zero-dimensional array containing the indices of the maximum values. + +### # argmin(x, /, *, axis=None, keepdims=False) + +Returns the indices of the minimum values along a specified axis. When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned. + +#### Parameters + +- **x**: _<array>_ + + - input array. + +- **axis**: _int_ + + - axis along which to search. If `None`, the function must return the index of the minimum value of the flattened array. Default: `None`. + +- **keepdims**: _bool_ + + - If `True`, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if `False`, the reduced axes (dimensions) must not be included in the result. Default: `False`. + +#### Returns + +- **out**: _<array>_ + + - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. \ No newline at end of file From 709e70a54a7c5cc53ff1448a8b8075b6a97e400f Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:11:28 -0700 Subject: [PATCH 04/11] Add nonzero signature --- spec/API_specification/searching_functions.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index a5061f125..066e43458 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -55,4 +55,20 @@ Returns the indices of the minimum values along a specified axis. When the minim - **out**: _<array>_ - - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. \ No newline at end of file + - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the minimum value; otherwise, a non-zero-dimensional array containing the indices of the minimum values. + +### # nonzero(x, /) + +Return the indices of the array elements which are non-zero. + +#### Parameters + +- **x**: _<array>_ + + - input array. + +#### Returns + +- **out**: _Tuple\[ <array>, ... ]_ + + - a tuple of arrays, one for each dimension of `x`, containing the indices of the non-zero elements in that dimension. The indices must be returned in row-major, C-style order. \ No newline at end of file From decec89624d4b204d68e055e213a97b5d77e7432 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:32:14 -0700 Subject: [PATCH 05/11] Add where signature --- spec/API_specification/searching_functions.md | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index 066e43458..c68643d3f 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -1,11 +1,14 @@ # Searching Functions -> Array API specification for sorting functions. +> Array API specification for functions for searching arrays. + A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions. - Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order. - Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments. +- Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`. - Unless stated otherwise, functions must support the data types defined in :ref:`data-types`. +- Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`. @@ -71,4 +74,28 @@ Return the indices of the array elements which are non-zero. - **out**: _Tuple\[ <array>, ... ]_ - - a tuple of arrays, one for each dimension of `x`, containing the indices of the non-zero elements in that dimension. The indices must be returned in row-major, C-style order. \ No newline at end of file + - a tuple of `k` arrays, one for each dimension of `x` and each of size `n` (where `n` is the total number of non-zero elements), containing the indices of the non-zero elements in that dimension. The indices must be returned in row-major, C-style order. + +### # where(condition, x1, x2, /) + +Return elements chosen from `x1` or `x2` depending on `condition`. + +#### Parameters + +- **condition**: _<array>_ + + - when truthy, yield `x1_i`; otherwise, yield `x2_i`. Must be compatible with `x1` and `x2` (see :ref:`broadcasting`). + +- **x1**: _<array>_ + + - first input array. Must be compatible with `condition` and `x2` (see :ref:`broadcasting`). + +- **x2**: _<array>_ + + - second input array. Must be compatible with `x1` and `condition` (see :ref:`broadcasting`). + +#### Returns + +- **out**: _Tuple\[ <array>, ... ]_ + + - an array with elements from `x1` where `condition` is truthy, and elements from `x2` elsewhere. \ No newline at end of file From aa286ce3e2f88c4ef74f63cb3a54d46d50d3ce6b Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:36:04 -0700 Subject: [PATCH 06/11] Update descriptions --- spec/API_specification/searching_functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index c68643d3f..a47ef2265 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -62,7 +62,7 @@ Returns the indices of the minimum values along a specified axis. When the minim ### # nonzero(x, /) -Return the indices of the array elements which are non-zero. +Returns the indices of the array elements which are non-zero. #### Parameters @@ -78,7 +78,7 @@ Return the indices of the array elements which are non-zero. ### # where(condition, x1, x2, /) -Return elements chosen from `x1` or `x2` depending on `condition`. +Returns elements chosen from `x1` or `x2` depending on `condition`. #### Parameters From 0886a865f415a42df40e2b33da5a462c15550c7c Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 00:37:33 -0700 Subject: [PATCH 07/11] Fix return typing --- spec/API_specification/searching_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index a47ef2265..a2741cd64 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -96,6 +96,6 @@ Returns elements chosen from `x1` or `x2` depending on `condition`. #### Returns -- **out**: _Tuple\[ <array>, ... ]_ +- **out**: _<array>_ - an array with elements from `x1` where `condition` is truthy, and elements from `x2` elsewhere. \ No newline at end of file From f51d1197f0d648089e17f6043b942c9bc6dd26e6 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 11:23:13 -0700 Subject: [PATCH 08/11] Require an arry of booleans --- spec/API_specification/searching_functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index a2741cd64..dd0ca0cbe 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -82,9 +82,9 @@ Returns elements chosen from `x1` or `x2` depending on `condition`. #### Parameters -- **condition**: _<array>_ +- **condition**: _<array<bool>>_ - - when truthy, yield `x1_i`; otherwise, yield `x2_i`. Must be compatible with `x1` and `x2` (see :ref:`broadcasting`). + - when `True`, yield `x1_i`; otherwise, yield `x2_i`. Must be compatible with `x1` and `x2` (see :ref:`broadcasting`). - **x1**: _<array>_ @@ -98,4 +98,4 @@ Returns elements chosen from `x1` or `x2` depending on `condition`. - **out**: _<array>_ - - an array with elements from `x1` where `condition` is truthy, and elements from `x2` elsewhere. \ No newline at end of file + - an array with elements from `x1` where `condition` is `True`, and elements from `x2` elsewhere. \ No newline at end of file From 2d2244eff97e7679b1e6f0932b93d68b21dbf6ec Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 11:28:59 -0700 Subject: [PATCH 09/11] Require positive rank --- spec/API_specification/searching_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index dd0ca0cbe..96faf42d0 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -68,7 +68,7 @@ Returns the indices of the array elements which are non-zero. - **x**: _<array>_ - - input array. + - input array. Must have a positive rank. If `x` is zero-dimensional, the function must raise an exception. #### Returns From 43bd5587259fa605061f165627dd0b593ada19a9 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 11:35:18 -0700 Subject: [PATCH 10/11] Add optional `out` keyword argument to maintain consistency with max/min --- spec/API_specification/searching_functions.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index 96faf42d0..b62499075 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -6,13 +6,14 @@ A conforming implementation of the array API standard must provide and support t - Positional parameters must be [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order. - Optional parameters must be [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments. +- The `out` keyword argument must follow the conventions defined in :ref:`out-keyword`. - Broadcasting semantics must follow the semantics defined in :ref:`broadcasting`. - Unless stated otherwise, functions must support the data types defined in :ref:`data-types`. - Unless stated otherwise, functions must adhere to the type promotion rules defined in :ref:`type-promotion`. -### # argmax(x, /, *, axis=None, keepdims=False) +### # argmax(x, /, *, axis=None, keepdims=False, out=None) Returns the indices of the maximum values along a specified axis. When the maximum value occurs multiple times, only the indices corresponding to the first occurrence are returned. @@ -30,13 +31,17 @@ Returns the indices of the maximum values along a specified axis. When the maxim - If `True`, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if `False`, the reduced axes (dimensions) must not be included in the result. Default: `False`. +- **out**: _Optional\[ <array> ]_ + + - output array. If provided, the output array must have the expected output shape. If not provided or is `None`, an uninitialized return array must be created and then filled with the result of each computation. Default: `None`. + #### Returns - **out**: _<array>_ - if `axis` is `None`, a zero-dimensional array containing the index of the first occurrence of the maximum value; otherwise, a non-zero-dimensional array containing the indices of the maximum values. -### # argmin(x, /, *, axis=None, keepdims=False) +### # argmin(x, /, *, axis=None, keepdims=False, out=None) Returns the indices of the minimum values along a specified axis. When the minimum value occurs multiple times, only the indices corresponding to the first occurrence are returned. @@ -54,6 +59,10 @@ Returns the indices of the minimum values along a specified axis. When the minim - If `True`, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see :ref:`broadcasting`). Otherwise, if `False`, the reduced axes (dimensions) must not be included in the result. Default: `False`. +- **out**: _Optional\[ <array> ]_ + + - output array. If provided, the output array must have the expected output shape. If not provided or is `None`, an uninitialized return array must be created and then filled with the result of each computation. Default: `None`. + #### Returns - **out**: _<array>_ From 13cf3f8e76545372ebf5b4bfe601bd6069b9ce88 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 26 Aug 2020 11:39:13 -0700 Subject: [PATCH 11/11] Update description --- spec/API_specification/searching_functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/searching_functions.md b/spec/API_specification/searching_functions.md index b62499075..58a3286d6 100644 --- a/spec/API_specification/searching_functions.md +++ b/spec/API_specification/searching_functions.md @@ -101,7 +101,7 @@ Returns elements chosen from `x1` or `x2` depending on `condition`. - **x2**: _<array>_ - - second input array. Must be compatible with `x1` and `condition` (see :ref:`broadcasting`). + - second input array. Must be compatible with `condition` and `x1` (see :ref:`broadcasting`). #### Returns 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