Registry / ai-ml / dctorch

dctorch

JSON →
library0.1.2pypypiunverified

DCTorch is a Python library providing fast discrete cosine transform (DCT) and inverse discrete cosine transform (IDCT) implementations optimized for PyTorch tensors. It enables efficient frequency domain analysis and manipulation within deep learning models, supporting 2D and 3D transforms. The current version is 0.1.2, and it appears to be actively maintained with recent commits.

pip install dctorch
INSTALL
IMPORT
SIG · DCTORCH
D
dctorch
ai-mlpythonv0.1.2
Install
81.2s avg
Import
Disk
4983MB
Pass rate
3/ 10
Env Coverage3 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 87.8s
py 3.11
✕ build_error
✓ 84.15s
py 3.12
✕ build_error
✓ 71.55s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✕ timeout
4983MB installed
● package 4983MB
Code
Verified usage

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

dct_2d
from dctorch import dct_2d
from dctorch import dct_2d

This quickstart demonstrates how to perform 2D Discrete Cosine Transform (DCT) and its inverse (IDCT) on a PyTorch tensor. It includes device selection for GPU acceleration and verifies the reconstruction accuracy.

import torch from dctorch import dct_2d, idct_2d # Determine device (CPU or CUDA if available) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") print(f"Using device: {device}") # Create a random tensor (Batch size, Channels, Height, Width) x = torch.randn(1, 3, 224, 224, device=device) print(f"Original tensor shape: {x.shape}") # Perform 2D Discrete Cosine Transform y = dct_2d(x) print(f"DCT transformed tensor shape: {y.shape}") # Perform Inverse 2D Discrete Cosine Transform x_recon = idct_2d(y) print(f"Reconstructed tensor shape: {x_recon.shape}") # Verify reconstruction accuracy reconstruction_error = torch.norm(x - x_recon).item() print(f"Reconstruction error (L2 norm): {reconstruction_error:.6f}") # Note: Error is typically very small due to floating point precision assert reconstruction_error < 1e-4
Debug
Known issues
gotchaPerformance heavily depends on PyTorch's underlying CUDA/CPU implementation. Ensure PyTorch is correctly installed and configured for your hardware for optimal speed, especially with large tensors.
fix
Verify your PyTorch installation and device setup. Ensure CUDA drivers are up-to-date if using a GPU. Always move tensors to the correct device (e.g., `tensor.to('cuda')`).
affects: All
gotchaDCTorch functions assume input tensors are floating-point types (e.g., `torch.float32`, `torch.float64`). Passing integer tensors will result in type errors or unexpected behavior.
fix
Convert input tensors to a float type using `.to(torch.float32)` or `.to(torch.float64)` before passing them to `dctorch` functions.
affects: All
gotchaWhile DCT and IDCT are often used with square inputs in traditional signal processing, `dctorch` functions `dct_2d` and `idct_2d` will work with rectangular inputs. However, ensure the spatial dimensions (height, width) are consistent for corresponding DCT and IDCT operations to correctly reconstruct the original signal.
fix
No specific fix, but users should be aware of this behavior and ensure input dimensions are managed appropriately for their use case.
affects: All
Upgrade
Version history
0.1.2latest on PyPI · released Sep 21, 2023
Audit
Dependencies
torchrequiredcore functionality relies on PyTorch tensors for inputs and outputs
Agent activity
33 hits · last 30 days
node
28
Amazon
1
OpenAI (training)
1
Resources
dctorch — pip install dctorch · libregistry