From f2ac67e236c1dbc60f66c4a4b041403a197e52f2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 23 Feb 2021 16:17:07 -0700 Subject: Update array_api namespace with latest changes from the spec --- numpy/_array_api/_creation_functions.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'numpy/_array_api/_creation_functions.py') diff --git a/numpy/_array_api/_creation_functions.py b/numpy/_array_api/_creation_functions.py index 68326f291..d015734ff 100644 --- a/numpy/_array_api/_creation_functions.py +++ b/numpy/_array_api/_creation_functions.py @@ -1,9 +1,21 @@ from __future__ import annotations -from ._types import Optional, Tuple, Union, array, device, dtype +from ._types import (Optional, SupportsDLPack, SupportsBufferProtocol, Tuple, + Union, array, device, dtype) import numpy as np +def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, SupportsBufferProtocol], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None, copy: Optional[bool] = None) -> array: + """ + Array API compatible wrapper for :py:func:`np.asarray `. + + See its docstring for more information. + """ + if device is not None: + # Note: Device support is not yet implemented on ndarray + raise NotImplementedError("Device support is not yet implemented") + return np.asarray(obj, dtype=dtype, copy=copy) + def arange(start: Union[int, float], /, *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: """ Array API compatible wrapper for :py:func:`np.arange `. @@ -48,6 +60,10 @@ def eye(N: int, /, *, M: Optional[int] = None, k: Optional[int] = 0, dtype: Opti raise NotImplementedError("Device support is not yet implemented") return np.eye(N, M=M, k=k, dtype=dtype) +def from_dlpack(x: object, /) -> array: + # Note: dlpack support is not yet implemented on ndarray + raise NotImplementedError("DLPack support is not yet implemented") + def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: """ Array API compatible wrapper for :py:func:`np.full `. -- cgit v1.2.1