torchwrench.nn.functional package

Functional interface.

torchwrench.nn.functional.activity_to_segments(x: Tensor) LongTensor[source]

Extracts segments start and end positions from a boolean activity/mask tensor.

Example 1

>>> x = torch.as_tensor([0, 1, 1, 0, 0, 1, 1, 1, 1, 0]).bool()
>>> starts, ends = extract_segments(x)
>>> starts
... tensor([1, 5])
>>> ends
... tensor([3, 9])

Example 2

>>> x = torch.as_tensor([[1, 1, 1, 0], [1, 0, 0, 1]]).bool()
>>> indices, starts, ends = extract_segments(x)
>>> indices
... tensor([0, 1, 1])
>>> starts
... tensor([0, 0, 3])
>>> ends
... tensor([3, 1, 4])
Args:

x: (…, N) bool tensor containing D dims

Returns:
segments: (D+1, M) tensor, where M is the total number of segments

When D > 1, segments also contains indices of the source column for each start and end value. See Example 2 for details.

torchwrench.nn.functional.activity_to_segments_list(x: Tensor) list[tuple[int, int]] | list[source]
torchwrench.nn.functional.all_eq(x: Tensor | ndarray | bool | int | float | complex | None | str | bytes | generic | Tensor0D | Iterable, dim: None = None) bool[source]
torchwrench.nn.functional.all_eq(x: T_TensorOrArray, dim: int) T_TensorOrArray

Check if all elements are equal in a tensor, ndarray, iterable or scalar object.

torchwrench.nn.functional.all_ne(x: Tensor | ndarray | bool | int | float | complex | None | str | bytes | generic | Tensor0D | Iterable) bool[source]

Check if all elements are NOT equal in a tensor, ndarray, iterable or scalar object.

