summaryrefslogtreecommitdiff
path: root/numpy/_array_api/_array_object.py
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-07-15 16:40:44 -0600
committerAaron Meurer <asmeurer@gmail.com>2021-07-15 16:40:44 -0600
commit6855a8ad71a5041d9a2804910f011ac09a859a48 (patch)
treeaf4acdd822721f34b92b664e8b1e2fa90345c129 /numpy/_array_api/_array_object.py
parentc5580134c71b68c0bd24104a6393e3cea9cb25ce (diff)
downloadnumpy-6855a8ad71a5041d9a2804910f011ac09a859a48.tar.gz
Move _validate_index above the methods that are actually part of the spec
Diffstat (limited to 'numpy/_array_api/_array_object.py')
-rw-r--r--numpy/_array_api/_array_object.py204
1 files changed, 102 insertions, 102 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py
index e523acd2d..99f0e5221 100644
--- a/numpy/_array_api/_array_object.py
+++ b/numpy/_array_api/_array_object.py
@@ -146,108 +146,6 @@ class Array:
x2 = Array._new(x2._array[None])
return (x1, x2)
- # Everything below this line is required by the spec.
-
- def __abs__(self: Array, /) -> Array:
- """
- Performs the operation __abs__.
- """
- res = self._array.__abs__()
- return self.__class__._new(res)
-
- @np.errstate(all='ignore')
- def __add__(self: Array, other: Union[int, float, Array], /) -> Array:
- """
- Performs the operation __add__.
- """
- if isinstance(other, (int, float, bool)):
- other = self._promote_scalar(other)
- self, other = self._normalize_two_args(self, other)
- res = self._array.__add__(other._array)
- return self.__class__._new(res)
-
- def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
- """
- Performs the operation __and__.
- """
- if isinstance(other, (int, float, bool)):
- other = self._promote_scalar(other)
- self, other = self._normalize_two_args(self, other)
- res = self._array.__and__(other._array)
- return self.__class__._new(res)
-
- 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:
- """
- Performs the operation __bool__.
- """
- # Note: This is an error here.
- if self._array.ndim != 0:
- raise TypeError("bool is only allowed on arrays with 0 dimensions")
- res = self._array.__bool__()
- return res
-
- 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]:
- """
- Performs the operation __dlpack_device__.
- """
- # Note: device support is required for this
- res = self._array.__dlpack_device__()
- return self.__class__._new(res)
-
- def __eq__(self: Array, other: Union[int, float, bool, Array], /) -> Array:
- """
- Performs the operation __eq__.
- """
- if isinstance(other, (int, float, bool)):
- other = self._promote_scalar(other)
- self, other = self._normalize_two_args(self, other)
- res = self._array.__eq__(other._array)
- return self.__class__._new(res)
-
- def __float__(self: Array, /) -> float:
- """
- Performs the operation __float__.
- """
- # Note: This is an error here.
- if self._array.ndim != 0:
- raise TypeError("float is only allowed on arrays with 0 dimensions")
- res = self._array.__float__()
- return res
-
- @np.errstate(all='ignore')
- def __floordiv__(self: Array, other: Union[int, float, Array], /) -> Array:
- """
- Performs the operation __floordiv__.
- """
- if isinstance(other, (int, float, bool)):
- other = self._promote_scalar(other)
- self, other = self._normalize_two_args(self, other)
- res = self._array.__floordiv__(other._array)
- return self.__class__._new(res)
-
- def __ge__(self: Array, other: Union[int, float, Array], /) -> Array:
- """
- Performs the operation __ge__.
- """
- if isinstance(other, (int, float, bool)):
- other = self._promote_scalar(other)
- self, other = self._normalize_two_args(self, other)
- res = self._array.__ge__(other._array)
- return self.__class__._new(res)
-
# Note: A large fraction of allowed indices are disallowed here (see the
# docstring below)
@staticmethod
@@ -357,6 +255,108 @@ class Array:
# Array() form, like a list of booleans.
raise IndexError("Only integers, slices (`:`), ellipsis (`...`), and boolean arrays are valid indices in the array API namespace")
+ # Everything below this line is required by the spec.
+
+ def __abs__(self: Array, /) -> Array:
+ """
+ Performs the operation __abs__.
+ """
+ res = self._array.__abs__()
+ return self.__class__._new(res)
+
+ @np.errstate(all='ignore')
+ def __add__(self: Array, other: Union[int, float, Array], /) -> Array:
+ """
+ Performs the operation __add__.
+ """
+ if isinstance(other, (int, float, bool)):
+ other = self._promote_scalar(other)
+ self, other = self._normalize_two_args(self, other)
+ res = self._array.__add__(other._array)
+ return self.__class__._new(res)
+
+ def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
+ """
+ Performs the operation __and__.
+ """
+ if isinstance(other, (int, float, bool)):
+ other = self._promote_scalar(other)
+ self, other = self._normalize_two_args(self, other)
+ res = self._array.__and__(other._array)
+ return self.__class__._new(res)
+
+ 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:
+ """
+ Performs the operation __bool__.
+ """
+ # Note: This is an error here.
+ if self._array.ndim != 0:
+ raise TypeError("bool is only allowed on arrays with 0 dimensions")
+ res = self._array.__bool__()
+ return res
+
+ 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]:
+ """
+ Performs the operation __dlpack_device__.
+ """
+ # Note: device support is required for this
+ res = self._array.__dlpack_device__()
+ return self.__class__._new(res)
+
+ def __eq__(self: Array, other: Union[int, float, bool, Array], /) -> Array:
+ """
+ Performs the operation __eq__.
+ """
+ if isinstance(other, (int, float, bool)):
+ other = self._promote_scalar(other)
+ self, other = self._normalize_two_args(self, other)
+ res = self._array.__eq__(other._array)
+ return self.__class__._new(res)
+
+ def __float__(self: Array, /) -> float:
+ """
+ Performs the operation __float__.
+ """
+ # Note: This is an error here.
+ if self._array.ndim != 0:
+ raise TypeError("float is only allowed on arrays with 0 dimensions")
+ res = self._array.__float__()
+ return res
+
+ @np.errstate(all='ignore')
+ def __floordiv__(self: Array, other: Union[int, float, Array], /) -> Array:
+ """
+ Performs the operation __floordiv__.
+ """
+ if isinstance(other, (int, float, bool)):
+ other = self._promote_scalar(other)
+ self, other = self._normalize_two_args(self, other)
+ res = self._array.__floordiv__(other._array)
+ return self.__class__._new(res)
+
+ def __ge__(self: Array, other: Union[int, float, Array], /) -> Array:
+ """
+ Performs the operation __ge__.
+ """
+ if isinstance(other, (int, float, bool)):
+ other = self._promote_scalar(other)
+ self, other = self._normalize_two_args(self, other)
+ res = self._array.__ge__(other._array)
+ return self.__class__._new(res)
+
def __getitem__(self: Array, key: Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array], /) -> Array:
"""
Performs the operation __getitem__.