From 825cec75215c179431f3eb2e733d836115bf237a Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Wed, 26 Jul 2023 13:17:30 -0500 Subject: [PATCH 1/6] add device kwarg to astype API --- .../_draft/data_type_functions.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 700bffd90..857d82ab8 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -1,7 +1,19 @@ -from ._types import Union, Tuple, array, dtype, finfo_object, iinfo_object - - -def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array: +from ._types import ( + Union, + Tuple, + array, + dtype, + finfo_object, + iinfo_object, + device, + Optional +) + + +def astype( + x: array, dtype: dtype, /, *, copy: bool = True, + device: Optional[device] = None +) -> array: """ Copies an array to a specified data type irrespective of :ref:`type-promotion` rules. @@ -31,6 +43,8 @@ def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array: desired data type. copy: bool specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated array must be returned. Default: ``True``. + device: Optional[device] + device on which to place the created array. Default: ``None``. Returns ------- From caca863cc228d14aa0a990084aaaf7a5a06175d9 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Gacha Date: Thu, 27 Jul 2023 16:32:13 -0500 Subject: [PATCH 2/6] Add review changes Co-authored-by: Athan --- src/array_api_stubs/_draft/data_type_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 857d82ab8..726e6c8c4 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -44,7 +44,7 @@ def astype( copy: bool specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated array must be returned. Default: ``True``. device: Optional[device] - device on which to place the created array. Default: ``None``. + device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``x``. Default: ``None``. Returns ------- From f7aa6805f598b810e596e296a1c0d5d4e51b70f9 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 19 Sep 2023 15:12:28 -0700 Subject: [PATCH 3/6] Revert removed exported symbols --- src/array_api_stubs/_draft/data_type_functions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 8243d7986..2301fc196 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -1,3 +1,5 @@ +__all__ = ["astype", "can_cast", "finfo", "iinfo", "isdtype", "result_type"] + from ._types import ( Union, Tuple, From 430c96751b59ff33c3825b859f473ad1a3bbf58d Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 19 Sep 2023 15:14:34 -0700 Subject: [PATCH 4/6] Update copy --- src/array_api_stubs/_draft/data_type_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 2301fc196..0f089c889 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -46,7 +46,7 @@ def astype( copy: bool specifies whether to copy an array when the specified ``dtype`` matches the data type of the input array ``x``. If ``True``, a newly allocated array must always be returned. If ``False`` and the specified ``dtype`` matches the data type of the input array, the input array must be returned; otherwise, a newly allocated array must be returned. Default: ``True``. device: Optional[device] - device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``x``. Default: ``None``. + device on which to place the returned array. If ``device`` is ``None``, the output array device must be inferred from ``x``. Default: ``None``. Returns ------- From c33c508114e0f846d6ede134bf679ad88e0ef5ca Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 19 Sep 2023 15:16:51 -0700 Subject: [PATCH 5/6] Fix lint error --- src/array_api_stubs/_draft/data_type_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 0f089c889..11533f7f2 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -8,7 +8,7 @@ finfo_object, iinfo_object, device, - Optional + Optional, ) From 1c6c73c29a45eba6963981a77324c3dce66b16f4 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 19 Sep 2023 15:18:14 -0700 Subject: [PATCH 6/6] Fix lint error --- src/array_api_stubs/_draft/data_type_functions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index 11533f7f2..81d518807 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -13,8 +13,7 @@ def astype( - x: array, dtype: dtype, /, *, copy: bool = True, - device: Optional[device] = None + x: array, dtype: dtype, /, *, copy: bool = True, device: Optional[device] = None ) -> array: """ Copies an array to a specified data type irrespective of :ref:`type-promotion` rules.