returnn.frontend._utils
#
Internal utils
- returnn.frontend._utils.get_backend_from_tensors(*args)[source]#
- Parameters:
args –
- Returns:
frontend, fallback to global frontend
- returnn.frontend._utils.get_dtype_name(x: T | Tensor[T] | int | float) str [source]#
- Parameters:
x – tensor
- Returns:
dtype of tensor, as string
- returnn.frontend._utils.is_int(x: T | Tensor[T] | int | float) bool [source]#
- Parameters:
x –
- Returns:
whether the dtype is int
- returnn.frontend._utils.bin_op_out_template(backend: Type[Backend], a: Tensor[T] | int | float | number, b: Tensor[T] | int | float | number, *, name: str, copy_sparse_dim: bool = True, allow_broadcast_all_sources: bool | None = None, dim_order: Sequence[Dim] | None = None, allow_scalar: bool = True) Tuple[Tensor[T], T, T] [source]#
make template for output tensor of binary op
- Parameters:
backend –
a –
b –
name – for returned Tensor. no other functionality
copy_sparse_dim –
allow_broadcast_all_sources – if True, it is allowed that neither a nor b has all dims of the result. Not needed when out_dims is specified explicitly.
dim_order – defines the order of the resulting dims. if None, it is automatically inferred from a and b. Not all the dims of a and b need to be specified here, and there could also be other dims in the dim_order.
allow_scalar – if True, it is allowed that a or b is a scalar, and then no broadcast dims are added. This can be relevant to allow things like x * 2, where x in on GPU, and then PyTorch allows 2 to stay on CPU.
- Returns:
out, a_raw, b_raw
- returnn.frontend._utils.res_feature_dim(a: Tensor, b: Tensor) Dim | None [source]#
- Parameters:
a –
b –
- Returns:
feature dim if consistent or None
- returnn.frontend._utils.res_sparse_dim(a: Tensor, b: Tensor) Dim | None [source]#
- Parameters:
a –
b –
- Returns:
sparse dim if consistent or None
- returnn.frontend._utils.strided_slice_raw_key(tensor: Tensor, axis: Dim | Sequence[Dim] | None = None, key: int | float | complex | number | ndarray | bool | str | Tensor | slice | Sequence[int | float | complex | number | ndarray | bool | str | Tensor | slice] | None = None, key_dim: Dim | Sequence[Dim] | None = None) Tuple[slice | int | T | Sequence[None | slice | int | T], Tuple[Dim, ...]] [source]#
Given an axis and a key, return a raw key that can be used to index into a raw tensor, as in raw_tensor[key]. The tensor is needed to infer the raw axis index.
- Returns:
raw item key, resulting dims of reduced tensor