Use sparse-matrix-based boundary wavelet transforms
mainFor transforms that do not add extra pixels at the edges (unlike padding/convolution approaches), use the MatrixWavedec and MatrixWaverec classes. These utilize torch.sparse.mm for efficiency.
1D Sparse Transforms
Use MatrixWavedec for forward and MatrixWaverec for backward transforms.
2D Sparse Transforms
Use MatrixWavedec2 and MatrixWaverec2.
- Separable (Default): Uses a 1D transformation along both axes. This is generally faster.
- Non-separable: Pass
separable=Falseto the constructor to use a non-separable transformation.
import torch
import ptwt
# 1D sparse matrix forward transform
data = torch.arange(16, dtype=torch.float32)
matrix_wavedec = ptwt.MatrixWavedec("haar", level=2)
coeff = matrix_wavedec(data)
# 1D sparse matrix backward transform
matrix_waverec = ptwt.MatrixWaverec("haar")
rec = matrix_waverec(coeff)