Discrete Cosine Transform (DCT) for pytorch
DCT (Discrete Cosine Transform) for pytorch
This library implements DCT in terms of the built-in FFT operations in pytorch so that back propagation works through it, on both CPU and GPU. For more information on DCT and the algorithms used here, see Wikipedia and the paper by J. Makhoul. This StackExchange article might also be helpful.
The following are currently implemented:
- 1-D DCT-I and its inverse (which is a scaled DCT-I)
- 1-D DCT-II and its inverse (which is a scaled DCT-III)
- 2-D DCT-II and its inverse (which is a scaled DCT-III)
- 3-D DCT-II and its inverse (which is a scaled DCT-III)
pip install torch-dct
torch>=0.4.1 (lower versions are probably OK but I haven't tested them).
You can run test by getting the source and run
pytest. To run the test you also
import numpy as np import torch import torch_dct as dct x = torch.tensor(np.random.normal(size=(1, 200))) X = dct.dct(x) # DCT-II done through the last dimension y = dct.idct(X) # scaled DCT-III done through the last dimension assert (torch.abs(x - y)).sum() < 1e-10 # x == y within numerical tolerance
dct.idct1 are for DCT-I and its inverse. The usage is the same.
to get the multidimensional versions.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size torch_dct-0.1.5-py3-none-any.whl (4.8 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size torch-dct-0.1.5.tar.gz (3.3 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for torch_dct-0.1.5-py3-none-any.whl