torchoutil.nn.modules.transform module

class AsTensor(
*,
device: device | None | Literal['default', 'cuda_if_available'] | str | int = None,
dtype: dtype | None | Literal['default'] | str | DTypeEnum = None,
)[source]

Bases: EModule

Module version of as_tensor().

extra_repr() str[source]

Set 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 Flatten(
start_dim: int = 0,
end_dim: int | None = None,
)[source]

Bases: EModule

extra_repr() str[source]

Set 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 Identity(
*args,
**kwargs,
)[source]

Bases: EModule

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 MoveToRec(
predicate: Callable[[Tensor | Module], bool] | None = None,
)[source]

Bases: EModule

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 PadAndCropDim(
target_length: int,
align: Literal['left', 'right', 'center', 'random'] = 'left',
pad_value: int | float | bool | Callable[[Tensor], int | float | bool] = 0.0,
dim: int = -1,
mode: Literal['constant', 'reflect', 'replicate', 'circular'] = 'constant',
generator: Generator | None | Literal['default'] | int = None,
)[source]

Bases: EModule

extra_repr() str[source]

Set 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 RepeatInterleaveNd(
repeats: int,
dim: int,
)[source]

Bases: EModule

For more information, see repeat_interleave_nd().

extra_repr() str[source]

Set 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 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: EModule

extra_repr() str[source]

Set 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 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: EModule

For more information, see resample_nearest_rates().

extra_repr() str[source]

Set 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 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: EModule

extra_repr() str[source]

Set 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 Shuffled(
dims: int | Iterable[int],
generator: Generator | None | Literal['default'] | int,
)[source]

Bases: EModule

extra_repr() str[source]

Set 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 Squeeze(
dim: None | int | Iterable[int] = None,
mode: Literal['view_if_possible', 'view', 'copy', 'inplace'] = 'view_if_possible',
)[source]

Bases: EModule

Module version of squeeze().

extra_repr() str[source]

Set 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 ToItem(
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = 'first_param',
)[source]

Bases: EModule

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.

ToTensor

alias of AsTensor

TopK

alias of Topk

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

Bases: EModule

Module version of top_p().

extra_repr() str[source]

Set 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 Topk(
k: int,
dim: int = -1,
largest: bool = True,
sorted: bool = True,
*,
return_values: bool = True,
return_indices: bool = True,
)[source]

Bases: EModule

Module version of topk().

extra_repr() str[source]

Set 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 TransformDrop(
transform: Callable[[T], T],
p: float,
generator: Generator | None | Literal['default'] | int = None,
)[source]

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

extra_repr() str[source]

Set 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 Unsqueeze(
dim: int | Iterable[int],
mode: Literal['view_if_possible', 'view', 'copy', 'inplace'] = 'view_if_possible',
)[source]

Bases: EModule

Module version of unsqueeze().

extra_repr() str[source]

Set 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 ViewAsComplex(
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = 'first_param',
)[source]

Bases: EModule

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 ViewAsReal(
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = 'first_param',
)[source]

Bases: EModule

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.