class Array:
n-d array object for the array API namespace.
See the docstring of np.ndarray
for more
information.
This is a wrapper around numpy.ndarray that restricts the usage to only those things that are required by the array API namespace. Note, attributes on this object that start with a single underscore are not part of the API specification and should only be used internally. This object should not be constructed directly. Rather, use one of the creation functions, such as asarray().
Class Method | _new |
This is a private method for initializing the array API Array object. |
Static Method | _normalize_two_args |
Normalize inputs to two arg functions to fix type promotion rules |
Static Method | _validate_index |
Validate an index according to the array API. |
Method | __abs__ |
Performs the operation __abs__. |
Method | __add__ |
Performs the operation __add__. |
Method | __and__ |
Performs the operation __and__. |
Method | __array__ |
Warning: this method is NOT part of the array API spec. Implementers of other libraries need not include it, and users should not assume it will be present in other implementations. |
Method | __array_namespace__ |
Undocumented |
Method | __bool__ |
Performs the operation __bool__. |
Method | __dlpack__ |
Performs the operation __dlpack__. |
Method | __dlpack_device__ |
Performs the operation __dlpack_device__. |
Method | __eq__ |
Performs the operation __eq__. |
Method | __float__ |
Performs the operation __float__. |
Method | __floordiv__ |
Performs the operation __floordiv__. |
Method | __ge__ |
Performs the operation __ge__. |
Method | __getitem__ |
Performs the operation __getitem__. |
Method | __gt__ |
Performs the operation __gt__. |
Method | __iadd__ |
Performs the operation __iadd__. |
Method | __iand__ |
Performs the operation __iand__. |
Method | __ifloordiv__ |
Performs the operation __ifloordiv__. |
Method | __ilshift__ |
Performs the operation __ilshift__. |
Method | __imatmul__ |
Performs the operation __imatmul__. |
Method | __imod__ |
Performs the operation __imod__. |
Method | __imul__ |
Performs the operation __imul__. |
Method | __index__ |
Performs the operation __index__. |
Method | __int__ |
Performs the operation __int__. |
Method | __invert__ |
Performs the operation __invert__. |
Method | __ior__ |
Performs the operation __ior__. |
Method | __ipow__ |
Performs the operation __ipow__. |
Method | __irshift__ |
Performs the operation __irshift__. |
Method | __isub__ |
Performs the operation __isub__. |
Method | __itruediv__ |
Performs the operation __itruediv__. |
Method | __ixor__ |
Performs the operation __ixor__. |
Method | __le__ |
Performs the operation __le__. |
Method | __lshift__ |
Performs the operation __lshift__. |
Method | __lt__ |
Performs the operation __lt__. |
Method | __matmul__ |
Performs the operation __matmul__. |
Method | __mod__ |
Performs the operation __mod__. |
Method | __mul__ |
Performs the operation __mul__. |
Method | __ne__ |
Performs the operation __ne__. |
Method | __neg__ |
Performs the operation __neg__. |
Method | __new__ |
Undocumented |
Method | __or__ |
Performs the operation __or__. |
Method | __pos__ |
Performs the operation __pos__. |
Method | __pow__ |
Performs the operation __pow__. |
Method | __radd__ |
Performs the operation __radd__. |
Method | __rand__ |
Performs the operation __rand__. |
Method | __repr__ |
Performs the operation __repr__. |
Method | __rfloordiv__ |
Performs the operation __rfloordiv__. |
Method | __rlshift__ |
Performs the operation __rlshift__. |
Method | __rmatmul__ |
Performs the operation __rmatmul__. |
Method | __rmod__ |
Performs the operation __rmod__. |
Method | __rmul__ |
Performs the operation __rmul__. |
Method | __ror__ |
Performs the operation __ror__. |
Method | __rpow__ |
Performs the operation __rpow__. |
Method | __rrshift__ |
Performs the operation __rrshift__. |
Method | __rshift__ |
Performs the operation __rshift__. |
Method | __rsub__ |
Performs the operation __rsub__. |
Method | __rtruediv__ |
Performs the operation __rtruediv__. |
Method | __rxor__ |
Performs the operation __rxor__. |
Method | __setitem__ |
Performs the operation __setitem__. |
Method | __str__ |
Performs the operation __str__. |
Method | __sub__ |
Performs the operation __sub__. |
Method | __truediv__ |
Performs the operation __truediv__. |
Method | __xor__ |
Performs the operation __xor__. |
Method | _check_allowed_dtypes |
Helper function for operators to only allow specific input dtypes |
Method | _promote_scalar |
Returns a promoted version of a Python scalar appropriate for use with operations on self. |
Method | to_device |
Undocumented |
Property | device |
Undocumented |
Property | dtype |
Array API compatible wrapper for np.ndarray.dtype . |
Property | mT |
Undocumented |
Property | ndim |
Array API compatible wrapper for np.ndarray.ndim . |
Property | shape |
Array API compatible wrapper for np.ndarray.shape . |
Property | size |
Array API compatible wrapper for np.ndarray.size . |
Property | T |
Array API compatible wrapper for np.ndarray.T . |
This is a private method for initializing the array API Array object.
Functions outside of the array_api submodule should not use this method. Use one of the creation functions instead, such as asarray.
Normalize inputs to two arg functions to fix type promotion rules
NumPy deviates from the spec type promotion rules in cases where one argument is 0-dimensional and the other is not. For example:
>>> import numpy as np >>> a = np.array([1.0], dtype=np.float32) >>> b = np.array(1.0, dtype=np.float64) >>> np.add(a, b) # The spec says this should be float64 array([2.], dtype=float32)
To fix this, we add a dimension to the 0-dimension array before passing it through. This works because a dimension would be added anyway from broadcasting, so the resulting shape is the same, but this prevents NumPy from not promoting the dtype.
Validate an index according to the array API.
The array API specification only requires a subset of indices that are supported by NumPy. This function will reject any index that is allowed by NumPy but not required by the array API specification. We always raise IndexError on such indices (the spec does not require any specific behavior on them, but this makes the NumPy array API namespace a minimal implementation of the spec). See https://data-apis.org/array-api/latest/API_specification/indexing.html for the full list of required indexing behavior
This function either raises IndexError if the index key is invalid, or a new key to be used in place of key in indexing. It only raises IndexError on indices that are not already rejected by NumPy, as NumPy will already raise the appropriate error on such indices. shape may be None, in which case, only cases that are independent of the array shape are checked.
The following cases are allowed by NumPy, but not specified by the array API specification:
Additionally, it should be noted that indices that would return a scalar in NumPy will return a 0-D array. Array scalars are not allowed in the specification, only 0-D arrays. This is done in the Array._new constructor, not this function.
Parameters | |
dtype:None|np.dtype[ | Undocumented |
Returns | |
npt.NDArray[ | Undocumented |
Undocumented
Parameters | |
api_version:Optional[ | Undocumented |
Returns | |
types.ModuleType | Undocumented |
Parameters | |
stream:None | Undocumented |
Returns | |
PyCapsule | Undocumented |
Returns | |
Tuple[ | Undocumented |
Helper function for operators to only allow specific input dtypes
Use like
other = self._check_allowed_dtypes(other, 'numeric', '__add__') if other is NotImplemented:
return other
Returns a promoted version of a Python scalar appropriate for use with operations on self.
This may raise an OverflowError in cases where the scalar is an integer that is too large to fit in a NumPy integer dtype, or TypeError when the scalar type is incompatible with the dtype of self.
int
=
Array API compatible wrapper for np.ndarray.ndim
.
See its docstring for more information.
Tuple[ int, ...]
=
Array API compatible wrapper for np.ndarray.shape
.
See its docstring for more information.
int
=
Array API compatible wrapper for np.ndarray.size
.
See its docstring for more information.