spyrit.misc.walsh_hadamard.fwalsh2_S_torch

spyrit.misc.walsh_hadamard.fwalsh2_S_torch(X, ind=True)[source]

Fast Walsh S-transform of X in ā€œ2Dā€

Args:

X (torch.tensor): input image with shape (*, n, n). `n`**2 should be a power of two.

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

ind (list, optional): permutation indices.

Returns:

torch.tensor: S-transformed signal with shape (*, n, n)

Examples:
>>> import spyrit.misc.walsh_hadamard as wh
>>> X = torch.tensor([[1, 3, 0, 8],[7, 5, 1, 2],[2, 3, 6, 1],[4, 6, 8, 0]])
>>> wh.fwalsh2_S_torch(X)
tensor([[ 0., 30., 27., 33.],
        [37., 33., 26., 26.],
        [32., 16., 29., 25.],
        [35., 33., 38., 28.]])
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(128, 2**6, 2**6, device=torch.device('cpu'))
>>> t = timeit.timeit(lambda: wh.fwalsh2_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]*X.shape[-2])
>>> t = timeit.timeit(lambda: wh.fwalsh2_S_torch(X,ind), number=10)
>>> print(f"With indices as inputs (10x): {t:.3f} seconds")
With indices as inputs (10x): ... seconds