Registry / ai-ml / torch-dct

torch-dct

JSON →
library0.1.6pypypiunverified

A PyTorch implementation of the Discrete Cosine Transform (DCT) and its inverse. Currently at version 0.1.6, the library provides functions for 1D, 2D, and 3D DCT and IDCT, supporting both orthogonal and non-orthogonal scaling. The package is mature but has a slow release cadence.

pip install torch-dct
INSTALL
IMPORT
SIG · TORCH-DCT
T
torch-dct
ai-mlpythonv0.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dct
from torch_dct import dct
from torch_dct import dct
idct
from torch_dct import idct
dct_2d
from torch_dct import dct_2d

Compute DCT and IDCT on a random tensor with orthogonal normalization.

import torch from torch_dct import dct, idct x = torch.randn(32, 64, 128) # Compute DCT along the last dimension X = dct(x, norm='ortho') # Reconstruct x_rec = idct(X, norm='ortho') print(torch.allclose(x, x_rec, atol=1e-6)) # Should print True
Debug
Known issues
gotchaThe default normalization ('norm' parameter) applies no scaling. To match common definitions (e.g., SciPy's 'ortho'), set norm='ortho'. 'norm=None' is the default and may lead to unexpected magnitudes.
fix
Always specify norm='ortho' unless you have a specific reason otherwise.
affects: All
gotchaThe library expects input tensors to have at least 2 dimensions for 2D DCT and 3 for 3D DCT. Passing a 1D vector will silently compute a 2D DCT on the last two dimensions, which may be unintended.
fix
Ensure input tensor dimensions match the DCT variant you intend to use (e.g., flatten before calling dct for 1D).
affects: All
breakingIn version 0.1.0, the module name was torch_dct, but some early users imported as torchdct. The correct import is now torch_dct.
fix
Use 'import torch_dct' or 'from torch_dct import dct'.
affects: >=0.1.0
Upgrade
Version history
0.1.6latest on PyPI · released Nov 6, 2022
Audit
Dependencies
torchrequiredRequired for tensor operations
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
torch-dct — pip install torch-dct · libregistry