torchwrench.nn.functional.transform module¶
-
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Never], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) Tensor1D[source]¶ -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Never]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) Tensor2D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Sequence[Never]]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) Tensor3D -
torchwrench.nn.functional.transform.as_tensor(data: bool, dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor0D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[bool], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor1D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[bool]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor2D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Sequence[bool]]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) BoolTensor3D -
torchwrench.nn.functional.transform.as_tensor(data: bool | int | float | complex, dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int =
None) BoolTensor0D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[bool | int | float | complex], dtype: 'bool', device: device | None | 'default' | 'cuda_if_available' | str | int =
None) BoolTensor1D -
torchwrench.nn.functional.transform.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.transform.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.transform.as_tensor(data: int, dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) LongTensor0D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[int], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) LongTensor1D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[int]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) LongTensor2D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Sequence[int]]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) LongTensor3D -
torchwrench.nn.functional.transform.as_tensor(data: bool | int | float | complex, dtype: 'int64' | 'long', device: device | None | 'default' | 'cuda_if_available' | str | int =
None) LongTensor0D -
torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.as_tensor(data: float, dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) FloatTensor0D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[float], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) FloatTensor1D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[float]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) FloatTensor2D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Sequence[float]]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) FloatTensor3D -
torchwrench.nn.functional.transform.as_tensor(data: bool | int | float | complex, dtype: 'float32' | 'float', device: device | None | 'default' | 'cuda_if_available' | str | int =
None) FloatTensor0D -
torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.as_tensor(data: complex, dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) CFloatTensor0D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[complex], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) CFloatTensor1D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[complex]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) CFloatTensor2D -
torchwrench.nn.functional.transform.as_tensor(data: Sequence[Sequence[Sequence[complex]]], dtype: None =
None, device: device | None | 'default' | 'cuda_if_available' | str | int =None) CFloatTensor3D -
torchwrench.nn.functional.transform.as_tensor(data: bool | int | float | complex, dtype: 'complex64' | 'cfloat', device: device | None | 'default' | 'cuda_if_available' | str | int =
None) CFloatTensor0D -
torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.flatten(x: Tensor, start_dim: int =
0, end_dim: int | None =None) Tensor1D[source]¶ -
torchwrench.nn.functional.transform.flatten(x: ndarray | generic, start_dim: int =
0, end_dim: int | None =None) ndarray -
torchwrench.nn.functional.transform.flatten(x: T_BuiltinScalar, start_dim: int =
0, end_dim: int | None =None) list[T_BuiltinScalar] -
torchwrench.nn.functional.transform.flatten(x: Iterable[T_BuiltinScalar], start_dim: int =
0, end_dim: int | None =None) list[T_BuiltinScalar]
-
torchwrench.nn.functional.transform.move_to(x: Mapping[T, U], predicate: Callable[[Tensor | Module], bool] | None =
None, **kwargs) dict[T, U][source]¶ -
torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.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.transform.squeeze_(x: Tensor, dim: int | Iterable[int] | None =
None) Tensor[source]¶
-
torchwrench.nn.functional.transform.squeeze_copy(x: T_TensorOrArray, dim: int | Iterable[int] | None =
None) T_TensorOrArray[source]¶
- torchwrench.nn.functional.transform.to_item(x: T_BuiltinScalar) T_BuiltinScalar[source]¶
- torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.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.transform.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.transform.top_p(x: Tensor, p: float, dim: int =
-1, largest: bool =True, *, return_values: False, return_indices: True =True) LongTensor -
torchwrench.nn.functional.transform.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.transform.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.transform.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.transform.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.transform.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.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.transform.unsqueeze(x: T_TensorOrArray, dim: int | Iterable[int], mode: 'view_if_possible' | 'view' | 'copy' | 'inplace' =
'view_if_possible') T_TensorOrArray[source]¶
- torchwrench.nn.functional.transform.unsqueeze_copy(x: T_TensorOrArray, dim: int | Iterable[int]) T_TensorOrArray[source]¶
- torchwrench.nn.functional.transform.view_as_complex(x: Tensor) ComplexFloatingTensor[source]¶
- torchwrench.nn.functional.transform.view_as_complex(x: ndarray) ndarray
- torchwrench.nn.functional.transform.view_as_complex(x: tuple[float, float]) complex
Convert floating-point input to complex-valued object.