returnn.frontend._numpy_backend

Allow to use Numpy arrays. This backend will probably never be feature-complete. It just has the bare minimum such that the user can assign Numpy arrays to Tensor.raw_tensor.

class returnn.frontend._numpy_backend.NumpyBackend[source]

Numpy backend

name: str | None = 'numpy'[source]
RawTensorType[source]

alias of ndarray

static executing_eagerly() bool[source]

executing eagerly

static get_dtype_name_raw(raw_tensor: ndarray) str[source]
Returns:

dtype of raw tensor, as string. e.g. “int64” etc.

static as_dtype_raw(dtype_name: str) dtype[source]
Parameters:

dtype_name – e.g. “float32”

Returns:

dtype object

static get_ndim_raw(raw_tensor: ndarray) int[source]
Returns:

ndim of raw tensor. assumes it is known

static get_shape_raw(raw_tensor: ndarray) Tuple[int][source]
Returns:

shape of raw tensor

static get_shape_tuple_raw(raw_tensor: ndarray) Tuple[int][source]
Returns:

shape of raw tensor. assumes that ndim is known. In eager frameworks, all dims are int.

static get_known_shape_raw(raw_tensor: ndarray) Tuple[int][source]
Returns:

shape of raw tensor, int for static known, None otherwise. assumes that ndim is known. This will not create any ops. In eager frameworks, all dims are known.

static expand_dims_raw(raw_tensor: ndarray, axis: int) ndarray[source]
Parameters:
  • raw_tensor

  • axis – e.g. 1

Returns:

raw tensor with new axis

static transpose_raw(raw_tensor: ndarray, perm: Sequence[int]) ndarray[source]
Parameters:
  • raw_tensor

  • perm – e.g. [0, 2, 1]

Returns:

permuted (transposed) raw tensor

static reshape_raw(raw_tensor: ndarray, shape: Sequence[int | ndarray] | ndarray) ndarray[source]

reshape raw

static compare_raw(a: ndarray, kind: str, b: ndarray) ndarray[source]
Parameters:
  • a

  • kind – “equal”, “less”, “less_equal”, “greater”, “greater_equal”, “not_equal”

  • b

Returns:

a kind b

static combine_raw(a: ndarray, kind: str, b: ndarray) ndarray[source]
Parameters:
  • a

  • kind – “add”, “sub”, “mul”, “truediv”, “floordiv”, “mod”, “pow”, “maximum”, “minimum”, “logical_and”, “logical_or”, “squared_difference”

  • b

Returns:

a kind b

static range_over_dim(dim: Dim, *, dtype: str | None = None, device: str | None = None) Tensor[ndarray][source]
Parameters:
  • dim

  • dtype

  • device

Returns:

tensor with shape [dim]

static reduce(source: Tensor[ndarray], *, mode: str, axis: Dim | Sequence[Dim], use_mask: bool = True) Tensor[ndarray][source]