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)
Install
pip install torch-dct
Requires 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
need scipy installed.
Usage
import torch
import torch_dct as dct
x = torch.randn(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.dct1 and dct.idct1 are for DCT-I and its inverse. The usage is the same.
Just replace dct and idct by dct_2d, dct_3d, idct_2d, idct_3d, etc
to get the multidimensional versions.
Metadata
Release files for torch-dct 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torch-dct-0.1.6.tar.gz | 4.8 kB | Without provenance | Details for torch-dct-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torch_dct-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for torch_dct-0.1.6-py3-none-any.whl |
Total release size: 9.9 kB
Release files / torch-dct-0.1.6.tar.gz
| Download URL | torch-dct-0.1.6.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87923c4b8430206e37f1ccaa80386b8600d4f65921741399cb99afdb61a3731a
|
|
BLAKE2b-256 checksum How to use checksums |
2c12518883ae7a1f0bd1039ddbb0ab3934a8cc8b1d609b47b1b7645eda59c72b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Release files / torch_dct-0.1.6-py3-none-any.whl
| Download URL | torch_dct-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ab1a064e7f138b649148c01e06cf0f0d354cdb3418ef0e04c81576ce9ba656b
|
|
BLAKE2b-256 checksum How to use checksums |
87883eef09f85bc6f22d78d820d8af91e3823a448fbee41ef53a35087297ed63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for torch-dct 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.