diff options
Diffstat (limited to 'numpy/_array_api')
-rw-r--r-- | numpy/_array_api/_array_object.py | 118 | ||||
-rw-r--r-- | numpy/_array_api/_creation_functions.py | 32 | ||||
-rw-r--r-- | numpy/_array_api/_data_type_functions.py | 14 | ||||
-rw-r--r-- | numpy/_array_api/_elementwise_functions.py | 114 | ||||
-rw-r--r-- | numpy/_array_api/_linear_algebra_functions.py | 10 | ||||
-rw-r--r-- | numpy/_array_api/_manipulation_functions.py | 16 | ||||
-rw-r--r-- | numpy/_array_api/_searching_functions.py | 10 | ||||
-rw-r--r-- | numpy/_array_api/_set_functions.py | 4 | ||||
-rw-r--r-- | numpy/_array_api/_sorting_functions.py | 6 | ||||
-rw-r--r-- | numpy/_array_api/_statistical_functions.py | 16 | ||||
-rw-r--r-- | numpy/_array_api/_types.py | 10 | ||||
-rw-r--r-- | numpy/_array_api/_utility_functions.py | 6 |
12 files changed, 178 insertions, 178 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py index 8f7252160..89ec3ba1a 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -22,7 +22,7 @@ from ._dtypes import _boolean_dtypes, _integer_dtypes, _floating_dtypes from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Any, Optional, PyCapsule, Tuple, Union, array + from ._types import Any, Optional, PyCapsule, Tuple, Union, Array import numpy as np @@ -71,13 +71,13 @@ class ndarray: # These functions are not required by the spec, but are implemented for # the sake of usability. - def __str__(self: array, /) -> str: + def __str__(self: Array, /) -> str: """ Performs the operation __str__. """ return self._array.__str__().replace('array', 'ndarray') - def __repr__(self: array, /) -> str: + def __repr__(self: Array, /) -> str: """ Performs the operation __repr__. """ @@ -142,7 +142,7 @@ class ndarray: # Everything below this line is required by the spec. - def __abs__(self: array, /) -> array: + def __abs__(self: Array, /) -> Array: """ Performs the operation __abs__. """ @@ -150,7 +150,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __add__(self: array, other: Union[int, float, array], /) -> array: + def __add__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __add__. """ @@ -160,7 +160,7 @@ class ndarray: res = self._array.__add__(other._array) return self.__class__._new(res) - def __and__(self: array, other: Union[int, bool, array], /) -> array: + def __and__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __and__. """ @@ -170,13 +170,13 @@ class ndarray: res = self._array.__and__(other._array) return self.__class__._new(res) - def __array_namespace__(self: array, /, *, api_version: Optional[str] = None) -> object: + def __array_namespace__(self: Array, /, *, api_version: Optional[str] = None) -> object: if api_version is not None: raise ValueError("Unrecognized array API version") from numpy import _array_api return _array_api - def __bool__(self: array, /) -> bool: + def __bool__(self: Array, /) -> bool: """ Performs the operation __bool__. """ @@ -186,14 +186,14 @@ class ndarray: res = self._array.__bool__() return res - def __dlpack__(self: array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule: + def __dlpack__(self: Array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule: """ Performs the operation __dlpack__. """ res = self._array.__dlpack__(stream=None) return self.__class__._new(res) - def __dlpack_device__(self: array, /) -> Tuple[IntEnum, int]: + def __dlpack_device__(self: Array, /) -> Tuple[IntEnum, int]: """ Performs the operation __dlpack_device__. """ @@ -201,7 +201,7 @@ class ndarray: res = self._array.__dlpack_device__() return self.__class__._new(res) - def __eq__(self: array, other: Union[int, float, bool, array], /) -> array: + def __eq__(self: Array, other: Union[int, float, bool, Array], /) -> Array: """ Performs the operation __eq__. """ @@ -211,7 +211,7 @@ class ndarray: res = self._array.__eq__(other._array) return self.__class__._new(res) - def __float__(self: array, /) -> float: + def __float__(self: Array, /) -> float: """ Performs the operation __float__. """ @@ -222,7 +222,7 @@ class ndarray: return res @np.errstate(all='ignore') - def __floordiv__(self: array, other: Union[int, float, array], /) -> array: + def __floordiv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __floordiv__. """ @@ -232,7 +232,7 @@ class ndarray: res = self._array.__floordiv__(other._array) return self.__class__._new(res) - def __ge__(self: array, other: Union[int, float, array], /) -> array: + def __ge__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __ge__. """ @@ -349,7 +349,7 @@ class ndarray: # ndarray() form, like a list of booleans. raise IndexError("Only integers, slices (`:`), ellipsis (`...`), and boolean arrays are valid indices in the array API namespace") - def __getitem__(self: array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], array], /) -> array: + def __getitem__(self: Array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array], /) -> Array: """ Performs the operation __getitem__. """ @@ -359,7 +359,7 @@ class ndarray: res = self._array.__getitem__(key) return self.__class__._new(res) - def __gt__(self: array, other: Union[int, float, array], /) -> array: + def __gt__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __gt__. """ @@ -369,7 +369,7 @@ class ndarray: res = self._array.__gt__(other._array) return self.__class__._new(res) - def __int__(self: array, /) -> int: + def __int__(self: Array, /) -> int: """ Performs the operation __int__. """ @@ -379,14 +379,14 @@ class ndarray: res = self._array.__int__() return res - def __invert__(self: array, /) -> array: + def __invert__(self: Array, /) -> Array: """ Performs the operation __invert__. """ res = self._array.__invert__() return self.__class__._new(res) - def __le__(self: array, other: Union[int, float, array], /) -> array: + def __le__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __le__. """ @@ -403,7 +403,7 @@ class ndarray: res = self._array.__len__() return self.__class__._new(res) - def __lshift__(self: array, other: Union[int, array], /) -> array: + def __lshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __lshift__. """ @@ -416,7 +416,7 @@ class ndarray: res = self._array.__lshift__(other._array).astype(self.dtype) return self.__class__._new(res) - def __lt__(self: array, other: Union[int, float, array], /) -> array: + def __lt__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __lt__. """ @@ -426,7 +426,7 @@ class ndarray: res = self._array.__lt__(other._array) return self.__class__._new(res) - def __matmul__(self: array, other: array, /) -> array: + def __matmul__(self: Array, other: Array, /) -> Array: """ Performs the operation __matmul__. """ @@ -438,7 +438,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __mod__(self: array, other: Union[int, float, array], /) -> array: + def __mod__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __mod__. """ @@ -449,7 +449,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __mul__(self: array, other: Union[int, float, array], /) -> array: + def __mul__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __mul__. """ @@ -459,7 +459,7 @@ class ndarray: res = self._array.__mul__(other._array) return self.__class__._new(res) - def __ne__(self: array, other: Union[int, float, bool, array], /) -> array: + def __ne__(self: Array, other: Union[int, float, bool, Array], /) -> Array: """ Performs the operation __ne__. """ @@ -469,14 +469,14 @@ class ndarray: res = self._array.__ne__(other._array) return self.__class__._new(res) - def __neg__(self: array, /) -> array: + def __neg__(self: Array, /) -> Array: """ Performs the operation __neg__. """ res = self._array.__neg__() return self.__class__._new(res) - def __or__(self: array, other: Union[int, bool, array], /) -> array: + def __or__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __or__. """ @@ -486,7 +486,7 @@ class ndarray: res = self._array.__or__(other._array) return self.__class__._new(res) - def __pos__(self: array, /) -> array: + def __pos__(self: Array, /) -> Array: """ Performs the operation __pos__. """ @@ -494,7 +494,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __pow__(self: array, other: Union[int, float, array], /) -> array: + def __pow__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __pow__. """ @@ -506,7 +506,7 @@ class ndarray: # arrays, so we use pow() here instead. return pow(self, other) - def __rshift__(self: array, other: Union[int, array], /) -> array: + def __rshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __rshift__. """ @@ -530,7 +530,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __sub__(self: array, other: Union[int, float, array], /) -> array: + def __sub__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __sub__. """ @@ -541,7 +541,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __truediv__(self: array, other: Union[int, float, array], /) -> array: + def __truediv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __truediv__. """ @@ -551,7 +551,7 @@ class ndarray: res = self._array.__truediv__(other._array) return self.__class__._new(res) - def __xor__(self: array, other: Union[int, bool, array], /) -> array: + def __xor__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __xor__. """ @@ -562,7 +562,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __iadd__(self: array, other: Union[int, float, array], /) -> array: + def __iadd__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __iadd__. """ @@ -572,7 +572,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __radd__(self: array, other: Union[int, float, array], /) -> array: + def __radd__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __radd__. """ @@ -582,7 +582,7 @@ class ndarray: res = self._array.__radd__(other._array) return self.__class__._new(res) - def __iand__(self: array, other: Union[int, bool, array], /) -> array: + def __iand__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __iand__. """ @@ -591,7 +591,7 @@ class ndarray: self._array.__iand__(other._array) return self - def __rand__(self: array, other: Union[int, bool, array], /) -> array: + def __rand__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __rand__. """ @@ -602,7 +602,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __ifloordiv__(self: array, other: Union[int, float, array], /) -> array: + def __ifloordiv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __ifloordiv__. """ @@ -612,7 +612,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rfloordiv__(self: array, other: Union[int, float, array], /) -> array: + def __rfloordiv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rfloordiv__. """ @@ -622,7 +622,7 @@ class ndarray: res = self._array.__rfloordiv__(other._array) return self.__class__._new(res) - def __ilshift__(self: array, other: Union[int, array], /) -> array: + def __ilshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __ilshift__. """ @@ -631,7 +631,7 @@ class ndarray: self._array.__ilshift__(other._array) return self - def __rlshift__(self: array, other: Union[int, array], /) -> array: + def __rlshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __rlshift__. """ @@ -644,7 +644,7 @@ class ndarray: res = self._array.__rlshift__(other._array).astype(other.dtype) return self.__class__._new(res) - def __imatmul__(self: array, other: array, /) -> array: + def __imatmul__(self: Array, other: Array, /) -> Array: """ Performs the operation __imatmul__. """ @@ -664,7 +664,7 @@ class ndarray: self._array[:] = self._array.__matmul__(other._array) return self - def __rmatmul__(self: array, other: array, /) -> array: + def __rmatmul__(self: Array, other: Array, /) -> Array: """ Performs the operation __rmatmul__. """ @@ -676,7 +676,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __imod__(self: array, other: Union[int, float, array], /) -> array: + def __imod__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __imod__. """ @@ -686,7 +686,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rmod__(self: array, other: Union[int, float, array], /) -> array: + def __rmod__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rmod__. """ @@ -697,7 +697,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __imul__(self: array, other: Union[int, float, array], /) -> array: + def __imul__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __imul__. """ @@ -707,7 +707,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rmul__(self: array, other: Union[int, float, array], /) -> array: + def __rmul__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rmul__. """ @@ -717,7 +717,7 @@ class ndarray: res = self._array.__rmul__(other._array) return self.__class__._new(res) - def __ior__(self: array, other: Union[int, bool, array], /) -> array: + def __ior__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __ior__. """ @@ -726,7 +726,7 @@ class ndarray: self._array.__ior__(other._array) return self - def __ror__(self: array, other: Union[int, bool, array], /) -> array: + def __ror__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __ror__. """ @@ -737,7 +737,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __ipow__(self: array, other: Union[int, float, array], /) -> array: + def __ipow__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __ipow__. """ @@ -747,7 +747,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rpow__(self: array, other: Union[int, float, array], /) -> array: + def __rpow__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rpow__. """ @@ -759,7 +759,7 @@ class ndarray: # for 0-d arrays, so we use pow() here instead. return pow(other, self) - def __irshift__(self: array, other: Union[int, array], /) -> array: + def __irshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __irshift__. """ @@ -768,7 +768,7 @@ class ndarray: self._array.__irshift__(other._array) return self - def __rrshift__(self: array, other: Union[int, array], /) -> array: + def __rrshift__(self: Array, other: Union[int, Array], /) -> Array: """ Performs the operation __rrshift__. """ @@ -782,7 +782,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __isub__(self: array, other: Union[int, float, array], /) -> array: + def __isub__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __isub__. """ @@ -792,7 +792,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rsub__(self: array, other: Union[int, float, array], /) -> array: + def __rsub__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rsub__. """ @@ -803,7 +803,7 @@ class ndarray: return self.__class__._new(res) @np.errstate(all='ignore') - def __itruediv__(self: array, other: Union[int, float, array], /) -> array: + def __itruediv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __itruediv__. """ @@ -813,7 +813,7 @@ class ndarray: return self @np.errstate(all='ignore') - def __rtruediv__(self: array, other: Union[int, float, array], /) -> array: + def __rtruediv__(self: Array, other: Union[int, float, Array], /) -> Array: """ Performs the operation __rtruediv__. """ @@ -823,7 +823,7 @@ class ndarray: res = self._array.__rtruediv__(other._array) return self.__class__._new(res) - def __ixor__(self: array, other: Union[int, bool, array], /) -> array: + def __ixor__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __ixor__. """ @@ -832,7 +832,7 @@ class ndarray: self._array.__ixor__(other._array) return self - def __rxor__(self: array, other: Union[int, bool, array], /) -> array: + def __rxor__(self: Array, other: Union[int, bool, Array], /) -> Array: """ Performs the operation __rxor__. """ diff --git a/numpy/_array_api/_creation_functions.py b/numpy/_array_api/_creation_functions.py index 08dc772b5..9845dd70f 100644 --- a/numpy/_array_api/_creation_functions.py +++ b/numpy/_array_api/_creation_functions.py @@ -4,14 +4,14 @@ from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: from ._types import (List, Optional, SupportsDLPack, - SupportsBufferProtocol, Tuple, Union, array, device, - dtype) + SupportsBufferProtocol, Tuple, Union, Array, Device, + Dtype) from collections.abc import Sequence from ._dtypes import _all_dtypes 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: +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>`. @@ -37,7 +37,7 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su raise TypeError(f"The array_api namespace does not support the dtype '{res.dtype}'") return ndarray._new(res) -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: +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>`. @@ -49,7 +49,7 @@ def arange(start: Union[int, float], /, stop: Optional[Union[int, float]] = None raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.arange(start, stop=stop, step=step, dtype=dtype)) -def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`. @@ -61,7 +61,7 @@ def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.empty(shape, dtype=dtype)) -def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def empty_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`. @@ -73,7 +73,7 @@ def empty_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[d raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.empty_like(x._array, dtype=dtype)) -def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`. @@ -85,11 +85,11 @@ def eye(n_rows: int, n_cols: Optional[int] = None, /, *, k: Optional[int] = 0, d raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.eye(n_rows, M=n_cols, k=k, dtype=dtype)) -def from_dlpack(x: object, /) -> array: +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: +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>`. @@ -108,7 +108,7 @@ def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, d raise TypeError("Invalid input to full") return ndarray._new(res) -def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def full_like(x: Array, /, fill_value: Union[int, float], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`. @@ -125,7 +125,7 @@ def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dty raise TypeError("Invalid input to full_like") return ndarray._new(res) -def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: bool = True) -> array: +def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None, endpoint: bool = True) -> Array: """ Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`. @@ -137,7 +137,7 @@ def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.linspace(start, stop, num, dtype=dtype, endpoint=endpoint)) -def meshgrid(*arrays: Sequence[array], indexing: str = 'xy') -> List[array, ...]: +def meshgrid(*arrays: Sequence[Array], indexing: str = 'xy') -> List[Array, ...]: """ Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`. @@ -146,7 +146,7 @@ def meshgrid(*arrays: Sequence[array], indexing: str = 'xy') -> List[array, ...] from ._array_object import ndarray return [ndarray._new(array) for array in np.meshgrid(*[a._array for a in arrays], indexing=indexing)] -def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`. @@ -158,7 +158,7 @@ def ones(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, d raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.ones(shape, dtype=dtype)) -def ones_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def ones_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`. @@ -170,7 +170,7 @@ def ones_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[de raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.ones_like(x._array, dtype=dtype)) -def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`. @@ -182,7 +182,7 @@ def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, raise NotImplementedError("Device support is not yet implemented") return ndarray._new(np.zeros(shape, dtype=dtype)) -def zeros_like(x: array, /, *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array: +def zeros_like(x: Array, /, *, dtype: Optional[Dtype] = None, device: Optional[Device] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`. diff --git a/numpy/_array_api/_data_type_functions.py b/numpy/_array_api/_data_type_functions.py index 03a857dfc..5ab611fd3 100644 --- a/numpy/_array_api/_data_type_functions.py +++ b/numpy/_array_api/_data_type_functions.py @@ -4,12 +4,12 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import List, Tuple, Union, array, dtype + from ._types import List, Tuple, Union, Array, Dtype from collections.abc import Sequence import numpy as np -def broadcast_arrays(*arrays: Sequence[array]) -> List[array]: +def broadcast_arrays(*arrays: Sequence[Array]) -> List[Array]: """ Array API compatible wrapper for :py:func:`np.broadcast_arrays <numpy.broadcast_arrays>`. @@ -18,7 +18,7 @@ def broadcast_arrays(*arrays: Sequence[array]) -> List[array]: from ._array_object import ndarray return [ndarray._new(array) for array in np.broadcast_arrays(*[a._array for a in arrays])] -def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array: +def broadcast_to(x: Array, /, shape: Tuple[int, ...]) -> Array: """ Array API compatible wrapper for :py:func:`np.broadcast_to <numpy.broadcast_to>`. @@ -27,7 +27,7 @@ def broadcast_to(x: array, /, shape: Tuple[int, ...]) -> array: from ._array_object import ndarray return ndarray._new(np.broadcast_to(x._array, shape)) -def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool: +def can_cast(from_: Union[Dtype, Array], to: Dtype, /) -> bool: """ Array API compatible wrapper for :py:func:`np.can_cast <numpy.can_cast>`. @@ -38,7 +38,7 @@ def can_cast(from_: Union[dtype, array], to: dtype, /) -> bool: from_ = from_._array return np.can_cast(from_, to) -def finfo(type: Union[dtype, array], /) -> finfo_object: +def finfo(type: Union[Dtype, Array], /) -> finfo_object: """ Array API compatible wrapper for :py:func:`np.finfo <numpy.finfo>`. @@ -46,7 +46,7 @@ def finfo(type: Union[dtype, array], /) -> finfo_object: """ return np.finfo(type) -def iinfo(type: Union[dtype, array], /) -> iinfo_object: +def iinfo(type: Union[Dtype, Array], /) -> iinfo_object: """ Array API compatible wrapper for :py:func:`np.iinfo <numpy.iinfo>`. @@ -54,7 +54,7 @@ def iinfo(type: Union[dtype, array], /) -> iinfo_object: """ return np.iinfo(type) -def result_type(*arrays_and_dtypes: Sequence[Union[array, dtype]]) -> dtype: +def result_type(*arrays_and_dtypes: Sequence[Union[Array, Dtype]]) -> Dtype: """ Array API compatible wrapper for :py:func:`np.result_type <numpy.result_type>`. diff --git a/numpy/_array_api/_elementwise_functions.py b/numpy/_array_api/_elementwise_functions.py index 197e77324..ae265181a 100644 --- a/numpy/_array_api/_elementwise_functions.py +++ b/numpy/_array_api/_elementwise_functions.py @@ -7,11 +7,11 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import array + from ._types import Array import numpy as np -def abs(x: array, /) -> array: +def abs(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.abs <numpy.abs>`. @@ -23,7 +23,7 @@ def abs(x: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def acos(x: array, /) -> array: +def acos(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arccos <numpy.arccos>`. @@ -35,7 +35,7 @@ def acos(x: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def acosh(x: array, /) -> array: +def acosh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arccosh <numpy.arccosh>`. @@ -46,7 +46,7 @@ def acosh(x: array, /) -> array: return ndarray._new(np.arccosh(x._array)) @np.errstate(all='ignore') -def add(x1: array, x2: array, /) -> array: +def add(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.add <numpy.add>`. @@ -59,7 +59,7 @@ def add(x1: array, x2: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def asin(x: array, /) -> array: +def asin(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arcsin <numpy.arcsin>`. @@ -71,7 +71,7 @@ def asin(x: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def asinh(x: array, /) -> array: +def asinh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arcsinh <numpy.arcsinh>`. @@ -82,7 +82,7 @@ def asinh(x: array, /) -> array: return ndarray._new(np.arcsinh(x._array)) # Note: the function name is different here -def atan(x: array, /) -> array: +def atan(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arctan <numpy.arctan>`. @@ -93,7 +93,7 @@ def atan(x: array, /) -> array: return ndarray._new(np.arctan(x._array)) # Note: the function name is different here -def atan2(x1: array, x2: array, /) -> array: +def atan2(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arctan2 <numpy.arctan2>`. @@ -106,7 +106,7 @@ def atan2(x1: array, x2: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def atanh(x: array, /) -> array: +def atanh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.arctanh <numpy.arctanh>`. @@ -116,7 +116,7 @@ def atanh(x: array, /) -> array: raise TypeError('Only floating-point dtypes are allowed in atanh') return ndarray._new(np.arctanh(x._array)) -def bitwise_and(x1: array, x2: array, /) -> array: +def bitwise_and(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.bitwise_and <numpy.bitwise_and>`. @@ -128,7 +128,7 @@ def bitwise_and(x1: array, x2: array, /) -> array: return ndarray._new(np.bitwise_and(x1._array, x2._array)) # Note: the function name is different here -def bitwise_left_shift(x1: array, x2: array, /) -> array: +def bitwise_left_shift(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.left_shift <numpy.left_shift>`. @@ -146,7 +146,7 @@ def bitwise_left_shift(x1: array, x2: array, /) -> array: return ndarray._new(np.left_shift(x1._array, x2._array).astype(x1.dtype)) # Note: the function name is different here -def bitwise_invert(x: array, /) -> array: +def bitwise_invert(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.invert <numpy.invert>`. @@ -156,7 +156,7 @@ def bitwise_invert(x: array, /) -> array: raise TypeError('Only integer or boolean dtypes are allowed in bitwise_invert') return ndarray._new(np.invert(x._array)) -def bitwise_or(x1: array, x2: array, /) -> array: +def bitwise_or(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.bitwise_or <numpy.bitwise_or>`. @@ -168,7 +168,7 @@ def bitwise_or(x1: array, x2: array, /) -> array: return ndarray._new(np.bitwise_or(x1._array, x2._array)) # Note: the function name is different here -def bitwise_right_shift(x1: array, x2: array, /) -> array: +def bitwise_right_shift(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.right_shift <numpy.right_shift>`. @@ -185,7 +185,7 @@ def bitwise_right_shift(x1: array, x2: array, /) -> array: # type promotion of the two input types. return ndarray._new(np.right_shift(x1._array, x2._array).astype(x1.dtype)) -def bitwise_xor(x1: array, x2: array, /) -> array: +def bitwise_xor(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.bitwise_xor <numpy.bitwise_xor>`. @@ -196,7 +196,7 @@ def bitwise_xor(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.bitwise_xor(x1._array, x2._array)) -def ceil(x: array, /) -> array: +def ceil(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.ceil <numpy.ceil>`. @@ -210,7 +210,7 @@ def ceil(x: array, /) -> array: return ndarray._new(np.ceil(x._array)) @np.errstate(all='ignore') -def cos(x: array, /) -> array: +def cos(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.cos <numpy.cos>`. @@ -221,7 +221,7 @@ def cos(x: array, /) -> array: return ndarray._new(np.cos(x._array)) @np.errstate(all='ignore') -def cosh(x: array, /) -> array: +def cosh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.cosh <numpy.cosh>`. @@ -232,7 +232,7 @@ def cosh(x: array, /) -> array: return ndarray._new(np.cosh(x._array)) @np.errstate(all='ignore') -def divide(x1: array, x2: array, /) -> array: +def divide(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.divide <numpy.divide>`. @@ -243,7 +243,7 @@ def divide(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.divide(x1._array, x2._array)) -def equal(x1: array, x2: array, /) -> array: +def equal(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.equal <numpy.equal>`. @@ -253,7 +253,7 @@ def equal(x1: array, x2: array, /) -> array: return ndarray._new(np.equal(x1._array, x2._array)) @np.errstate(all='ignore') -def exp(x: array, /) -> array: +def exp(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.exp <numpy.exp>`. @@ -264,7 +264,7 @@ def exp(x: array, /) -> array: return ndarray._new(np.exp(x._array)) @np.errstate(all='ignore') -def expm1(x: array, /) -> array: +def expm1(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.expm1 <numpy.expm1>`. @@ -274,7 +274,7 @@ def expm1(x: array, /) -> array: raise TypeError('Only floating-point dtypes are allowed in expm1') return ndarray._new(np.expm1(x._array)) -def floor(x: array, /) -> array: +def floor(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.floor <numpy.floor>`. @@ -288,7 +288,7 @@ def floor(x: array, /) -> array: return ndarray._new(np.floor(x._array)) @np.errstate(all='ignore') -def floor_divide(x1: array, x2: array, /) -> array: +def floor_divide(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.floor_divide <numpy.floor_divide>`. @@ -299,7 +299,7 @@ def floor_divide(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.floor_divide(x1._array, x2._array)) -def greater(x1: array, x2: array, /) -> array: +def greater(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.greater <numpy.greater>`. @@ -310,7 +310,7 @@ def greater(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.greater(x1._array, x2._array)) -def greater_equal(x1: array, x2: array, /) -> array: +def greater_equal(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.greater_equal <numpy.greater_equal>`. @@ -321,7 +321,7 @@ def greater_equal(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.greater_equal(x1._array, x2._array)) -def isfinite(x: array, /) -> array: +def isfinite(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.isfinite <numpy.isfinite>`. @@ -331,7 +331,7 @@ def isfinite(x: array, /) -> array: raise TypeError('Only numeric dtypes are allowed in isfinite') return ndarray._new(np.isfinite(x._array)) -def isinf(x: array, /) -> array: +def isinf(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.isinf <numpy.isinf>`. @@ -341,7 +341,7 @@ def isinf(x: array, /) -> array: raise TypeError('Only numeric dtypes are allowed in isinf') return ndarray._new(np.isinf(x._array)) -def isnan(x: array, /) -> array: +def isnan(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.isnan <numpy.isnan>`. @@ -351,7 +351,7 @@ def isnan(x: array, /) -> array: raise TypeError('Only numeric dtypes are allowed in isnan') return ndarray._new(np.isnan(x._array)) -def less(x1: array, x2: array, /) -> array: +def less(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.less <numpy.less>`. @@ -362,7 +362,7 @@ def less(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.less(x1._array, x2._array)) -def less_equal(x1: array, x2: array, /) -> array: +def less_equal(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.less_equal <numpy.less_equal>`. @@ -374,7 +374,7 @@ def less_equal(x1: array, x2: array, /) -> array: return ndarray._new(np.less_equal(x1._array, x2._array)) @np.errstate(all='ignore') -def log(x: array, /) -> array: +def log(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.log <numpy.log>`. @@ -385,7 +385,7 @@ def log(x: array, /) -> array: return ndarray._new(np.log(x._array)) @np.errstate(all='ignore') -def log1p(x: array, /) -> array: +def log1p(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.log1p <numpy.log1p>`. @@ -396,7 +396,7 @@ def log1p(x: array, /) -> array: return ndarray._new(np.log1p(x._array)) @np.errstate(all='ignore') -def log2(x: array, /) -> array: +def log2(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.log2 <numpy.log2>`. @@ -407,7 +407,7 @@ def log2(x: array, /) -> array: return ndarray._new(np.log2(x._array)) @np.errstate(all='ignore') -def log10(x: array, /) -> array: +def log10(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.log10 <numpy.log10>`. @@ -417,7 +417,7 @@ def log10(x: array, /) -> array: raise TypeError('Only floating-point dtypes are allowed in log10') return ndarray._new(np.log10(x._array)) -def logaddexp(x1: array, x2: array) -> array: +def logaddexp(x1: Array, x2: Array) -> Array: """ Array API compatible wrapper for :py:func:`np.logaddexp <numpy.logaddexp>`. @@ -428,7 +428,7 @@ def logaddexp(x1: array, x2: array) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.logaddexp(x1._array, x2._array)) -def logical_and(x1: array, x2: array, /) -> array: +def logical_and(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.logical_and <numpy.logical_and>`. @@ -439,7 +439,7 @@ def logical_and(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.logical_and(x1._array, x2._array)) -def logical_not(x: array, /) -> array: +def logical_not(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.logical_not <numpy.logical_not>`. @@ -449,7 +449,7 @@ def logical_not(x: array, /) -> array: raise TypeError('Only boolean dtypes are allowed in logical_not') return ndarray._new(np.logical_not(x._array)) -def logical_or(x1: array, x2: array, /) -> array: +def logical_or(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.logical_or <numpy.logical_or>`. @@ -460,7 +460,7 @@ def logical_or(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.logical_or(x1._array, x2._array)) -def logical_xor(x1: array, x2: array, /) -> array: +def logical_xor(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.logical_xor <numpy.logical_xor>`. @@ -472,7 +472,7 @@ def logical_xor(x1: array, x2: array, /) -> array: return ndarray._new(np.logical_xor(x1._array, x2._array)) @np.errstate(all='ignore') -def multiply(x1: array, x2: array, /) -> array: +def multiply(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.multiply <numpy.multiply>`. @@ -483,7 +483,7 @@ def multiply(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.multiply(x1._array, x2._array)) -def negative(x: array, /) -> array: +def negative(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.negative <numpy.negative>`. @@ -493,7 +493,7 @@ def negative(x: array, /) -> array: raise TypeError('Only numeric dtypes are allowed in negative') return ndarray._new(np.negative(x._array)) -def not_equal(x1: array, x2: array, /) -> array: +def not_equal(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.not_equal <numpy.not_equal>`. @@ -502,7 +502,7 @@ def not_equal(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.not_equal(x1._array, x2._array)) -def positive(x: array, /) -> array: +def positive(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.positive <numpy.positive>`. @@ -514,7 +514,7 @@ def positive(x: array, /) -> array: # Note: the function name is different here @np.errstate(all='ignore') -def pow(x1: array, x2: array, /) -> array: +def pow(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.power <numpy.power>`. @@ -526,7 +526,7 @@ def pow(x1: array, x2: array, /) -> array: return ndarray._new(np.power(x1._array, x2._array)) @np.errstate(all='ignore') -def remainder(x1: array, x2: array, /) -> array: +def remainder(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.remainder <numpy.remainder>`. @@ -537,7 +537,7 @@ def remainder(x1: array, x2: array, /) -> array: x1, x2 = ndarray._normalize_two_args(x1, x2) return ndarray._new(np.remainder(x1._array, x2._array)) -def round(x: array, /) -> array: +def round(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.round <numpy.round>`. @@ -547,7 +547,7 @@ def round(x: array, /) -> array: raise TypeError('Only numeric dtypes are allowed in round') return ndarray._new(np.round(x._array)) -def sign(x: array, /) -> array: +def sign(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.sign <numpy.sign>`. @@ -558,7 +558,7 @@ def sign(x: array, /) -> array: return ndarray._new(np.sign(x._array)) @np.errstate(all='ignore') -def sin(x: array, /) -> array: +def sin(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.sin <numpy.sin>`. @@ -569,7 +569,7 @@ def sin(x: array, /) -> array: return ndarray._new(np.sin(x._array)) @np.errstate(all='ignore') -def sinh(x: array, /) -> array: +def sinh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.sinh <numpy.sinh>`. @@ -580,7 +580,7 @@ def sinh(x: array, /) -> array: return ndarray._new(np.sinh(x._array)) @np.errstate(all='ignore') -def square(x: array, /) -> array: +def square(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.square <numpy.square>`. @@ -591,7 +591,7 @@ def square(x: array, /) -> array: return ndarray._new(np.square(x._array)) @np.errstate(all='ignore') -def sqrt(x: array, /) -> array: +def sqrt(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.sqrt <numpy.sqrt>`. @@ -602,7 +602,7 @@ def sqrt(x: array, /) -> array: return ndarray._new(np.sqrt(x._array)) @np.errstate(all='ignore') -def subtract(x1: array, x2: array, /) -> array: +def subtract(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.subtract <numpy.subtract>`. @@ -614,7 +614,7 @@ def subtract(x1: array, x2: array, /) -> array: return ndarray._new(np.subtract(x1._array, x2._array)) @np.errstate(all='ignore') -def tan(x: array, /) -> array: +def tan(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.tan <numpy.tan>`. @@ -624,7 +624,7 @@ def tan(x: array, /) -> array: raise TypeError('Only floating-point dtypes are allowed in tan') return ndarray._new(np.tan(x._array)) -def tanh(x: array, /) -> array: +def tanh(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.tanh <numpy.tanh>`. @@ -634,7 +634,7 @@ def tanh(x: array, /) -> array: raise TypeError('Only floating-point dtypes are allowed in tanh') return ndarray._new(np.tanh(x._array)) -def trunc(x: array, /) -> array: +def trunc(x: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.trunc <numpy.trunc>`. diff --git a/numpy/_array_api/_linear_algebra_functions.py b/numpy/_array_api/_linear_algebra_functions.py index 461770641..b6b0c6f6e 100644 --- a/numpy/_array_api/_linear_algebra_functions.py +++ b/numpy/_array_api/_linear_algebra_functions.py @@ -5,7 +5,7 @@ from ._dtypes import _numeric_dtypes from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Optional, Sequence, Tuple, Union, array + from ._types import Optional, Sequence, Tuple, Union, Array import numpy as np @@ -19,7 +19,7 @@ import numpy as np # """ # return np.einsum() -def matmul(x1: array, x2: array, /) -> array: +def matmul(x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.matmul <numpy.matmul>`. @@ -33,7 +33,7 @@ def matmul(x1: array, x2: array, /) -> array: return ndarray._new(np.matmul(x1._array, x2._array)) # Note: axes must be a tuple, unlike np.tensordot where it can be an array or array-like. -def tensordot(x1: array, x2: array, /, *, axes: Union[int, Tuple[Sequence[int], Sequence[int]]] = 2) -> array: +def tensordot(x1: Array, x2: Array, /, *, axes: Union[int, Tuple[Sequence[int], Sequence[int]]] = 2) -> Array: # Note: the restriction to numeric dtypes only is different from # np.tensordot. if x1.dtype not in _numeric_dtypes or x2.dtype not in _numeric_dtypes: @@ -41,7 +41,7 @@ def tensordot(x1: array, x2: array, /, *, axes: Union[int, Tuple[Sequence[int], return ndarray._new(np.tensordot(x1._array, x2._array, axes=axes)) -def transpose(x: array, /, *, axes: Optional[Tuple[int, ...]] = None) -> array: +def transpose(x: Array, /, *, axes: Optional[Tuple[int, ...]] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.transpose <numpy.transpose>`. @@ -50,7 +50,7 @@ def transpose(x: array, /, *, axes: Optional[Tuple[int, ...]] = None) -> array: return ndarray._new(np.transpose(x._array, axes=axes)) # Note: vecdot is not in NumPy -def vecdot(x1: array, x2: array, /, *, axis: Optional[int] = None) -> array: +def vecdot(x1: Array, x2: Array, /, *, axis: Optional[int] = None) -> Array: if axis is None: axis = -1 return tensordot(x1, x2, axes=((axis,), (axis,))) diff --git a/numpy/_array_api/_manipulation_functions.py b/numpy/_array_api/_manipulation_functions.py index 5f7b0a451..da02155f9 100644 --- a/numpy/_array_api/_manipulation_functions.py +++ b/numpy/_array_api/_manipulation_functions.py @@ -4,12 +4,12 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Optional, Tuple, Union, array + from ._types import Optional, Tuple, Union, Array import numpy as np # Note: the function name is different here -def concat(arrays: Tuple[array, ...], /, *, axis: Optional[int] = 0) -> array: +def concat(arrays: Tuple[Array, ...], /, *, axis: Optional[int] = 0) -> Array: """ Array API compatible wrapper for :py:func:`np.concatenate <numpy.concatenate>`. @@ -18,7 +18,7 @@ def concat(arrays: Tuple[array, ...], /, *, axis: Optional[int] = 0) -> array: arrays = tuple(a._array for a in arrays) return ndarray._new(np.concatenate(arrays, axis=axis)) -def expand_dims(x: array, /, *, axis: int) -> array: +def expand_dims(x: Array, /, *, axis: int) -> Array: """ Array API compatible wrapper for :py:func:`np.expand_dims <numpy.expand_dims>`. @@ -26,7 +26,7 @@ def expand_dims(x: array, /, *, axis: int) -> array: """ return ndarray._new(np.expand_dims(x._array, axis)) -def flip(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> array: +def flip(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.flip <numpy.flip>`. @@ -34,7 +34,7 @@ def flip(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> """ return ndarray._new(np.flip(x._array, axis=axis)) -def reshape(x: array, /, shape: Tuple[int, ...]) -> array: +def reshape(x: Array, /, shape: Tuple[int, ...]) -> Array: """ Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`. @@ -42,7 +42,7 @@ def reshape(x: array, /, shape: Tuple[int, ...]) -> array: """ return ndarray._new(np.reshape(x._array, shape)) -def roll(x: array, /, shift: Union[int, Tuple[int, ...]], *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> array: +def roll(x: Array, /, shift: Union[int, Tuple[int, ...]], *, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.roll <numpy.roll>`. @@ -50,7 +50,7 @@ def roll(x: array, /, shift: Union[int, Tuple[int, ...]], *, axis: Optional[Unio """ return ndarray._new(np.roll(x._array, shift, axis=axis)) -def squeeze(x: array, /, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> array: +def squeeze(x: Array, /, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> Array: """ Array API compatible wrapper for :py:func:`np.squeeze <numpy.squeeze>`. @@ -58,7 +58,7 @@ def squeeze(x: array, /, axis: Optional[Union[int, Tuple[int, ...]]] = None) -> """ return ndarray._new(np.squeeze(x._array, axis=axis)) -def stack(arrays: Tuple[array, ...], /, *, axis: int = 0) -> array: +def stack(arrays: Tuple[Array, ...], /, *, axis: int = 0) -> Array: """ Array API compatible wrapper for :py:func:`np.stack <numpy.stack>`. diff --git a/numpy/_array_api/_searching_functions.py b/numpy/_array_api/_searching_functions.py index 9a5d583bc..690256430 100644 --- a/numpy/_array_api/_searching_functions.py +++ b/numpy/_array_api/_searching_functions.py @@ -4,11 +4,11 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Tuple, array + from ._types import Tuple, Array import numpy as np -def argmax(x: array, /, *, axis: int = None, keepdims: bool = False) -> array: +def argmax(x: Array, /, *, axis: int = None, keepdims: bool = False) -> Array: """ Array API compatible wrapper for :py:func:`np.argmax <numpy.argmax>`. @@ -17,7 +17,7 @@ def argmax(x: array, /, *, axis: int = None, keepdims: bool = False) -> array: # Note: this currently fails as np.argmax does not implement keepdims return ndarray._new(np.asarray(np.argmax(x._array, axis=axis, keepdims=keepdims))) -def argmin(x: array, /, *, axis: int = None, keepdims: bool = False) -> array: +def argmin(x: Array, /, *, axis: int = None, keepdims: bool = False) -> Array: """ Array API compatible wrapper for :py:func:`np.argmin <numpy.argmin>`. @@ -26,7 +26,7 @@ def argmin(x: array, /, *, axis: int = None, keepdims: bool = False) -> array: # Note: this currently fails as np.argmin does not implement keepdims return ndarray._new(np.asarray(np.argmin(x._array, axis=axis, keepdims=keepdims))) -def nonzero(x: array, /) -> Tuple[array, ...]: +def nonzero(x: Array, /) -> Tuple[Array, ...]: """ Array API compatible wrapper for :py:func:`np.nonzero <numpy.nonzero>`. @@ -34,7 +34,7 @@ def nonzero(x: array, /) -> Tuple[array, ...]: """ return ndarray._new(np.nonzero(x._array)) -def where(condition: array, x1: array, x2: array, /) -> array: +def where(condition: Array, x1: Array, x2: Array, /) -> Array: """ Array API compatible wrapper for :py:func:`np.where <numpy.where>`. diff --git a/numpy/_array_api/_set_functions.py b/numpy/_array_api/_set_functions.py index 025a27d80..719d54e5f 100644 --- a/numpy/_array_api/_set_functions.py +++ b/numpy/_array_api/_set_functions.py @@ -4,11 +4,11 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Tuple, Union, array + 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) -> 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>`. diff --git a/numpy/_array_api/_sorting_functions.py b/numpy/_array_api/_sorting_functions.py index 6e87bd90e..3dc0ec444 100644 --- a/numpy/_array_api/_sorting_functions.py +++ b/numpy/_array_api/_sorting_functions.py @@ -4,11 +4,11 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import array + from ._types import Array import numpy as np -def argsort(x: array, /, *, axis: int = -1, descending: bool = False, stable: bool = True) -> array: +def argsort(x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True) -> Array: """ Array API compatible wrapper for :py:func:`np.argsort <numpy.argsort>`. @@ -21,7 +21,7 @@ def argsort(x: array, /, *, axis: int = -1, descending: bool = False, stable: bo res = np.flip(res, axis=axis) return ndarray._new(res) -def sort(x: array, /, *, axis: int = -1, descending: bool = False, stable: bool = True) -> array: +def sort(x: Array, /, *, axis: int = -1, descending: bool = False, stable: bool = True) -> Array: """ Array API compatible wrapper for :py:func:`np.sort <numpy.sort>`. diff --git a/numpy/_array_api/_statistical_functions.py b/numpy/_array_api/_statistical_functions.py index 26afd7354..e6a791fe6 100644 --- a/numpy/_array_api/_statistical_functions.py +++ b/numpy/_array_api/_statistical_functions.py @@ -4,29 +4,29 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Optional, Tuple, Union, array + from ._types import Optional, Tuple, Union, Array import numpy as np -def max(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def max(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: return ndarray._new(np.max(x._array, axis=axis, keepdims=keepdims)) -def mean(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def mean(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: return ndarray._new(np.asarray(np.mean(x._array, axis=axis, keepdims=keepdims))) -def min(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def min(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: return ndarray._new(np.min(x._array, axis=axis, keepdims=keepdims)) -def prod(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def prod(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: return ndarray._new(np.asarray(np.prod(x._array, axis=axis, keepdims=keepdims))) -def std(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False) -> array: +def std(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False) -> Array: # Note: the keyword argument correction is different here return ndarray._new(np.asarray(np.std(x._array, axis=axis, ddof=correction, keepdims=keepdims))) -def sum(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def sum(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: return ndarray._new(np.asarray(np.sum(x._array, axis=axis, keepdims=keepdims))) -def var(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False) -> array: +def var(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, correction: Union[int, float] = 0.0, keepdims: bool = False) -> Array: # Note: the keyword argument correction is different here return ndarray._new(np.asarray(np.var(x._array, axis=axis, ddof=correction, keepdims=keepdims))) diff --git a/numpy/_array_api/_types.py b/numpy/_array_api/_types.py index 1086699fc..602c1df3e 100644 --- a/numpy/_array_api/_types.py +++ b/numpy/_array_api/_types.py @@ -6,8 +6,8 @@ annotations in the function signatures. The functions in the module are only valid for inputs that match the given type annotations. """ -__all__ = ['Any', 'List', 'Literal', 'Optional', 'Tuple', 'Union', 'array', - 'device', 'dtype', 'SupportsDLPack', 'SupportsBufferProtocol', +__all__ = ['Any', 'List', 'Literal', 'Optional', 'Tuple', 'Union', 'Array', + 'Device', 'Dtype', 'SupportsDLPack', 'SupportsBufferProtocol', 'PyCapsule'] from typing import Any, List, Literal, Optional, Tuple, Union, TypeVar @@ -15,9 +15,9 @@ from typing import Any, List, Literal, Optional, Tuple, Union, TypeVar from . import (ndarray, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64) -array = ndarray -device = TypeVar('device') -dtype = Literal[int8, int16, int32, int64, uint8, uint16, +Array = ndarray +Device = TypeVar('device') +Dtype = Literal[int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64] SupportsDLPack = TypeVar('SupportsDLPack') SupportsBufferProtocol = TypeVar('SupportsBufferProtocol') diff --git a/numpy/_array_api/_utility_functions.py b/numpy/_array_api/_utility_functions.py index e280b5785..a6a7721dd 100644 --- a/numpy/_array_api/_utility_functions.py +++ b/numpy/_array_api/_utility_functions.py @@ -4,11 +4,11 @@ from ._array_object import ndarray from typing import TYPE_CHECKING if TYPE_CHECKING: - from ._types import Optional, Tuple, Union, array + from ._types import Optional, Tuple, Union, Array import numpy as np -def all(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def all(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: """ Array API compatible wrapper for :py:func:`np.all <numpy.all>`. @@ -16,7 +16,7 @@ def all(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keep """ return ndarray._new(np.asarray(np.all(x._array, axis=axis, keepdims=keepdims))) -def any(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> array: +def any(x: Array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False) -> Array: """ Array API compatible wrapper for :py:func:`np.any <numpy.any>`. |