heat.array_api._array_object
Module Contents
- class Array
DNDarray object for the array API namespace. This is a wrapper around
heat.DNDarraythat 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 asasarray.- _array :heat.DNDarray
- _new(x, /)[source]
Initializes 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.- Parameters:
x (DNDarray) – Underlying
DNDarray
- _check_allowed_dtypes(other: bool | int | float | Array, dtype_category: str, op: str) Array[source]
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
- _promote_scalar(scalar)[source]
Returns a promoted version of a Python scalar appropriate for use with operations on self. This may raise a
TypeErrorwhen the scalar type is incompatible with the dtype of self.
- _normalize_two_args(x1, x2) Tuple[Array, Array][source]
Normalize inputs to two arg functions to fix type promotion rules Heat deviates from the spec type promotion rules in cases where one argument is 0-dimensional and the other is not. For example: >>> import heat as ht >>> a = ht.array([1.0], dtype=ht.float32) >>> b = ht.array(1.0, dtype=ht.float64) >>> ht.add(a, b) # The spec says this should be float64 DNDarray([2.], dtype=ht.float32, device=cpu:0, split=None) 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 Heat from not promoting the dtype.
- _validate_index(key)[source]
Validate an index according to the array API. The array API specification only requires a subset of indices that are supported by Heat. This function will reject any index that is allowed by Heat but not required by the array API specification. This function raises IndexError if the index
keyis invalid.
- __abs__(/) Array[source]
Calculates the absolute value for each element of an array instance (i.e., the element-wise result has the same magnitude as the respective element but has positive sign).
- __add__(other: int | float | Array, /) Array[source]
Calculates the sum for each element of an array instance with the respective element of the array
other.- Parameters:
other (Union[int, float, Array]) – Addend array. Must have a numeric data type.
- __and__(other: int | bool | Array, /) Array[source]
Evaluates
self_i & other_ifor each element of an array instance with the respective element of the arrayother.
- __array_namespace__(/, *, api_version: str | None = None) Any[source]
Returns an object that has all the array API functions on it.
- Parameters:
api_version (Optional[str]) – string representing the version of the array API specification to be returned, in
'YYYY.MM'form. If it isNone(default), it returns the namespace corresponding to latest version of the array API specification.
- __dlpack__(/, *, stream: Optional[Union[int, Any]]=None) heat.array_api._typing.PyCapsule[source]
Exports the array for consumption by
from_dlpack()as a DLPack capsule.- Parameters:
stream (Optional[Union[int, Any]]) – For CUDA and ROCm, a Python integer representing a pointer to a stream, on devices that support streams.
- __dlpack_device__(/) Tuple[enum.Enum, int][source]
Returns device type and device ID in DLPack format. Meant for use within
from_dlpack().
- __eq__(other: int | float | bool | Array, /) Array[source]
Computes the truth value of
self_i == other_ifor each element of an array instance with the respective element of the arrayother.
- __float__(/) float[source]
Converts a zero-dimensional floating-point array to a Python
floatobject.
- __floordiv__(other: int | float | Array, /) Array[source]
Evaluates
self_i // other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __ge__(other: int | float | Array, /) Array[source]
Computes the truth value of
self_i >= other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __getitem__(key: int | slice | ellipsis | Tuple[int | slice | ellipsis, Ellipsis] | Array, /) Array[source]
Returns
self[key].- Parameters:
key (Union[int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array]) – Index key
- __gt__(other: int | float | Array, /) Array[source]
Computes the truth value of
self_i > other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __le__(other: int | float | Array, /) Array[source]
Computes the truth value of
self_i <= other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __lshift__(other: int | Array, /) Array[source]
Evaluates
self_i << other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, Array]) – Other array. Must have an integer data type. Each element must be greater than or equal to
0.
- __lt__(other: int | float | Array, /) Array[source]
Computes the truth value of
self_i < other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, Array]) – Other array. Must have a numeric data type.
- __matmul__(other: Array, /) Array[source]
Computes the matrix product.
- Parameters:
other (Array) – Other array. Must have a numeric data type and at least one dimension.
- __mod__(other: int | float | Array, /) Array[source]
Evaluates
self_i % other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __mul__(other: int | float | Array, /) Array[source]
Calculates the product for each element of an array instance with the respective element of the array
other.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __ne__(other: int | float | bool | Array, /) Array[source]
Computes the truth value of
self_i != other_ifor each element of an array instance with the respective element of the arrayother.
- __or__(other: int | bool | Array, /) Array[source]
Evaluates
self_i | other_ifor each element of an array instance with the respective element of the arrayother.
- __pow__(other: int | float | Array, /) Array[source]
Calculates an approximation of exponentiation by raising each element (the base) of an array instance to the power of
other_i(the exponent), whereother_iis the corresponding element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __rshift__(other: int | Array, /) Array[source]
Evaluates
self_i >> other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, Array]) – Other array. Must have an integer data type. Each element must be greater than or equal to
0.
- __setitem__(key: int | slice | ellipsis | Tuple[int | slice | ellipsis, Ellipsis] | Array, value: int | float | bool | Array, /) None[source]
Sets
self[key]tovalue.
- __sub__(other: int | float | Array, /) Array[source]
Calculates the difference for each element of an array instance with the respective element of the array
other.- Parameters:
other (Union[int, float, Array]) – Subtrahend array. Must have a numeric data type.
- __truediv__(other: int | float | Array, /) Array[source]
Evaluates
self_i / other_ifor each element of an array instance with the respective element of the arrayother.- Parameters:
other (Union[int, float, Array]) – Subtrahend array. Must have a numeric data type.
- __xor__(other: int | bool | Array, /) Array[source]
Evaluates
self_i ^ other_ifor each element of an array instance with the respective element of the arrayother.
- __radd__(other: int | float | Array, /) Array[source]
Reflected version of
__add__.- Parameters:
other (Union[int, float, Array]) – Addend array. Must have a numeric data type.
- __rfloordiv__(other: int | float | Array, /) Array[source]
Reflected version of
__floordiv__.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __rmul__(other: int | float | Array, /) Array[source]
Reflected version of
__mul__.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __rpow__(other: int | float | Array, /) Array[source]
Reflected version of
__rpow__.- Parameters:
other (Union[int, float, Array]) – Other array. Must have a numeric data type.
- __rsub__(other: int | float | Array, /) Array[source]
Reflected version of
__sub__.- Parameters:
other (Union[int, float, Array]) – Subtrahend array. Must have a numeric data type.
- __rtruediv__(other: float | Array, /) Array[source]
Reflected version of
__truediv__.- Parameters:
other (Union[int, float, Array]) – Subtrahend array. Must have a numeric data type.
- to_device(device: heat.array_api._typing.Device, /, stream: int | Any | None = None) Array[source]
Copy the array from the device on which it currently resides to the specified
device.- Parameters:
device (Device) – A
Deviceobject.stream (Optional[Union[int, Any]]) – Stream object to use during copy.