tensordecomp
tensordecomp is a lightweight, high-performance Python library for multi-dimensional tensor decompositions and PuzzleTensor sparsity-inducing permutation algorithms.
Features
- Core Tensor Decompositions:
- CANDECOMP/PARAFAC (
CP) via Alternating Least Squares (ALS) - Tucker Decomposition (Higher-Order Orthogonal Iteration / HOSVD core)
- Higher-Order Singular Value Decomposition (
HOSVD) - Tensor Train (
TT/ TT-SVD)
- CANDECOMP/PARAFAC (
- PuzzleTensor Optimization (KDD 2025 Paper):
- Greedy cyclic slice shifting to minimize matricization SVD decay cost $F(A)$
- SVD energy concentration for enhanced low-rank compressibility
- Augmented pipelines:
cp_puzzle,tucker_puzzle,hosvd_puzzle,tensor_train_puzzle
- Reconstruction, Accuracy & Benchmarking:
- Exact/approximate tensor reconstruction from decomposed factors
- Numerical metrics: Relative Error, RMSE, MAE, Compression Ratio
- Execution speed benchmarks and FLOP estimation
- Zero Heavy Dependencies:
- Requires only
numpy>=1.26
- Requires only
Installation
Local Editable Install (Development Mode)
pip install -e ./tensordecomp
# or with uv
uv pip install -e ./tensordecomp
Quickstart
import numpy as np
import tensordecomp as td
# 1. Create a 3D tensor
tensor = np.random.rand(4, 5, 6)
# 2. Run CP Decomposition
cp_res = td.cp(tensor, rank=3)
print("CP Factors:", [f.shape for f in cp_res["factors"]])
# 3. Run PuzzleTensor Shifting
shifted_tensor, shifts = td.puzzle_tensor(tensor, max_shift=2)
# 4. Run Puzzle-Augmented Tucker Decomposition
tucker_res = td.tucker_puzzle(tensor, ranks=[3, 3, 3])
print("Tucker Core Shape:", tucker_res["core"].shape)
# 5. Numerical Accuracy & Metrics
analysis = td.analyze_decomposition(tensor, "tucker_puzzle", tucker_res)
print(f"RMSE: {analysis['root_mean_squared_error']:.6f}")
print(f"Compression: {analysis['compression_ratio']:.2f}x")
# 6. Compare All Methods Side-by-Side
comparison = td.compare_methods(tensor, ["cp", "tucker", "hosvd", "tensor_train"])
for row in comparison:
print(f"{row['algorithm']}: {row['execution_time_ms']:.2f}ms, error={row['relative_error']:.4e}")
License
MIT License.
Metadata
Release files for tensordecomp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tensordecomp-0.1.0.tar.gz | 17.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tensordecomp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.4 kB
Release files / tensordecomp-0.1.0.tar.gz
| Download URL | tensordecomp-0.1.0.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcf4ed6b3e118468e73cdc8407d1a64fbcb4238c6d32862693d85ad806fa7c5e
|
|
BLAKE2b-256 checksum How to use checksums |
d82866ba210e3463a8d0f9a978fb3ec274e06861e0964d9fe537c0df08f04c28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / tensordecomp-0.1.0-py3-none-any.whl
| Download URL | tensordecomp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8ee4e0bff9da0b21c2ae8a96a91fb4c22674a1aa79a5941be0eeb22fc2e1415
|
|
BLAKE2b-256 checksum How to use checksums |
0d9756cc43be3ec371a7684f80c37ba966019f77a3a4272786064ffb0d301275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|