heat.array_api._creation_functions

Module Contents

arange(start: int | float, /, stop: int | float | None = None, step: int | float = 1, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns evenly spaced values within the half-open interval [start, stop) as a one-dimensional array.

Parameters:
  • start (Union[int, float]) – If stop is specified, the start of interval (inclusive); otherwise, the end of the interval (exclusive). If stop is not specified, the default starting value is 0.

  • stop (Optional[Union[int, float]]) – The end of the interval. Default: None.

  • step (Union[int, float]) – the distance between two adjacent elements (out[i+1] - out[i]). Must not be 0; may be negative, this results in an empty array if stop >= start. Default: 1.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from start, stop and step.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

asarray(obj: heat.array_api._array_object.Array | bool | int | float | heat.array_api._typing.NestedSequence[bool | int | float] | heat.array_api._typing.SupportsBufferProtocol, /, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None, copy: bool | None = None) heat.array_api._array_object.Array[source]

Convert the input to an array.

Parameters:
  • obj (Union[Array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]) – Object to be converted to an array. May be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting the Python buffer protocol. Default: None.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from the data type(s) in obj.

  • device (Optional[Device]) – Device on which to place the created array. If device is None and x is an array, the output array device is inferred from x. Default: None.

  • copy (Optional[bool]) – Boolean indicating whether or not to copy the input.

empty(shape: int | Tuple[int, Ellipsis], *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns an uninitialized array having a specified shape.

Parameters:
  • shape (Union[int, Tuple[int, ...]]) – Output array shape.

  • dtype (Optional[Dtype]) – Output array data type. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

empty_like(x: heat.array_api._array_object.Array, /, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns an uninitialized array with the same shape as an input array x.

Parameters:
  • x (Array) – Input array from which to derive the output array shape.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from x. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

eye(n_rows: int, n_cols: int | None = None, /, *, k: int = 0, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a two-dimensional array with ones on the k h diagonal and zeros elsewhere.

Parameters:
  • n_rows (int) – Number of rows in the output array.

  • n_cols (Optional[int]) – Number of columns in the output array. If None, the default number of columns in the output array is equal to n_rows. Default: None.

  • k (int) – Index of the diagonal. A positive value refers to an upper diagonal, a negative value to a lower diagonal, and 0 to the main diagonal. Default: 0.

  • dtype (Optional[Dtype]) – Output array data type. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

from_dlpack(x: object, /) heat.array_api._array_object.Array[source]

Returns a new array containing the data from another (array) object with a __dlpack__ method.

Parameters:

x (object) – Input (array) object.

full(shape: int | Tuple[int, Ellipsis], fill_value: int | float, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array having a specified shape and filled with fill_value.

Parameters:
  • shape (Union[int, Tuple[int, ...]]) – Output array shape.

  • fill_value (Union[int, float]) – Fill value.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from fill_value. Default: None.

  • device (Optional[Device]) – Device on which to place the created array.

full_like(x: heat.array_api._array_object.Array, /, fill_value: int | float, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array filled with fill_value and having the same shape as an input array x.

Parameters:
  • x (Array) – Input array from which to derive the output array shape.

  • fill_value (Union[int, float]) – Fill value.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from x. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

linspace(start: int | float, stop: int | float, /, num: int, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None, endpoint: bool = True) heat.array_api._array_object.Array[source]

Returns evenly spaced numbers over a specified interval.

Parameters:
  • start (Union[int, float]) – The start of the interval.

  • stop (Union[int, float]) – The end of the interval.

  • num (int) – Number of samples.

  • dtype (Optional[Dtype]) – Output array data type. Must be a floating-point data type. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

  • endpoint (bool) – Boolean indicating whether to include stop in the interval. Default: True.

meshgrid(*arrays: heat.array_api._array_object.Array, indexing: str = 'xy') List[heat.array_api._array_object.Array][source]

Returns coordinate matrices from coordinate vectors.

Parameters:
  • arrays (Array) – An arbitrary number of one-dimensional arrays representing grid coordinates. Each array must have the same numeric data type.

  • indexing (str) – Cartesian 'xy' or matrix 'ij' indexing of output. If provided zero or one one-dimensional vector(s) (i.e., the zero- and one-dimensional cases, respectively), the indexing keyword has no effect and is ignored. Default: 'xy'.

ones(shape: int | Tuple[int, Ellipsis], *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array having a specified shape and filled with ones.

Parameters:
  • shape (Union[int, Tuple[int, ...]]) – Output array shape.

  • dtype (Optional[Dtype]) – Output array data type. Default: None.

  • device (Optional[Device]) – Device on which to place the created array.

ones_like(x: heat.array_api._array_object.Array, /, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array filled with ones and having the same shape as an input array x.

Parameters:
  • x (Array) – Input array from which to derive the output array shape.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from x. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.

tril(x: heat.array_api._array_object.Array, /, *, k: int = 0) heat.array_api._array_object.Array[source]

Returns the lower triangular part of a matrix (or a stack of matrices) x.

Parameters:
  • x (Array) – Input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices.

  • k (int) – Diagonal above which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default: 0.

triu(x: heat.array_api._array_object.Array, /, *, k: int = 0) heat.array_api._array_object.Array[source]

Returns the upper triangular part of a matrix (or a stack of matrices) x.

Parameters:
  • x (Array) – Input array having shape (..., M, N) and whose innermost two dimensions form MxN matrices.

  • k (int) – Diagonal below which to zero elements. If k = 0, the diagonal is the main diagonal. If k < 0, the diagonal is below the main diagonal. If k > 0, the diagonal is above the main diagonal. Default: 0.

zeros(shape: int | Tuple[int, Ellipsis], *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array having a specified shape and filled with zeros.

Parameters:
  • shape (Union[int, Tuple[int, ...]]) – Output array shape.

  • dtype (Optional[Dtype]) – Output array data type. Default: None.

  • device (Optional[Device]) – Device on which to place the created array.

zeros_like(x: heat.array_api._array_object.Array, /, *, dtype: heat.array_api._typing.Dtype | None = None, device: heat.array_api._typing.Device | None = None) heat.array_api._array_object.Array[source]

Returns a new array filled with zeros and having the same shape as an input array x.

Parameters:
  • x (Array) – Input array from which to derive the output array shape.

  • dtype (Optional[Dtype]) – Output array data type. If dtype is None, the output array data type is inferred from x. Default: None.

  • device (Optional[Device]) – Device on which to place the created array. Default: None.