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`+1

should be a power of two.

ind (bool, optional): True for sequency (default)

ind (list, optional): permutation indices. This is faster than True

when 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)
tensor([12.,  9.,  9., 16.,  4.,  5.,  9.])
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('cpu'))
>>> t = timeit.timeit(lambda: wh.fwalsh_S_torch(x), number=10)
>>> print(f"No indices as inputs (10x): {t:.3f} seconds")
No indices as inputs (10x): ... 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")
With indices as inputs (10x): ... seconds