spyrit.core.torch.fwht_2d
- spyrit.core.torch.fwht_2d(x, order=True)[source]
Returns the fast Walsh-Hadamard transform of a 2D tensor.
This function uses the fast Walsh-Hadamard transform for 1D signals. It is optimized for the natural order (with order = False) and the sequency order (with order = True). The fast Walsh-Hadamard transform is applied along the last two dimensions of the input tensor.
- Args:
x (torch.tensor): Batch of 2D tensors to transform. The last two dimensions msut be a power of two. Has shape \((*, h, w)\) where \(h\) and \(w\) are the height and width of the image, and * represents any number of batch dimensions.
order (bool or list, optional): If a bool, defines if the sequency order is used (True) or the natural order is used (False). If a list, it defines the permutation indices to use. Default is True.
- Raises:
ValueError: If either of the last two dimensions of the input tensor is not a power of two.
- Returns:
torch.tensor: 2D Walsh-Hadamard transformed tensor.