torchwrench.nn.modules.transform module

class torchwrench.nn.modules.transform.AsTensor(*, device: device | None | 'default' | 'cuda_if_available' | str | int = None, dtype: dtype | None | 'default' | str | DTypeEnum = None)[source]

Bases: Module

Module version of as_tensor().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Any) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.Identity(*args, **kwargs)[source]

Bases: Module

forward(x: T) T[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.MoveToRec(predicate: Callable[[Tensor | Module], bool] | None = None)[source]

Bases: Module

Module version of move_to_rec().

forward(x: Any) Any[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.PadAndCropDim(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)[source]

Bases: Module

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.RepeatInterleaveNd(repeats: int, dim: int)[source]

Bases: Module

For more information, see repeat_interleave_nd().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ResampleNearestFreqs(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>)[source]

Bases: Module

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ResampleNearestRates(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>)[source]

Bases: Module

For more information, see resample_nearest_rates().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ResampleNearestSteps(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>)[source]

Bases: Module

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.Shuffled(dims: int | Iterable[int] = -1, generator: Generator | None | 'default' | int = None)[source]

Bases: Module

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.Squeeze(dim: int | Iterable[int] | None = None, mode: 'view_if_possible' | 'view' | 'copy' | 'inplace' = 'view_if_possible')[source]

Bases: Module

Module version of squeeze().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.TFlatten(start_dim: int = 0, end_dim: int | None = None)[source]

Bases: Module

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor[source]
forward(x: ndarray | generic) ndarray
forward(x: T_BuiltinScalar) list[T_BuiltinScalar]
forward(x: Iterable[T_BuiltinScalar]) list[T_BuiltinScalar]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ToItem(*args: Any, **kwargs: Any)[source]

Bases: Module

Module version of to_item().

forward(x: bool | int | float | complex | None | str | bytes | ndarray | generic | Tensor0D | Tensor | SupportsIterLen) bool | int | float | complex | None | str | bytes[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

torchwrench.nn.modules.transform.ToTensor

alias of AsTensor

torchwrench.nn.modules.transform.TopK

alias of Topk

class torchwrench.nn.modules.transform.TopP(p: float, dim: int = -1, largest: bool = True, *, return_values: bool = True, return_indices: bool = True)[source]

Bases: Module

Module version of top_p().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor | LongTensor | top_p[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.Topk(k: int, dim: int = -1, largest: bool = True, sorted: bool = True, *, return_values: bool = True, return_indices: bool = True)[source]

Bases: Module

Module version of topk().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: Tensor) Tensor | LongTensor | topk[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.TransformDrop(transform: Callable[[T], T], p: float, generator: Generator | None | 'default' | int = None)[source]

Bases: Generic[T], EModule[T, T]

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: T) T[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.Unsqueeze(dim: int | Iterable[int], mode: 'view_if_possible' | 'view' | 'copy' | 'inplace' = 'view_if_possible')[source]

Bases: Module

Module version of unsqueeze().

extra_repr() str[source]

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(x: T_TensorOrArray) T_TensorOrArray[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ViewAsComplex(*args: Any, **kwargs: Any)[source]

Bases: Module

Module version of to_item().

forward(x: Tensor | ndarray | tuple[float, float]) ComplexFloatingTensor | ndarray | complex[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class torchwrench.nn.modules.transform.ViewAsReal(*args: Any, **kwargs: Any)[source]

Bases: Module

Module version of to_item().

forward(x: Tensor | ndarray | complex) Tensor | ndarray | tuple[float, float][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.