Metadata-Version: 2.5
Name: tensordecomp
Version: 0.1.0
Summary: High-dimensional tensor decompositions and PuzzleTensor optimization library
Project-URL: Homepage, https://github.com/141Kamrul/tensordecomp
Project-URL: Repository, https://github.com/141Kamrul/tensordecomp
Project-URL: Issues, https://github.com/141Kamrul/tensordecomp/issues
Author: 141Kamrul
License: MIT License
        
        Copyright (c) 2026 Tensor Decomposer Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: cp-decomposition,hosvd,puzzle-tensor,tensor,tensor-decomposition,tensor-train,tucker-decomposition
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Requires-Dist: numpy>=1.26
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# tensordecomp

[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**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)
- **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`

---

## Installation

### Local Editable Install (Development Mode)
```bash
pip install -e ./tensordecomp
# or with uv
uv pip install -e ./tensordecomp
```

---

## Quickstart

```python
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.