torchwrench.nn.functional.arange(end: int | float | bool, *, out: Tensor | None = None, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor1D[source]
torchwrench.nn.functional.arange(start: int | float | bool, end: int | float | bool, *, out: Tensor | None = None, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor1D
torchwrench.nn.functional.arange(start: int | float | bool, end: int | float | bool, step: int | float | bool, *, out: Tensor | None = None, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor1D
torchwrench.nn.functional.arange(end: int | float | bool, *, out: Tensor | None = None, dtype: dtype | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor1D
torchwrench.nn.functional.arange(start: int | float | bool, end: int | float | bool, *, out: Tensor | None = None, dtype: dtype | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor1D
torchwrench.nn.functional.arange(start: int | float | bool, end: int | float | bool, step: int | float | bool, *, out: Tensor | None = None, dtype: dtype | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor1D
torchwrench.nn.functional.as_device(device: None) None[source]
torchwrench.nn.functional.as_device(device: str | int | device = CUDA_IF_AVAILABLE) device

Create concrete device object from device-like object.

torchwrench.nn.functional.as_dtype(dtype: None = None) None[source]
torchwrench.nn.functional.as_dtype(dtype: str | DTypeEnum | dtype) dtype

Create concrete dtype object from dtype-like object.

torchwrench.nn.functional.as_generator(generator: None = None) None[source]
torchwrench.nn.functional.as_generator(generator: int | Generator | 'default') Generator

Create concrete generator object from generator-like object.

torchwrench.nn.functional.as_tensor(data: Sequence[Never], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor1D[source]
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Never]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[Never]]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor3D
torchwrench.nn.functional.as_tensor(data: bool, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool]]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor3D
torchwrench.nn.functional.as_tensor(data: bool | int | float | complex, dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool | int | float | complex], dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool | int | float | complex]], dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool | int | float | complex]]], dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor3D
torchwrench.nn.functional.as_tensor(data: int, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[int], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[int]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[int]]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor3D
torchwrench.nn.functional.as_tensor(data: bool | int | float | complex, dtype: 'int64' | 'long', device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool | int | float | complex], dtype: 'int64' | 'long', device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool | int | float | complex]], dtype: 'int64' | 'long', device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool | int | float | complex]]], dtype: 'int64' | 'long', device: device | None | 'default' | 'cuda_if_available' | str | int = None) LongTensor3D
torchwrench.nn.functional.as_tensor(data: float, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[float], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[float]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[float]]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor3D
torchwrench.nn.functional.as_tensor(data: bool | int | float | complex, dtype: 'float32' | 'float', device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool | int | float | complex], dtype: 'float32' | 'float', device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool | int | float | complex]], dtype: 'float32' | 'float', device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool | int | float | complex]]], dtype: 'float32' | 'float', device: device | None | 'default' | 'cuda_if_available' | str | int = None) FloatTensor3D
torchwrench.nn.functional.as_tensor(data: complex, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[complex], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[complex]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[complex]]], dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor3D
torchwrench.nn.functional.as_tensor(data: bool | int | float | complex, dtype: 'complex64' | 'cfloat', device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool | int | float | complex], dtype: 'complex64' | 'cfloat', device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool | int | float | complex]], dtype: 'complex64' | 'cfloat', device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool | int | float | complex]]], dtype: 'complex64' | 'cfloat', device: device | None | 'default' | 'cuda_if_available' | str | int = None) CFloatTensor3D
torchwrench.nn.functional.as_tensor(data: bool | int | float | complex, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor0D
torchwrench.nn.functional.as_tensor(data: Sequence[bool | int | float | complex], dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor1D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[bool | int | float | complex]], dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor2D
torchwrench.nn.functional.as_tensor(data: Sequence[Sequence[Sequence[bool | int | float | complex]]], dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor3D
torchwrench.nn.functional.as_tensor(data: Any, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor

Convert arbitrary data to tensor.

Unlike torch.as_tensor, it works recursively and stack sequences like List[Tensor]. It also accept python generator objects.

Args:

data: Data to convert to tensor. Can be Tensor, np.ndarray, list, tuple or any number-like object. dtype: Target torch dtype. defaults to None. device: Target torch device. defaults to None.

Returns:

PyTorch tensor created from data.

torchwrench.nn.functional.average_power(x: T_TensorOrArray, dim: int | tuple[int, ...] | None = -1) T_TensorOrArray[source]

Compute average power of a signal along a specified dim/axis.

torchwrench.nn.functional.cat(tensors: list[Tensor] | tuple[Tensor, ...], dim: int = 0, *, out: Tensor | None = None) Tensor[source]
torchwrench.nn.functional.cat_padded_batch(x1: Tensor, x1_lens: Tensor, x2: Tensor, x2_lens: Tensor, seq_dim: int = -1, batch_dim: int = 0) tuple[Tensor, Tensor][source]

Concatenate padded batched of sequences.

Args:

x1: First batch with D dims of shape (batch_size, …, N1, …) x1_lens: First lengths of each element in sequence dim of shape (batch_size,). x2: Second batch with D dims of shape (batch_size, …, N2, …)

The shape must be the same than x1 unless for the dimension N2.

x2_lens: Second lengths of each element in sequence dim of shape (batch_size,). seq_dim: Dimension index of sequence. defaults to -1. batch_dim: Batch dimension index. defaults to 0.

torchwrench.nn.functional.checksum_any(x: ~typing.Any, *, isinstance_fn: ~typing.Callable[[~typing.Any, type | tuple], bool] = <built-in function isinstance>, **kwargs) int[source]

Compute checksum integer value from an arbitrary object.

Supports most builtin types. Checksum can be used to compare objects. Not meant for security/cryptography.

torchwrench.nn.functional.concat(tensors: list[Tensor] | tuple[Tensor, ...], dim: int = 0, *, out: Tensor | None = None) Tensor[source]
torchwrench.nn.functional.count_parameters(model: Module, *, recurse: bool = True, only_trainable: bool = False, buffers: bool = False) int[source]

Returns the number of parameters in a module.

torchwrench.nn.functional.crop_dim(x: Tensor, target_length: int, *, dim: int = -1, align: 'left' | 'right' | 'center' | 'random' = 'left', generator: Generator | None | 'default' | int = None) Tensor[source]

Generic function to crop a tensor along a single dimension.

Args:

x: Tensor to crop of with N dims of shape (…, D, …), where D is the size of the dim-th dimension. target_length: Target length for dim. dims: Axis/dim to crop. defaults to -1. align: Alignement for crop. generator: Random generator when align is “random”.

Returns:

Cropped tensor of N dims of (…, target_length, …).

torchwrench.nn.functional.crop_dims(x: Tensor, target_lengths: Iterable[int], *, dims: Iterable[int] | 'auto' | None = 'auto', aligns: 'left' | 'right' | 'center' | 'random' | Iterable['left' | 'right' | 'center' | 'random'] = 'left', generator: Generator | None | 'default' | int = None) Tensor[source]

Generic function to crop a tensor along multiple dimensions.

Args:

x: Tensor to crop of with N dims. target_lengths: List of target lengths for each dimension. The list has size M <= N. dims: Dimensions for each length. Must be of size M. If “auto”, creates a list of the M last dimensions. aligns: Alignement or list of alignements for each dimension of size M. generator: Random generator when aligns is “random”.

Returns:

Cropped tensor of N dims.

torchwrench.nn.functional.deep_equal(x: T, y: T, *args: T) bool[source]

Recursive comparison between objects.

Supports Scalar-like, NDArrays, Tensors, DataFrames, Mapping and List-like objects. Unlike default equal, NaNs values are considered equal. Tensors and NDArrays of different shapes are supported and returns False.

torchwrench.nn.functional.empty(size: Sequence[Never], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor0D[source]
torchwrench.nn.functional.empty(size: tuple[int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.empty(size: tuple[int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.empty(size: tuple[int, int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.empty(size0: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.empty(size0: int, size1: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.empty(size0: int, size1: int, size2: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, memory_format: memory_format | None = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.equal(input, other) bool

True if two tensors have the same size and elements, False otherwise.

Note

Tensors containing NaNs are never equal to each other. Additionally, this function does not differentiate between the data types of the tensors during comparison. For more thorough tensor checks, use torch.testing.assert_close().

Example:

>>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
True
>>> torch.equal(torch.tensor([3, torch.nan]), torch.tensor([3, torch.nan]))
False
>>> torch.equal(torch.tensor([1, 2, 3], dtype=torch.int32), torch.tensor([1, 2, 3], dtype=torch.float32))
True
torchwrench.nn.functional.find(value: Any, x: Tensor, *, default: None | Tensor | bool | int | float | complex = None, dim: int = -1) LongTensor[source]

Return the index of the first occurrence of value in a tensor.

torchwrench.nn.functional.flatten(x: Tensor, start_dim: int = 0, end_dim: int | None = None) Tensor1D[source]
torchwrench.nn.functional.flatten(x: ndarray | generic, start_dim: int = 0, end_dim: int | None = None) ndarray
torchwrench.nn.functional.flatten(x: T_BuiltinScalar, start_dim: int = 0, end_dim: int | None = None) list[T_BuiltinScalar]
torchwrench.nn.functional.flatten(x: Iterable[T_BuiltinScalar], start_dim: int = 0, end_dim: int | None = None) list[T_BuiltinScalar]
torchwrench.nn.functional.full(size: Sequence[Never], fill_value: bool, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) BoolTensor0D[source]
torchwrench.nn.functional.full(size: tuple[int], fill_value: bool, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) BoolTensor1D
torchwrench.nn.functional.full(size: tuple[int, int], fill_value: bool, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) BoolTensor2D
torchwrench.nn.functional.full(size: tuple[int, int, int], fill_value: bool, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) BoolTensor3D
torchwrench.nn.functional.full(size: Sequence[Never], fill_value: int, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) LongTensor0D
torchwrench.nn.functional.full(size: tuple[int], fill_value: int, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) LongTensor1D
torchwrench.nn.functional.full(size: tuple[int, int], fill_value: int, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) LongTensor2D
torchwrench.nn.functional.full(size: tuple[int, int, int], fill_value: int, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) LongTensor3D
torchwrench.nn.functional.full(size: Sequence[Never], fill_value: float, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor0D
torchwrench.nn.functional.full(size: tuple[int], fill_value: float, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor1D
torchwrench.nn.functional.full(size: tuple[int, int], fill_value: float, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor2D
torchwrench.nn.functional.full(size: tuple[int, int, int], fill_value: float, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor3D
torchwrench.nn.functional.full(size: Sequence[Never], fill_value: complex, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) CFloatTensor0D
torchwrench.nn.functional.full(size: tuple[int], fill_value: complex, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) CFloatTensor1D
torchwrench.nn.functional.full(size: tuple[int, int], fill_value: complex, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) CFloatTensor2D
torchwrench.nn.functional.full(size: tuple[int, int, int], fill_value: complex, *, dtype: None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) CFloatTensor3D
torchwrench.nn.functional.full(size: Sequence[Never], fill_value: bool | int | float | complex, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor0D
torchwrench.nn.functional.full(size: tuple[int], fill_value: bool | int | float | complex, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.full(size: tuple[int, int], fill_value: bool | int | float | complex, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.full(size: tuple[int, int, int], fill_value: bool | int | float | complex, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.generate_square_subsequent_mask(size: int, diagonal: int = 0, *, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]
torchwrench.nn.functional.get_default_device() device[source]

Returns default device used when creating a tensor.

torchwrench.nn.functional.get_default_dtype() dtype[source]
torchwrench.nn.functional.get_default_generator() Generator[source]
torchwrench.nn.functional.get_inverse_perm(indices: Tensor, dim: int = -1) Tensor[source]

Return inverse permutation indices. The output will be a tensor of shape (…, N).

Args:

indices: Original permutation indices as tensor of shape (…, N). dim: Dimension of indices. defaults to -1.

Example 1

>>> x = torch.as_tensor([2, 4, 8, 10])
>>> indices = torch.randperm(len(x))
>>> x = x[indices]
>>> # x is now shuffled, to get back the original order we need the indices
>>> inv_indices = get_inverse_perm(indices)
>>> x_reordered = x[inv_indices]
>>> x_reordered
... tensor([2, 4, 8, 10])
torchwrench.nn.functional.get_ndim(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable, *, use_first_for_list_tuple: bool = False, return_indicator: False = False, return_default_on_invalid: False = False, default: Any = -1, return_valid: bool | None = None) int[source]
torchwrench.nn.functional.get_ndim(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable, *, use_first_for_list_tuple: bool = False, return_indicator: False = False, return_default_on_invalid: bool, default: U = -1, return_valid: bool | None = None) int | U
torchwrench.nn.functional.get_ndim(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable, *, use_first_for_list_tuple: bool = False, return_indicator: True, return_default_on_invalid: False = False, default: Any = -1, return_valid: bool | None = None) ndim[int]
torchwrench.nn.functional.get_ndim(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable, *, use_first_for_list_tuple: bool = False, return_indicator: True, return_default_on_invalid: bool, default: U = -1, return_valid: bool | None = None) ndim[int | U]

Scan first argument to return its number of dimension(s). Works recursively with Tensors, numpy arrays and builtins types instances.

Note: Sets and dicts are considered as scalars with a ndim equal to 0.

Args:

x: Input value to scan. use_first_for_list_tuple: If True, use first value to determine ndim for list and tuple argument. Otherwise it will scan each value in argument to determine its shape. defaults to False. return_indicator: If True, returns a tuple containing a boolean indicator if the data has an homogeneous ndim instead of raising a ValueError. defaults to False. return_default_on_invalid: If True and return_indicator=False, returns the default value instead of raising a ValueError. defaults to False. default: Value to return if input is a heterogeneous list/tuple. defaults to (). return_valid: Deprecated. Use return_indicator instead.

Raises:

ValueError if input has an heterogeneous number of dimensions and return_valid=False. TypeError if input has an unsupported type.

torchwrench.nn.functional.get_perm_indices(x1: Tensor, x2: Tensor) LongTensor[source]

Find permutation between two vectors t1 and t2 which contains values from 0 to N-1.

Example 1::

>>> x1 = torch.as_tensor([0, 1, 2, 4, 3, 6, 5, 7])
>>> x2 = torch.as_tensor([0, 2, 1, 4, 3, 5, 6, 7])
>>> indices = get_perm_indices(x1, x2)
>>> torch.equal(x1, x2[indices])
True
torchwrench.nn.functional.get_shape(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | DataFrame | list | tuple | set | frozenset | dict, *, output_type: Callable[[tuple[int, ...]], T] = identity, use_first_for_list_tuple: bool = False, return_indicator: False = False, return_default_on_invalid: False = False, default: Any = (), return_valid: bool | None = None) T[source]
torchwrench.nn.functional.get_shape(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | DataFrame | list | tuple | set | frozenset | dict, *, output_type: Callable[[tuple[int, ...]], T] = identity, use_first_for_list_tuple: bool = False, return_indicator: False = False, return_default_on_invalid: bool, default: U = (), return_valid: bool | None = None) T | U
torchwrench.nn.functional.get_shape(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | DataFrame | list | tuple | set | frozenset | dict, *, output_type: Callable[[tuple[int, ...]], T] = identity, use_first_for_list_tuple: bool = False, return_indicator: True, return_default_on_invalid: False = False, default: Any = (), return_valid: bool | None = None) shape[T]
torchwrench.nn.functional.get_shape(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | DataFrame | list | tuple | set | frozenset | dict, *, output_type: Callable[[tuple[int, ...]], T] = identity, use_first_for_list_tuple: bool = False, return_indicator: True, return_default_on_invalid: bool, default: U = (), return_valid: bool | None = None) shape[T | U]

Scan first argument to return its shape. Works recursively with Tensors, numpy arrays and builtins types instances.

Note: Sets and dicts are considered as scalars with a shape equal to ().

Args:

x: Input value to scan. output_type: Output shape type. defaults to identity, which returns a tuple of ints. use_first_for_list_tuple: If True, use first value in sequences to determine shape for list and tuple argument. Otherwise it will scan each value in argument to determine its shape. defaults to False. return_indicator: If True, returns a tuple containing a boolean indicator if the data has an homogeneous shape instead of raising a ValueError. defaults to False. return_default_on_invalid: If True and return_indicator=False, returns the default value instead of raising a ValueError. defaults to False. default: Value to return if input is a heterogeneous list/tuple. This default value is NOT passed to the output_type() callable argument. defaults to (). return_valid: Deprecated. Use return_indicator instead.

Raises:

ValueError: if input has an heterogeneous shape and return_valid=False. TypeError: if input has an unsupported type.

torchwrench.nn.functional.identity(x: T, **kwargs) T[source]

Identity function placeholder. Returns the first argument. Other keywords arguments are ignored.

torchwrench.nn.functional.index_to_name(index: ~typing.Sequence[int] | ~torch.Tensor | ~numpy.ndarray | ~typing.Sequence, idx_to_name: ~typing.Mapping[int, __SPHINX_IMMATERIAL_TYPE_VAR__V_T_Name] | ~typing.Iterable[__SPHINX_IMMATERIAL_TYPE_VAR__V_T_Name], *, is_number_fn: ~typing.Callable[[~typing.Any], bool] = <function is_number_like>) list[T_Name][source]

Convert indices of labels to names using a mapping for multiclass classification.

Args:

indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. is_number_fn: Type guard to check if a value is a scalar number. defaults to is_number_like.

torchwrench.nn.functional.index_to_onehot(index: Iterable[int], num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor2D[source]
torchwrench.nn.functional.index_to_onehot(index: Iterable[Iterable[int]], num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor3D
torchwrench.nn.functional.index_to_onehot(index: Iterable, num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor

Convert indices of labels to onehot boolean encoding for multiclass classification.

Args:
indices: List label indices.

Can be a nested list of indices, but it should be convertible to Tensor.

num_classes: Number maximal of unique classes. padding_idx: Class index to ignore. Output will contains only zeroes for this value. defaults to None. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.indices_to_multihot(indices: Iterable, num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert indices of labels to multihot boolean encoding for multilabel classification.

Args:

indices: List of list of label indices. Values should be integers in range [0..num_classes-1] num_classes: Number maximal of unique classes. padding_idx: Optional pad value to ignore. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.indices_to_multinames(indices: Iterable[int | Iterable[int] | Tensor | ndarray] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None = None) list[source]

Convert indices of labels to names using a mapping for multilabel classification.

Args:

indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. padding_idx: Optional pad value to ignore.

torchwrench.nn.functional.initial_seed() int[source]

Returns the initial seed for generating random numbers as a Python long.

Note

The returned seed is for the default generator on CPU only.

torchwrench.nn.functional.insert_at_indices(x: Tensor, indices: Tensor | list | bool | int | float | complex, values: bool | int | float | complex | Tensor) Tensor1D[source]

Insert value(s) in vector at specified indices.

Example 1::

>>> x = torch.as_tensor([1, 1, 2, 2, 2, 3])
>>> indices = torch.as_tensor([2, 5])
>>> values = 4
>>> insert_values(x, indices, values)
tensor([1, 1, 4, 2, 2, 2, 4, 3])
torchwrench.nn.functional.is_complex(x: Tensor) TypeGuard[ComplexFloatingTensor][source]
torchwrench.nn.functional.is_complex(x: ndarray) TypeGuard[ndarray]
torchwrench.nn.functional.is_complex(x: complex) TypeGuard[complex]
torchwrench.nn.functional.is_complex(x: Any) TypeGuard[ComplexFloatingTensor | ndarray | complex]

Returns True if object is a/contains complex-valued object(s).

torchwrench.nn.functional.is_convertible_to_tensor(x: Any) bool[source]

Returns True if inputs can be passed to torch.as_tensor function.

This function returns False for heterogeneous inputs like [[], 1], but this kind of value can be accepted by torch.as_tensor.

torchwrench.nn.functional.is_floating_point(x: Tensor) TypeGuard[FloatingTensor][source]
torchwrench.nn.functional.is_floating_point(x: ndarray) TypeGuard[ndarray]
torchwrench.nn.functional.is_floating_point(x: float) TypeGuard[float]
torchwrench.nn.functional.is_floating_point(x: Any) TypeGuard[FloatingTensor | ndarray | float]

Returns True if object is a/contains floating-point object(s).

torchwrench.nn.functional.is_full(x: Tensor | ndarray, target: Any = Ellipsis) bool[source]

Check if all element are equal to target in a tensor or array. Accept an optional value ‘target’ to specified the expected value.

torchwrench.nn.functional.is_sorted(x: Tensor | ndarray | Iterable, *, reverse: bool = False, strict: bool = False) bool[source]

Returns True if the sequence is sorted.

torchwrench.nn.functional.is_stackable(tensors: list[Any] | tuple[Any, ...]) TypeGuard[list[Tensor] | tuple[Tensor, ...]][source]

Returns True if inputs can be passed to torch.stack function, i.e. contains a non-empty list or tuple of tensors with the same shape.

torchwrench.nn.functional.is_tensor(obj: Any, /) TypeIs[Tensor][source]

Returns True if obj is a PyTorch tensor.

Args:

obj (object): Object to test

Example:

>>> x = torch.tensor([1, 2, 3])
>>> torch.is_tensor(x)
True
torchwrench.nn.functional.is_unique(x: Tensor | ndarray | bool | int | float | complex | None | str | bytes | generic | Tensor0D | Iterable) bool[source]

Check if all elements are NOT equal in a tensor, ndarray, iterable or scalar object.

torchwrench.nn.functional.lengths_to_non_pad_mask(lengths: Tensor, max_len: int | None = None, include_end: bool = False, *, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]

Convert lengths to binary mask of non-padded values.

The output will be a tensor of shape (B, max_len).

Args:

lengths: (bsize,) max_len: Optional int for indicate the maximal length.

If None, it will be set to lengths.max(). defaults to None.

include_end: If True, the value at index of len will be True in returned mask.

defaults to False.

Example 1::

>>> input = torch.as_tensor([4, 2, 0, 3, 0])
>>> lengths_to_non_pad_mask(input, max_len=6, include_end=False)
tensor([[True, True, True, True, False, False],
        [True, True, False, False, False, False],
        [False, False, False, False, False, False],
        [True, True, True, False, False, False],
        [False, False, False, False, False, False]])
torchwrench.nn.functional.lengths_to_pad_mask(lengths: Tensor, max_len: int | None = None, include_end: bool = True, *, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]

Convert lengths to binary mask of padded values. The output will be a tensor of shape (B, max_len).

Args:

lengths: (B,) max_len: Optional int for indicate the maximal length.

If None, it will be set to lengths.max(). defaults to None.

include_end: If True, the last value of each size will be set to False.

defaults to True.

Example 1::

>>> input = torch.as_tensor([4, 2, 0, 3, 0])
>>> lengths_to_non_pad_mask(input, max_len=None, include_end=True)
tensor([[False, False, False, False],
        [False, False, True, True],
        [True, True, True, True],
        [False, False, False, True],
        [True, True, True, True]])
torchwrench.nn.functional.lengths_to_ratios(lengths: Tensor, max_len: int | None = None) Tensor[source]
torchwrench.nn.functional.log_softmax_multidim(x: Tensor, *, dims: Iterable[int] | None = (-1,)) Tensor[source]

A multi-dimensional version of torch.log_softmax along multiple dimensions at the same time.

torchwrench.nn.functional.manual_seed(seed) Generator[source]

Sets the seed for generating random numbers on all devices. Returns a torch.Generator object.

Args:
seed (int): The desired seed. Value must be within the inclusive range

[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]. Otherwise, a RuntimeError is raised. Negative inputs are remapped to positive values with the formula 0xffff_ffff_ffff_ffff + seed.

torchwrench.nn.functional.masked_equal(x1: Tensor, x2: Tensor, mask: Tensor) bool[source]

Check if two tensors are equal at the specific positions.

Args:

x1: First tensor of shape S. x2: Second tensor of shape S. mask: Boolean tensor of shape S. Position marked as False are ignored by the equality.

torchwrench.nn.functional.masked_mean(x: T_TensorOrArray, non_pad_mask: T_TensorOrArray, *, dim: None | int | Iterable[int] = None, min_div: float | None = 1.0) T_TensorOrArray[source]

Average a tensor along the specified dim(s).

Args:

tensor: (N, …) non_pad_mask: Non-padding mask, should be broadcastable with argument tensor and reduced with argument dim.

It should be a boolean tensor or a float tensor containing only 1 and 0 values.

dim: Optional dim(s) to reduce. If None, result will be reduced to a scalar. defaults to None. min_div: Minimal value to avoid division by 0. defaults to 1.0.

torchwrench.nn.functional.masked_sum(x: T_TensorOrArray, non_pad_mask: T_TensorOrArray, *, dim: None | int | Iterable[int] = None) T_TensorOrArray[source]

Sum a tensor along the specified dim(s).

Args:

x: (N, …) non_pad_mask: Non-padding mask, should be broadcastable with argument tensor and reduced with argument dim.

It should be a boolean tensor or a float tensor containing only 1 and 0 values.

dim: Optional dim(s) to reduce. If None, result will be reduced to a scalar. defaults to None.

torchwrench.nn.functional.matmul(input, other, *, out=None) Tensor

Matrix product of two tensors.

The behavior depends on the dimensionality of the tensors as follows:

  • If both tensors are 1-dimensional, the dot product (scalar) is returned.

  • If both arguments are 2-dimensional, the matrix-matrix product is returned.

  • If the first argument is 1-dimensional and the second argument is 2-dimensional, a 1 is prepended to its dimension for the purpose of the matrix multiply. After the matrix multiply, the prepended dimension is removed.

  • If the first argument is 2-dimensional and the second argument is 1-dimensional, the matrix-vector product is returned.

  • If both arguments are at least 1-dimensional and at least one argument is N-dimensional (where N > 2), then a batched matrix multiply is returned. If the first argument is 1-dimensional, a 1 is prepended to its dimension for the purpose of the batched matrix multiply and removed after. If the second argument is 1-dimensional, a 1 is appended to its dimension for the purpose of the batched matrix multiply and removed after.

    The first N-2 dimensions of each argument, the batch dimensions, are broadcast (and thus must be broadcastable). The last 2, the matrix dimensions, are handled as in the matrix-matrix product.

    For example, if input is a \((j \times 1 \times n \times m)\) tensor and other is a \((k \times m \times p)\) tensor, the batch dimensions are \((j \times 1)\) and \((k)\), and the matrix dimensions are \((n \times m)\) and \((m \times p)\). out will be a \((j \times k \times n \times p)\) tensor.

This operation has support for arguments with sparse layouts. In particular the matrix-matrix (both arguments 2-dimensional) supports sparse arguments with the same restrictions as torch.mm()

Warning

Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported, or may not have autograd support. If you notice missing functionality please open a feature request.

This operator supports TensorFloat32.

On certain ROCm devices, when using float16 inputs this module will use different precision for backward.

Note

The 1-dimensional dot product version of this function does not support an out parameter.

Arguments:

input (Tensor): the first tensor to be multiplied other (Tensor): the second tensor to be multiplied

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> # vector x vector
>>> tensor1 = torch.randn(3)
>>> tensor2 = torch.randn(3)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([])
>>> # matrix x vector
>>> tensor1 = torch.randn(3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([3])
>>> # batched matrix x broadcasted vector
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3])
>>> # batched matrix x batched matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(10, 4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
>>> # batched matrix x broadcasted matrix
>>> tensor1 = torch.randn(10, 3, 4)
>>> tensor2 = torch.randn(4, 5)
>>> torch.matmul(tensor1, tensor2).size()
torch.Size([10, 3, 5])
torchwrench.nn.functional.move_to(x: Mapping[T, U], predicate: Callable[[Tensor | Module], bool] | None = None, **kwargs) dict[T, U][source]
torchwrench.nn.functional.move_to(x: T, predicate: Callable[[Tensor | Module], bool] | None = None, **kwargs) T

Move all modules and tensors recursively to a specific dtype or device.

Works recursively on Iterables, Mappings or dataclasses.

torchwrench.nn.functional.move_to_rec(x: Any, predicate: Callable[[Tensor | Module], bool] | None = None, **kwargs) Any[source]

Move all modules and tensors recursively to a specific dtype or device.

Works recursively on Iterables, Mappings or dataclasses.

torchwrench.nn.functional.mse(x1: Tensor, x2: Tensor, *, dim: int | tuple[int, ...] | None = None) Tensor[source]

Mean squared error function.

torchwrench.nn.functional.multi_indices_to_multihot(indices: Iterable[int], num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor1D[source]
torchwrench.nn.functional.multi_indices_to_multihot(indices: Iterable[Iterable[int]], num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor2D
torchwrench.nn.functional.multi_indices_to_multihot(indices: Iterable, num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor

Convert indices of labels to multihot boolean encoding for multilabel classification.

Args:

indices: List of list of label indices. Values should be integers in range [0..num_classes-1] num_classes: Number maximal of unique classes. padding_idx: Optional pad value to ignore. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.multi_indices_to_multinames(indices: Iterable[int], idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None = None) list[T_Name][source]
torchwrench.nn.functional.multi_indices_to_multinames(indices: Iterable[Iterable[int]], idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None = None) list[list[T_Name]]
torchwrench.nn.functional.multi_indices_to_multinames(indices: Iterable[Iterable[int] | Tensor | ndarray] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | SupportsGetitemLen[T_Name, Any], *, padding_idx: int | None = None) list

Convert indices of labels to names using a mapping for multilabel classification.

Args:

indices: List of list of label indices. idx_to_name: Mapping to convert a class index to its name. padding_idx: Optional pad value to ignore.

torchwrench.nn.functional.multihot_to_indices(multihot: Tensor | ndarray | Iterable[Tensor | ndarray] | Iterable[bool] | Iterable[Iterable[bool]], *, keep_tensor: bool = False, padding_idx: int | None = None, dim: int = -1) list | LongTensor | LongTensor1D[source]

Convert multihot boolean encoding to indices of labels for multilabel classification.

Args:

multihot: Multihot labels encoded as 2D matrix. Must be convertible to Tensor. keep_tensor: If True, output will be converted to a tensor if possible. defaults to False. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.multihot_to_multi_indices(multihot: Iterable[bool], *, keep_tensor: False = False, padding_idx: int | None = None, dim: int = -1) list[int][source]
torchwrench.nn.functional.multihot_to_multi_indices(multihot: Iterable[bool], *, keep_tensor: True, padding_idx: int | None = None, dim: int = -1) LongTensor1D
torchwrench.nn.functional.multihot_to_multi_indices(multihot: Iterable[Iterable[bool]], *, keep_tensor: False = False, padding_idx: int | None = None, dim: int = -1) list[list[int]]
torchwrench.nn.functional.multihot_to_multi_indices(multihot: Tensor | ndarray | Iterable[Tensor | ndarray], *, keep_tensor: bool = False, padding_idx: int | None = None, dim: int = -1) list | LongTensor

Convert multihot boolean encoding to indices of labels for multilabel classification.

Args:

multihot: Multihot labels encoded as 2D matrix. Must be convertible to Tensor. keep_tensor: If True, output will be converted to a tensor if possible. defaults to False. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.multihot_to_multinames(multihot: Tensor | ndarray | Iterable[Tensor | ndarray] | Iterable[bool] | Iterable[Iterable[bool]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name], *, dim: int = -1) list[source]

Convert multihot boolean encoding to names using a mapping for multilabel classification.

Args:

multihot: Multihot labels encoded as 2D matrix. idx_to_name: Mapping to convert a class index to its name. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.multilabel_to_powerset(multilabel: Tensor, *, num_classes: int, max_set_size: int) Tensor3D[source]
torchwrench.nn.functional.multilabel_to_powerset(multilabel: Tensor, *, mapping: Tensor) Tensor3D
Args:

multilabel: (batch_size, num_frames, num_classes) Tensor

Returns:

powerset: (batch_size, num_frames, num_powerset_classes) Tensor

torchwrench.nn.functional.multinames_to_indices(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[int]][source]

Convert names to indices of labels for multilabel classification.

Args:

names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.

torchwrench.nn.functional.multinames_to_multi_indices(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[int]][source]

Convert names to indices of labels for multilabel classification.

Args:

names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.

torchwrench.nn.functional.multinames_to_multihot(names: list[list[T_Name]], idx_to_name: Mapping[int, T_Name] | Sequence[T_Name], *, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert names to multihot boolean encoding for multilabel classification.

Args:

names: List of list of label names. idx_to_name: Mapping to convert a class index to its name. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.name_to_index(name: list[T_Name], idx_to_name: Mapping[int, T_Name] | Iterable[T_Name]) Tensor[source]

Convert names to indices of labels for multiclass classification.

Args:

names: List of list of label names. idx_to_name: Mapping to convert a class index to its name.

torchwrench.nn.functional.name_to_onehot(name: list[T_Name], idx_to_name: Mapping[int, T_Name] | SupportsIterLen[T_Name], *, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert names to onehot boolean encoding for multiclass classification.

Args:

names: List of list of label names. idx_to_name: Mapping to convert a class index to its name. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.ndim(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable, *, use_first_for_list_tuple: bool = False, return_indicator: bool = False, return_default_on_invalid: bool = False, default: U = -1, return_valid: bool | None = None) int | U | ndim[int | U][source]

Scan first argument to return its number of dimension(s). Works recursively with Tensors, numpy arrays and builtins types instances.

Note: Sets and dicts are considered as scalars with a ndim equal to 0.

Args:

x: Input value to scan. use_first_for_list_tuple: If True, use first value to determine ndim for list and tuple argument. Otherwise it will scan each value in argument to determine its shape. defaults to False. return_indicator: If True, returns a tuple containing a boolean indicator if the data has an homogeneous ndim instead of raising a ValueError. defaults to False. return_default_on_invalid: If True and return_indicator=False, returns the default value instead of raising a ValueError. defaults to False. default: Value to return if input is a heterogeneous list/tuple. defaults to (). return_valid: Deprecated. Use return_indicator instead.

Raises:

ValueError if input has an heterogeneous number of dimensions and return_valid=False. TypeError if input has an unsupported type.

torchwrench.nn.functional.nelement(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | Iterable) int[source]

Returns the number of elements in Tensor-like object.

class torchwrench.nn.functional.no_grad(orig_func: F)[source]
class torchwrench.nn.functional.no_grad(orig_func: None = None)

Bases: _NoParamDecoratorContextManager

Context-manager that disables gradient calculation.

Disabling gradient calculation is useful for inference, when you are sure that you will not call Tensor.backward(). It will reduce memory consumption for computations that would otherwise have requires_grad=True.

In this mode, the result of every computation will have requires_grad=False, even when the inputs have requires_grad=True. There is an exception! All factory functions, or functions that create a new Tensor and take a requires_grad kwarg, will NOT be affected by this mode.

This context manager is thread local; it will not affect computation in other threads.

Also functions as a decorator.

Note

No-grad is one of several mechanisms that can enable or disable gradients locally see Locally disabling gradient computation for more information on how they compare.

Note

This API does not apply to forward-mode AD. If you want to disable forward AD for a computation, you can unpack your dual tensors.

Example::
>>> # xdoctest: +SKIP
>>> x = torch.tensor([1.], requires_grad=True)
>>> with torch.no_grad():
...     y = x * 2
>>> y.requires_grad
False
>>> @torch.no_grad()
... def doubler(x):
...     return x * 2
>>> z = doubler(x)
>>> z.requires_grad
False
>>> @torch.no_grad()
... def tripler(x):
...     return x * 3
>>> z = tripler(x)
>>> z.requires_grad
False
>>> # factory function exception
>>> with torch.no_grad():
...     a = torch.nn.Parameter(torch.rand(10))
>>> a.requires_grad
True
torchwrench.nn.functional.non_pad_mask_to_lengths(mask: T_TensorOrArray, *, dim: int = -1) T_TensorOrArray[source]
torchwrench.nn.functional.non_pad_mask_to_ratios(non_pad_mask: Tensor, *, dim: int = -1) Tensor[source]
torchwrench.nn.functional.one_hot(index: Iterable, num_classes: int, *, padding_idx: int | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert indices of labels to onehot boolean encoding for multiclass classification.

Args:
indices: List label indices.

Can be a nested list of indices, but it should be convertible to Tensor.

num_classes: Number maximal of unique classes. padding_idx: Class index to ignore. Output will contains only zeroes for this value. defaults to None. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.onehot_to_index(onehot: T_TensorOrArray, *, padding_idx: int | None = None, dim: int = -1) T_TensorOrArray[source]

Convert onehot boolean encoding to indices of labels for multiclass classification.

Args:

onehot: Onehot labels encoded as 2D matrix. padding_idx: Class index placeholder when input contains only zeroes. defaults to None. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.onehot_to_name(onehot: Tensor, idx_to_name: Mapping[int, T_Name] | Iterable[T_Name], *, dim: int = -1) list[T_Name][source]

Convert onehot boolean encoding to names using a mapping for multiclass classification.

Args:

onehot: Onehot labels encoded as 2D matrix. idx_to_name: Mapping to convert a class index to its name. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.ones(size: Sequence[Never], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor0D[source]
torchwrench.nn.functional.ones(size: tuple[int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.ones(size: tuple[int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.ones(size: tuple[int, int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.ones(size0: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.ones(size0: int, size1: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.ones(size0: int, size1: int, size2: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.pad_and_crop_dim(x: Tensor, target_length: int, *, align: 'left' | 'right' | 'center' | 'random' = 'left', pad_value: int | float | bool | Tensor0D | Callable[[Tensor], int | float | bool] = 0.0, dim: int = -1, mode: 'constant' | 'reflect' | 'replicate' | 'circular' = 'constant', generator: Generator | None | 'default' | int = None) Tensor[source]

Pad and crop along the specified dimension.

torchwrench.nn.functional.pad_and_stack_rec(sequence: Tensor | int | float | tuple | list, pad_value: int | float | bool = 0, *, align: 'left' | 'right' | 'center' | 'random' = 'left', device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]

Recursive version of torch.nn.utils.rnn.pad_sequence, with padding of Tensors.

Args:

sequence: The sequence to pad. Must be convertable to tensor by having the correct number of dims in all sublists. pad_value: The pad value used. defaults to 0.

Note: Complex values is currently not supported.

align: Alignement used for padding. defaults to “left”. device: The device of the output Tensor. defaults to None. dtype: The dtype of the output Tensor. defaults to None.

Example 1::

>>> sequence = [[1, 2], [3], [], [4, 5]]
>>> output = pad_sequence_rec(sequence, 0)
tensor([[1, 2], [3, 0], [0, 0], [4, 5]])

Example 2::

>>> invalid_sequence = [[1, 2, 3], 3]
>>> output = pad_sequence_rec(invalid_sequence, 0)
ValueError : Cannot pad sequence of tensors of differents number of dims.
torchwrench.nn.functional.pad_dim(x: Tensor, target_length: int, *, dim: int = -1, align: 'left' | 'right' | 'center' | 'random' = 'left', pad_value: int | float | bool | Tensor0D | Callable[[Tensor], int | float | bool] = 0.0, mode: 'constant' | 'reflect' | 'replicate' | 'circular' = 'constant', generator: Generator | None | 'default' | int = None) Tensor[source]

Generic function to pad a tensor along a single dimension.

Args:

x: Tensor to pad of with N dims of shape (…, D, …), where D is the size of the dim-th dimension. target_length: Target length for dim. dims: Axis/dim to pad. defaults to -1. align: Alignement for pad. pad_value: Pad value used to fill tensor. defaults to 0.0.

Note: Complex values is currently not supported.

mode: Pad mode used. defaults to “constant”. generator: Random generator when align is “random”.

Returns:

Padded tensor of N dims of (…, target_length, …).

torchwrench.nn.functional.pad_dims(x: Tensor, target_lengths: Iterable[int], *, dims: Iterable[int] | 'auto' | None = None, aligns: 'left' | 'right' | 'center' | 'random' | Iterable['left' | 'right' | 'center' | 'random'] = 'left', pad_value: int | float | bool | Tensor0D | Callable[[Tensor], int | float | bool] = 0.0, mode: 'constant' | 'reflect' | 'replicate' | 'circular' = 'constant', generator: Generator | None | 'default' | int = None) Tensor[source]

Generic function to pad a tensor along multiple dimensions.

Args:

x: Tensor to pad of with N dims. target_lengths: List of target lengths for each dimension. The list has size M <= N. dims: Dimensions for each length. Must be of size M. If “auto”, creates a list of the M last dimensions. aligns: Alignement or list of alignements for each dimension of size M. pad_value: Pad value used to fill tensor. defaults to 0.0.

Note: Complex values is currently not supported.

mode: Pad mode used. defaults to “constant”. generator: Random generator when aligns is “random”.

Returns:

Padded tensor of N dims.

torchwrench.nn.functional.pad_mask_to_lengths(mask: T_TensorOrArray, *, dim: int = -1) T_TensorOrArray[source]
torchwrench.nn.functional.pad_mask_to_ratios(pad_mask: Tensor, *, dim: int = -1) Tensor[source]
torchwrench.nn.functional.powerset_to_multilabel(powerset: Tensor, soft: bool = False, *, num_classes: int, max_set_size: int) Tensor3D[source]
torchwrench.nn.functional.powerset_to_multilabel(powerset: Tensor, soft: bool = False, *, mapping: Tensor) Tensor3D
Args:

powerset: Powerset logits, probabilities or onehot tensor of shape (batch_size, num_frames, num_powerset_classes).

Returns:

multilabel: (batch_size, num_frames, num_classes) Tensor

torchwrench.nn.functional.probs_to_index(probs: Tensor, *, dim: int = -1) LongTensor[source]

Convert matrix of probabilities to indices of labels for multiclass classification.

Args:

probs: Output probabilities for each classes. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.probs_to_indices(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, padding_idx: int | None = None, dim: int = -1) list | LongTensor[source]

Convert matrix of probabilities to indices of labels for multilabel classification.

Args:

probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.probs_to_multi_indices(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, padding_idx: int | None = None, dim: int = -1) list | LongTensor[source]

Convert matrix of probabilities to indices of labels for multilabel classification.

Args:

probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. padding_idx: Class index fill value. When none, output will not be padded. defaults to None. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.probs_to_multihot(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, *, dim: int = -1, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert matrix of probabilities to multihot boolean encoding for multilabel classification.

Args:

probs: Output probabilities for each class. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. dim: Dimension of classes. defaults to -1. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.probs_to_multinames(probs: Tensor | ndarray, threshold: float | Sequence[float] | Tensor | ndarray, idx_to_name: Mapping[int, T_Name] | Sequence[T_Name]) list[list[T_Name]][source]

Convert matrix of probabilities to labels names for multilabel classification.

Args:

probs: Output probabilities for each classes. threshold: Threshold(s) to binarize probabilities. Can be a scalar or a sequence of (num_classes,) thresholds. idx_to_name: Mapping to convert a class index to its name.

torchwrench.nn.functional.probs_to_name(probs: Tensor, idx_to_name: Mapping[int, T_Name] | Iterable[T_Name], *, dim: int = -1) list[T_Name][source]

Convert matrix of probabilities to labels names for multiclass classification.

Args:

probs: Output probabilities for each classes. idx_to_name: Mapping to convert a class index to its name. dim: Dimension of classes. defaults to -1.

torchwrench.nn.functional.probs_to_onehot(probs: Tensor, *, dim: int = -1, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = torch.bool) Tensor[source]

Convert matrix of probabilities to onehot boolean encoding for multiclass classification.

Args:

probs: Output probabilities for each classes. dim: Dimension of classes. defaults to -1. device: PyTorch device of the output tensor. dtype: PyTorch DType of the output tensor.

torchwrench.nn.functional.prod(x: T_TensorOrArray, *, dim: int | None = None, start: Any = 1) T_TensorOrArray[source]
torchwrench.nn.functional.prod(x: Iterable[T_BuiltinNumber], *, dim: Any = None, start: T_BuiltinNumber = 1) T_BuiltinNumber

Returns the product of all elements in input.

torchwrench.nn.functional.rand(size: Sequence[Never], /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor0D[source]
torchwrench.nn.functional.rand(size: tuple[int], /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor1D
torchwrench.nn.functional.rand(size: tuple[int, int], /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor2D
torchwrench.nn.functional.rand(size: tuple[int, int, int], /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor3D
torchwrench.nn.functional.rand(size0: int, /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor1D
torchwrench.nn.functional.rand(size0: int, size1: int, /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor2D
torchwrench.nn.functional.rand(size0: int, size1: int, size2: int, /, *, dtype: 'float' | 'float32' | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) FloatTensor3D
torchwrench.nn.functional.rand(size: Sequence[Never], /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor0D
torchwrench.nn.functional.rand(size: tuple[int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.rand(size: tuple[int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.rand(size: tuple[int, int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.rand(size0: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.rand(size0: int, size1: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.rand(size0: int, size1: int, size2: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple, *, generator: Generator | None | 'default' | int = None, dtype: None | 'long' | 'int64' = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor0D[source]
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int], *, generator: Generator | None | 'default' | int = None, dtype: None | 'long' | 'int64' = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor1D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int, int], *, generator: Generator | None | 'default' | int = None, dtype: None | 'long' | 'int64' = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor2D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int, int, int], *, generator: Generator | None | 'default' | int = None, dtype: None | 'long' | 'int64' = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) LongTensor3D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple, *, generator: Generator | None | 'default' | int = None, dtype: dtype | str | None | 'default' | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor0D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int], *, generator: Generator | None | 'default' | int = None, dtype: dtype | str | None | 'default' | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor1D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int, int], *, generator: Generator | None | 'default' | int = None, dtype: dtype | str | None | 'default' | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor2D
torchwrench.nn.functional.randint(low: int, high: int, size: tuple[int, int, int], *, generator: Generator | None | 'default' | int = None, dtype: dtype | str | None | 'default' | DTypeEnum, device: device | None | 'default' | 'cuda_if_available' | str | int = None, requires_grad: bool = False, pin_memory: bool = False) Tensor3D
torchwrench.nn.functional.randn(size: Sequence[int], *, generator: Generator | None | 'default' | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = None, layout: layout | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor[source]
torchwrench.nn.functional.randperm(n: int, *, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, dtype: None | 'long' | 'int64' = 'long', layout: layout | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, pin_memory: bool | None = False, requires_grad: bool | None = False) LongTensor1D[source]
torchwrench.nn.functional.randperm(n: int, *, generator: Generator | None | 'default' | int = None, out: Tensor | None = None, dtype: dtype | str | None | 'default' | DTypeEnum, layout: layout | None = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.randperm_diff(size: int, generator: Generator | None | 'default' | int = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, *, dtype: dtype | None | 'default' | str | DTypeEnum = torch.int64) LongTensor1D[source]

This function ensure that every value i cannot be the element at index i. The output will be a tensor of shape (size,).

Args:

size: The number of indices. Cannot be < 2. generator: The seed or torch.Generator used to generate permutation. defaults to None. device: The PyTorch device of the output indices tensor. defaults to None. dtype: The PyTorch datatype of the output tensor. defaults to torch.long.

Example 1

>>> torch.randperm(5)
tensor([1, 4, 2, 5, 0])  # 2 is the element of index 2 !
>>> randperm_diff(5)
tensor([2, 0, 4, 1, 3])
torchwrench.nn.functional.ranks(x: Tensor, dim: int = -1, descending: bool = False) LongTensor[source]

Get the ranks of each value in range [0, x.shape[dim][.

torchwrench.nn.functional.ratios_to_lengths(ratios: Tensor, max_len: int, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]
torchwrench.nn.functional.ratios_to_non_pad_mask(ratios: Tensor, max_len: int, include_end: bool = False, *, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]
torchwrench.nn.functional.ratios_to_pad_mask(ratios: Tensor, max_len: int, include_end: bool = True, *, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]
torchwrench.nn.functional.recursive_to(fn: Callable[[P], U]) Callable[[P], U]
torchwrench.nn.functional.remove_at_indices(x: Tensor, indices: Tensor | list | bool | int | float | complex) Tensor1D[source]

Remove value(s) in vector at specified indices.

torchwrench.nn.functional.repeat_interleave_nd(x: Tensor, repeats: int, dim: int = 0) Tensor[source]

Generalized version of torch.repeat_interleave for N >= 1 dimensions. The output size will be (…, D*repeats, …), where D is the size of the dimension of the dim argument.

Args:

x: Any tensor of shape (…, D, …) with at least 1 dim. repeats: Number of repeats. dim: The dimension to repeat. defaults to 0.

Examples::

>>> x = torch.as_tensor([[0, 1, 2, 3], [4, 5, 6, 7]])
>>> repeat_interleave_nd(x, n=2, dim=0)
tensor([[0, 1, 2, 3],
        [0, 1, 2, 3],
        [4, 5, 6, 7],
        [4, 5, 6, 7]])
torchwrench.nn.functional.resample_nearest_freqs(x: ~torch.Tensor, orig_freq: int, new_freq: int, *, dims: int | ~typing.Iterable[int] = -1, round_fn: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <built-in method floor of type object>) Tensor[source]

Nearest neigbour resampling using tensor slices.

Args:

x: Input tensor. orig_freq: Source sampling rate. new_freq: Target sampling rate. dims: Dimensions to apply resampling. defaults to -1. round_fn: Rounding function to compute sub-indices. defaults to torch.floor.

torchwrench.nn.functional.resample_nearest_rates(x: ~torch.Tensor, rates: float | ~typing.Iterable[float], *, dims: int | ~typing.Iterable[int] = -1, round_fn: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <built-in method floor of type object>) Tensor[source]

Nearest neigbour resampling using tensor slices.

Args:

x: Input tensor. rate: The reduction factor of each axis, e.g. a factor of 0.5 will divide the input axes by 2. dims: Dimensions to apply resampling. defaults to -1. round_fn: Rounding function to compute sub-indices. defaults to torch.floor.

torchwrench.nn.functional.resample_nearest_steps(x: ~torch.Tensor, steps: float | ~typing.Iterable[float], *, dims: int | ~typing.Iterable[int] = -1, round_fn: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <built-in method floor of type object>) Tensor[source]

Nearest neigbour resampling using tensor slices.

Args:

x: Input tensor. steps: Floating step for resampling each value. dims: Dimensions to apply resampling. defaults to -1. round_fn: Rounding function to compute sub-indices. defaults to torch.floor.

torchwrench.nn.functional.rmse(x1: Tensor, x2: Tensor, *, dim: int | tuple[int, ...] | None = None) Tensor[source]

Root mean squared error function.

torchwrench.nn.functional.seed() int[source]

Sets the seed for generating random numbers to a non-deterministic random number on all devices. Returns a 64 bit number used to seed the RNG.

torchwrench.nn.functional.segments_list_to_activity(segments_list: list[tuple[int, int]] | Tensor | list, maxsize: int | None = None, *, device: device | None | 'default' | 'cuda_if_available' | str | int = None) BoolTensor[source]

Convert list of (start, end) tuples to activity boolean tensor.

Example

`python >>> segments = [(3, 6), (8, 9)] >>> segments_list_to_activity(segments) ... tensor([False, False, False, True, True, True, False, False, True]) `

Args:

segments_list: list of (start, end) tuples of shape (*, N, 2). maxsize: Optional max size. If None, use segments_list.max(). defaults to None. device: Optional output device. If None and segments_list is a tensor, it will use the same device. defaults to None.

Returns:

activity boolean tensor of shape (*, maxsize)

torchwrench.nn.functional.segments_to_activity(x: Tensor, maxsize: int | None = None) BoolTensor[source]

Convert stacked list/tensor of starts end stops separated to activity boolean tensor.

Args:

x: (*, 2, N) tensor maxsize: Optional max size. If None, use x.max().

Returns:

activity boolean tensor of shape (*, maxsize)

torchwrench.nn.functional.segments_to_segments_list(segments: Tensor, maxsize: int | tuple[int, ...] | None = None) list[tuple[int, int]] | list[source]

Convert stacked list/tensor of starts end stops separated to list of (start, end) tuples.

Args:

x: (2+C, N) tensor, where C defines indices in dimensions of a segments for 3D activity tensors. maxsize: Optional max size. If None, use x.max().

Returns:
list of (start, end) tuples of shape (*, N, 2).

note: (*) corresponds to C batched dimensions.

torchwrench.nn.functional.set_default_dtype(dtype: dtype | None | 'default' | str | DTypeEnum) None[source]
torchwrench.nn.functional.set_default_generator(generator: Generator | None | 'default' | int) None[source]
torchwrench.nn.functional.shape(x: bool | int | float | complex | None | str | bytes | ~numpy.ndarray | ~numpy.generic | ~torchwrench.types.tensor_subclasses.Tensor0D | ~torch.Tensor | ~pandas.DataFrame | list | tuple | set | frozenset | dict, *, output_type: ~typing.Callable[[~typing.Tuple[int, ...]], __SPHINX_IMMATERIAL_TYPE_VAR__V_T] = <function identity>, use_first_for_list_tuple: bool = False, return_indicator: bool = False, return_default_on_invalid: bool = False, default: __SPHINX_IMMATERIAL_TYPE_VAR__V_U = (), return_valid: bool | None = None) T | U | shape[T | U][source]

Scan first argument to return its shape. Works recursively with Tensors, numpy arrays and builtins types instances.

Note: Sets and dicts are considered as scalars with a shape equal to ().

Args:

x: Input value to scan. output_type: Output shape type. defaults to identity, which returns a tuple of ints. use_first_for_list_tuple: If True, use first value in sequences to determine shape for list and tuple argument. Otherwise it will scan each value in argument to determine its shape. defaults to False. return_indicator: If True, returns a tuple containing a boolean indicator if the data has an homogeneous shape instead of raising a ValueError. defaults to False. return_default_on_invalid: If True and return_indicator=False, returns the default value instead of raising a ValueError. defaults to False. default: Value to return if input is a heterogeneous list/tuple. This default value is NOT passed to the output_type() callable argument. defaults to (). return_valid: Deprecated. Use return_indicator instead.

Raises:

ValueError: if input has an heterogeneous shape and return_valid=False. TypeError: if input has an unsupported type.

torchwrench.nn.functional.shuffled(x: T_Tensor, dims: int | Iterable[int] = -1, generator: Generator | None | 'default' | int = None) T_Tensor[source]

Returns a shuffled version of the input tensor along specific dimension(s).

torchwrench.nn.functional.softmax_multidim(x: Tensor, *, dims: Iterable[int] | None = (-1,)) Tensor[source]

A multi-dimensional version of torch.softmax along multiple dimensions at the same time.

torchwrench.nn.functional.split(tensor: Tensor, split_size_or_sections: int | list[int], dim: int = 0) tuple[Tensor, ...][source]

Splits the tensor into chunks. Each chunk is a view of the original tensor.

If split_size_or_sections is an integer type, then tensor will be split into equally sized chunks (if possible). Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by split_size.

If split_size_or_sections is a list, then tensor will be split into len(split_size_or_sections) chunks with sizes in dim according to split_size_or_sections.

Args:

tensor (Tensor): tensor to split. split_size_or_sections (int) or (list(int)): size of a single chunk or

list of sizes for each chunk

dim (int): dimension along which to split the tensor.

Example:

>>> a = torch.arange(10).reshape(5, 2)
>>> a
tensor([[0, 1],
        [2, 3],
        [4, 5],
        [6, 7],
        [8, 9]])
>>> torch.split(a, 2)
(tensor([[0, 1],
         [2, 3]]),
 tensor([[4, 5],
         [6, 7]]),
 tensor([[8, 9]]))
>>> torch.split(a, [1, 4])
(tensor([[0, 1]]),
 tensor([[2, 3],
         [4, 5],
         [6, 7],
         [8, 9]]))
torchwrench.nn.functional.squeeze(x: T_TensorOrArray, dim: int | Iterable[int] | None = None, mode: 'view_if_possible' | 'view' | 'copy' | 'inplace' = 'view_if_possible') T_TensorOrArray[source]
torchwrench.nn.functional.squeeze_(x: Tensor, dim: int | Iterable[int] | None = None) Tensor[source]
torchwrench.nn.functional.squeeze_copy(x: T_TensorOrArray, dim: int | Iterable[int] | None = None) T_TensorOrArray[source]
torchwrench.nn.functional.stack(tensors: list[Tensor0D] | tuple[Tensor0D, ...], dim: int = 0, *, out: Tensor1D | None = None) Tensor1D[source]
torchwrench.nn.functional.stack(tensors: list[Tensor1D] | tuple[Tensor1D, ...], dim: int = 0, *, out: Tensor2D | None = None) Tensor2D
torchwrench.nn.functional.stack(tensors: list[Tensor2D] | tuple[Tensor2D, ...], dim: int = 0, *, out: Tensor3D | None = None) Tensor3D
torchwrench.nn.functional.stack(tensors: list[Tensor] | tuple[Tensor, ...], dim: int = 0, *, out: Tensor | None = None) Tensor
torchwrench.nn.functional.tensor_to_lengths(tensor: Tensor, *, pad_value: float | None = None, end_value: float | None = None, dim: int = -1) LongTensor[source]

Get the lengths of the non-padded elements of a tensor.

You must provide a value for one of pad_value or end_value. If both values are provided, the end_value is ignored. The output will be of shape (N,). The end_value is not included in the length of the sentence.

Args:

tensor: Input of shape (N, *). pad_value: The pad value used in tensor. defaults to None. end_value: The end value used in tensor. defaults to None. dim: The dimension of the length. defaults to -1.

Example 1::

` >>> x = torch.as_tensor([1, 10, 20, 2, 0, 0]) >>> tensor_to_lengths(x, end_value=2) ... tensor(3) `

Example 2::

` >>> x = torch.as_tensor([1, 10, 20, 2, 0, 0]) >>> tensor_to_lengths(x, pad_value=0) ... tensor(4) `

torchwrench.nn.functional.tensor_to_non_pad_mask(tensor: Tensor, *, pad_value: float | None = None, end_value: float | None = None, include_end: bool = False, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]

Convert tensor to non-pad binary mask. You must provide a value for one of pad_value or end_value. If both values are provided, the end_value is ignored. The output will be a binary mask representing the non-padded values. Shape is the same than the input tensor.

Args:

tensor: A tensor of values. If end_value is given instead of pad_value, the number of dims must be <= 2. pad_value: The pad value used in tensor. defaults to None. end_value: The end value used in tensor. defaults to None. include_end: If True, the end value will be included in non_pad_mask.

This parameter is ignored if end_value is None. defaults to False.

Example 1::

>>> input = torch.as_tensor([1, 10, 20, 2, 0, 0])
>>> tensor_to_pad_mask(input, end_value=2)
tensor([True, True, True, False, False, False])
torchwrench.nn.functional.tensor_to_pad_mask(tensor: Tensor, *, pad_value: float | None = None, end_value: float | None = None, include_end: bool = True, dtype: dtype | None | 'default' | str | DTypeEnum = None) Tensor[source]

Convert tensor to pad binary mask.

You must provide a value for one of pad_value or end_value. If both values are provided, the end_value is ignored.

The output will be a binary mask representing the padded values. Shape is the same than the input tensor.

Args:

tensor: A tensor of values. If end_value is given instead of pad_value, the number of dims must be <= 2. pad_value: The pad value used in tensor. defaults to None. end_value: The end value used in tensor. defaults to None. include_end: If True, the end value will be included in pad_mask. defaults to True.

Example 1::

>>> input = torch.as_tensor([1, 10, 20, 2, 0, 0])
>>> tensor_to_pad_mask(input, end_value=2)
tensor([False, False, False, True, True, True])
torchwrench.nn.functional.tensor_to_tensors_list(x: Tensor, *, pad_value: float | None = None, end_value: float | None = None, non_pad_mask: Tensor | None = None, lengths: None | Tensor | list[int] = None, dim: int = -1) list[Tensor][source]

Convert padded tensor to tensor list.

You must provide a value for one of the 4 arguments: pad_value, end_value, non_pad_mask or lengths. If multiple values are provided, only one will be used and the priority order is pad_value, end_value, non_pad_mask and lengths. The output will be a list of N tensors of shape (*).

Args:

tensor: (N, *) pad_value: Pad value index. defaults to None. end_value: End value index. defaults to None. non_pad_mask: Optional non-padded boolean mask. defaults to None. lengths: Length of each sequence in padded batch. dim: Dimension to get lengths. defaults to -1.

torchwrench.nn.functional.tensors_list_to_lengths(tensors: list[Tensor], dim: int = -1) LongTensor1D[source]

Return the size of the tensor at a specific dim.

The output will be a tensor of size N.

Args:

tensors: List of N tensors. dim: The dimension of the output sizes. defaults to -1.

torchwrench.nn.functional.to_item(x: T_BuiltinScalar) T_BuiltinScalar[source]
torchwrench.nn.functional.to_item(x: Tensor | ndarray | SupportsIterLen) bool | int | float | complex | None | str | bytes

Convert scalar value to the closest built-in type.

torchwrench.nn.functional.to_tensor(data: Any, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None) Tensor[source]

Convert arbitrary data to tensor.

Unlike torch.as_tensor, it works recursively and stack sequences like List[Tensor]. It also accept python generator objects.

Args:

data: Data to convert to tensor. Can be Tensor, np.ndarray, list, tuple or any number-like object. dtype: Target torch dtype. defaults to None. device: Target torch device. defaults to None.

Returns:

PyTorch tensor created from data.

torchwrench.nn.functional.top_k(x: T_Tensor, k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: bool = True, return_indices: bool = True) T_Tensor | LongTensor | topk[source]
torchwrench.nn.functional.top_p(x: Tensor, p: float, dim: int = -1, largest: bool = True, *, return_values: True = True, return_indices: True = True) top_p[source]
torchwrench.nn.functional.top_p(x: T_Tensor, p: float, dim: int = -1, largest: bool = True, *, return_values: True = True, return_indices: False) T_Tensor
torchwrench.nn.functional.top_p(x: Tensor, p: float, dim: int = -1, largest: bool = True, *, return_values: False, return_indices: True = True) LongTensor
torchwrench.nn.functional.top_p(x: T_Tensor, p: float, dim: int = -1, largest: bool = True, *, return_values: bool = True, return_indices: bool = True) T_Tensor | LongTensor | top_p
torchwrench.nn.functional.topk(x: Tensor, k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: True = True, return_indices: True = True) topk[source]
torchwrench.nn.functional.topk(x: T_Tensor, k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: True = True, return_indices: False) T_Tensor
torchwrench.nn.functional.topk(x: Tensor, k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: False, return_indices: True = True) LongTensor
torchwrench.nn.functional.topk(x: T_Tensor, k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: bool = True, return_indices: bool = True) T_Tensor | LongTensor | topk
torchwrench.nn.functional.transform_drop(transform: Callable[[T], T], x: T, p: float, *, generator: Generator | None | 'default' | int = None) T[source]

Apply a transform on a tensor with a probability of p.

Args:

transform: Transform to apply. x: Argument of the transform. p: Probability p to apply the transform. Cannot be negative.

If > 1, it will apply the transform floor(p) times and apply a last time with a probability of p - floor(p).

torchwrench.nn.functional.unsqueeze(x: T_TensorOrArray, dim: int | Iterable[int], mode: 'view_if_possible' | 'view' | 'copy' | 'inplace' = 'view_if_possible') T_TensorOrArray[source]
torchwrench.nn.functional.unsqueeze_(x: Tensor, dim: int | Iterable[int]) Tensor[source]
torchwrench.nn.functional.unsqueeze_copy(x: T_TensorOrArray, dim: int | Iterable[int]) T_TensorOrArray[source]
torchwrench.nn.functional.view_as_complex(x: Tensor) ComplexFloatingTensor[source]
torchwrench.nn.functional.view_as_complex(x: ndarray) ndarray
torchwrench.nn.functional.view_as_complex(x: tuple[float, float]) complex

Convert floating-point input to complex-valued object.

torchwrench.nn.functional.view_as_real(x: Tensor) Tensor[source]
torchwrench.nn.functional.view_as_real(x: ndarray) ndarray
torchwrench.nn.functional.view_as_real(x: complex) tuple[float, float]

Convert complex-valued input to floating-point object.

torchwrench.nn.functional.where(condition, input, other, *, out=None) Tensor

Return a tensor of elements selected from either input or other, depending on condition.

The operation is defined as:

\[\begin{split}\text{out}_i = \begin{cases} \text{input}_i & \text{if } \text{condition}_i \\ \text{other}_i & \text{otherwise} \\ \end{cases}\end{split}\]

Note

The tensors condition, input, other must be broadcastable.

Arguments:

condition (BoolTensor): When True (nonzero), yield input, otherwise yield other input (Tensor or Scalar): value (if input is a scalar) or values selected at indices

where condition is True

other (Tensor or Scalar): value (if other is a scalar) or values selected at indices

where condition is False

Keyword args:

out (Tensor, optional): the output tensor.

Returns:

Tensor: A tensor of shape equal to the broadcasted shape of condition, input, other

Example:

>>> x = torch.randn(3, 2)
>>> y = torch.ones(3, 2)
>>> x
tensor([[-0.4620,  0.3139],
        [ 0.3898, -0.7197],
        [ 0.0478, -0.1657]])
>>> torch.where(x > 0, 1.0, 0.0)
tensor([[0., 1.],
        [1., 0.],
        [1., 0.]])
>>> torch.where(x > 0, x, y)
tensor([[ 1.0000,  0.3139],
        [ 0.3898,  1.0000],
        [ 0.0478,  1.0000]])
>>> x = torch.randn(2, 2, dtype=torch.double)
>>> x
tensor([[ 1.0779,  0.0383],
        [-0.8785, -1.1089]], dtype=torch.float64)
>>> torch.where(x > 0, x, 0.)
tensor([[1.0779, 0.0383],
        [0.0000, 0.0000]], dtype=torch.float64)
torchwrench.nn.functional.where(condition) tuple of LongTensor

torch.where(condition) is identical to torch.nonzero(condition, as_tuple=True).

Note

See also torch.nonzero().

torchwrench.nn.functional.zeros(size: Sequence[Never], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor0D[source]
torchwrench.nn.functional.zeros(size: tuple[int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.zeros(size: tuple[int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.zeros(size: tuple[int, int, int], /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D
torchwrench.nn.functional.zeros(size0: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor1D
torchwrench.nn.functional.zeros(size0: int, size1: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor2D
torchwrench.nn.functional.zeros(size0: int, size1: int, size2: int, /, *, dtype: dtype | None | 'default' | str | DTypeEnum = None, device: device | None | 'default' | 'cuda_if_available' | str | int = None, out: Tensor | None = None, layout: layout | None = None, pin_memory: bool | None = False, requires_grad: bool | None = False) Tensor3D

Submodules