spyrit.misc.walsh_hadamard.fwalsh_S_torch
- spyrit.misc.walsh_hadamard.fwalsh_S_torch(x, ind=True)[source]
Fast Walsh S-transform of x
- Args:
x(torch.tensor): input signal with shape (*, n). `n`+1should be a power of two.
ind(bool, optional): True for sequency (default)ind(list, optional): permutation indices. This is faster than Truewhen repeating the sequency-ordered transform multilple times.
- Returns:
torch.tensor: -by-n S-transformed signal
- Example 1:
Walsh-ordered S-transform of a signal of length 7
>>> import spyrit.misc.walsh_hadamard as wh >>> import torch >>> x = torch.tensor([1, 3, 0, -1, 7, 5, 1]) >>> s = wh.fwalsh_S_torch(x) >>> print(s)
- Example 2:
Repeating the Walsh-ordered S-transform using input indices is faster
>>> import timeit >>> import torch >>> import spyrit.misc.walsh_hadamard as wh >>> x = torch.rand(512, 2**14-1, device=torch.device('cuda:0')) >>> t = timeit.timeit(lambda: wh.fwalsh_S_torch(x), number=10) >>> print(f"No indices as inputs (10x): {t:.3f} seconds") >>> ind = wh.sequency_perm_ind(x.shape[-1]+1) >>> t = timeit.timeit(lambda: wh.fwalsh_S_torch(x,ind), number=10) >>> print(f"With indices as inputs (10x): {t:.3f} seconds")