From 6e57d829cb6628610e163524f203245b247a2839 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Aug 2021 16:47:05 -0600 Subject: Rename numpy._array_api to numpy.array_api Instead of the leading underscore, the experimentalness of the module will be indicated by omitting a warning on import. That we, we do not have to change the API from underscore to no underscore when the module is no longer experimental. --- numpy/array_api/_set_functions.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 numpy/array_api/_set_functions.py (limited to 'numpy/array_api/_set_functions.py') diff --git a/numpy/array_api/_set_functions.py b/numpy/array_api/_set_functions.py new file mode 100644 index 000000000..f28c2ee72 --- /dev/null +++ b/numpy/array_api/_set_functions.py @@ -0,0 +1,15 @@ +from __future__ import annotations + +from ._array_object import Array + +from typing import Tuple, Union + +import numpy as np + +def unique(x: Array, /, *, return_counts: bool = False, return_index: bool = False, return_inverse: bool = False) -> Union[Array, Tuple[Array, ...]]: + """ + Array API compatible wrapper for :py:func:`np.unique `. + + See its docstring for more information. + """ + return Array._new(np.unique(x._array, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse)) -- cgit v1.2.1 From 4063752757a97c444b8913947a0890f2c2387bca Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 6 Aug 2021 16:57:10 -0600 Subject: Fix the array API unique() function --- numpy/array_api/_set_functions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'numpy/array_api/_set_functions.py') diff --git a/numpy/array_api/_set_functions.py b/numpy/array_api/_set_functions.py index f28c2ee72..acd59f597 100644 --- a/numpy/array_api/_set_functions.py +++ b/numpy/array_api/_set_functions.py @@ -12,4 +12,8 @@ def unique(x: Array, /, *, return_counts: bool = False, return_index: bool = Fal See its docstring for more information. """ - return Array._new(np.unique(x._array, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse)) + res = np.unique(x._array, return_counts=return_counts, + return_index=return_index, return_inverse=return_inverse) + if isinstance(res, tuple): + return tuple(Array._new(i) for i in res) + return Array._new(res) -- cgit v1.2.1 From 8f7d00ed447174d9398af3365709222b529c1cad Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 6 Aug 2021 18:22:00 -0600 Subject: Run (selective) black on the array_api submodule I've omitted a few changes from black that messed up the readability of some complicated if statements that were organized logically line-by-line, and some changes that use unnecessary operator spacing. --- numpy/array_api/_set_functions.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'numpy/array_api/_set_functions.py') diff --git a/numpy/array_api/_set_functions.py b/numpy/array_api/_set_functions.py index acd59f597..357f238f5 100644 --- a/numpy/array_api/_set_functions.py +++ b/numpy/array_api/_set_functions.py @@ -6,14 +6,26 @@ from typing import Tuple, Union import numpy as np -def unique(x: Array, /, *, return_counts: bool = False, return_index: bool = False, return_inverse: bool = False) -> Union[Array, Tuple[Array, ...]]: + +def unique( + x: Array, + /, + *, + return_counts: bool = False, + return_index: bool = False, + return_inverse: bool = False, +) -> Union[Array, Tuple[Array, ...]]: """ Array API compatible wrapper for :py:func:`np.unique `. See its docstring for more information. """ - res = np.unique(x._array, return_counts=return_counts, - return_index=return_index, return_inverse=return_inverse) + res = np.unique( + x._array, + return_counts=return_counts, + return_index=return_index, + return_inverse=return_inverse, + ) if isinstance(res, tuple): return tuple(Array._new(i) for i in res) return Array._new(res) -- cgit v1.2.1