summaryrefslogtreecommitdiff
path: root/numpy/_array_api
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-02-23 16:17:07 -0700
committerAaron Meurer <asmeurer@gmail.com>2021-02-23 16:17:07 -0700
commitf2ac67e236c1dbc60f66c4a4b041403a197e52f2 (patch)
treec4c50c88cb923667d94666a1558108f9decca963 /numpy/_array_api
parentaffc5f0c2581a8d17825bcb7d9610e4f58560b5d (diff)
downloadnumpy-f2ac67e236c1dbc60f66c4a4b041403a197e52f2.tar.gz
Update array_api namespace with latest changes from the spec
Diffstat (limited to 'numpy/_array_api')
-rw-r--r--numpy/_array_api/_creation_functions.py18
-rw-r--r--numpy/_array_api/_data_type_functions.py30
-rw-r--r--numpy/_array_api/_elementwise_functions.py8
-rw-r--r--numpy/_array_api/_set_functions.py4
-rw-r--r--numpy/_array_api/_types.py6
5 files changed, 62 insertions, 4 deletions
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 <numpy.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 <numpy.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 <numpy.full>`.
diff --git a/numpy/_array_api/_data_type_functions.py b/numpy/_array_api/_data_type_functions.py
new file mode 100644
index 000000000..18f741ebd
--- /dev/null
+++ b/numpy/_array_api/_data_type_functions.py
@@ -0,0 +1,30 @@
+from __future__ import annotations
+
+from ._types import Union, array, dtype
+from collections.abc import Sequence
+
+import numpy as np
+
+def finfo(type: Union[dtype, array], /) -> finfo:
+ """
+ Array API compatible wrapper for :py:func:`np.finfo <numpy.finfo>`.
+
+ See its docstring for more information.
+ """
+ return np.finfo(type)
+
+def iinfo(type: Union[dtype, array], /) -> iinfo:
+ """
+ Array API compatible wrapper for :py:func:`np.iinfo <numpy.iinfo>`.
+
+ See its docstring for more information.
+ """
+ return np.iinfo(type)
+
+def result_type(*arrays_and_dtypes: Sequence[Union[array, dtype]]) -> dtype:
+ """
+ Array API compatible wrapper for :py:func:`np.result_type <numpy.result_type>`.
+
+ See its docstring for more information.
+ """
+ return np.result_type(*arrays_and_dtypes)
diff --git a/numpy/_array_api/_elementwise_functions.py b/numpy/_array_api/_elementwise_functions.py
index 9de4261ac..a117c3370 100644
--- a/numpy/_array_api/_elementwise_functions.py
+++ b/numpy/_array_api/_elementwise_functions.py
@@ -294,6 +294,14 @@ def log10(x: array, /) -> array:
"""
return np.log10(x)
+def logaddexp(x1: array, x2: array) -> array:
+ """
+ Array API compatible wrapper for :py:func:`np.logaddexp <numpy.logaddexp>`.
+
+ See its docstring for more information.
+ """
+ return np.logaddexp(x1, x2)
+
def logical_and(x1: array, x2: array, /) -> array:
"""
Array API compatible wrapper for :py:func:`np.logical_and <numpy.logical_and>`.
diff --git a/numpy/_array_api/_set_functions.py b/numpy/_array_api/_set_functions.py
index 0a75d727e..4dfc215a7 100644
--- a/numpy/_array_api/_set_functions.py
+++ b/numpy/_array_api/_set_functions.py
@@ -4,10 +4,10 @@ from ._types import Tuple, Union, array
import numpy as np
-def unique(x: array, /, *, return_counts: bool = False, return_index: bool = False, return_inverse: bool = False, sorted: bool = True) -> 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 <numpy.unique>`.
See its docstring for more information.
"""
- return np.unique._implementation(x, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse, sorted=sorted)
+ return np.unique._implementation(x, return_counts=return_counts, return_index=return_index, return_inverse=return_inverse)
diff --git a/numpy/_array_api/_types.py b/numpy/_array_api/_types.py
index e8867a29b..3800b7156 100644
--- a/numpy/_array_api/_types.py
+++ b/numpy/_array_api/_types.py
@@ -6,7 +6,8 @@ annotations in the function signatures. The functions in the module are only
valid for inputs that match the given type annotations.
"""
-__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device', 'dtype']
+__all__ = ['Literal', 'Optional', 'Tuple', 'Union', 'array', 'device',
+ 'dtype', 'SupportsDLPack', 'SupportsBufferProtocol', 'PyCapsule']
from typing import Literal, Optional, Tuple, Union, TypeVar
@@ -16,3 +17,6 @@ array = np.ndarray
device = TypeVar('device')
dtype = Literal[np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16,
np.uint32, np.uint64, np.float32, np.float64]
+SupportsDLPack = TypeVar('SupportsDLPack')
+SupportsBufferProtocol = TypeVar('SupportsBufferProtocol')
+PyCapsule = TypeVar('PyCapsule')