| Crates.io | tenrso-decomp |
| lib.rs | tenrso-decomp |
| version | 0.1.0-alpha.2 |
| created_at | 2025-11-08 08:51:51.514411+00 |
| updated_at | 2025-12-17 06:36:13.101353+00 |
| description | Tensor decompositions: CP-ALS, Tucker-HOOI, TT-SVD |
| homepage | https://github.com/cool-japan/tenrso |
| repository | https://github.com/cool-japan/tenrso |
| max_upload_size | |
| id | 1922668 |
| size | 636,139 |
Tensor decomposition methods: CP-ALS, Tucker-HOOI/HOSVD, and TT-SVD.
tenrso-decomp provides production-grade implementations of major tensor decomposition algorithms:
All methods support initialization strategies, convergence criteria, and reconstruction error tracking.
Add to your Cargo.toml:
[dependencies]
tenrso-decomp = "0.1"
use tenrso_decomp::cp_als;
use scirs2_core::ndarray_ext::Array;
let tensor = Array::zeros(vec![100, 200, 300]);
// CP-ALS with rank 64
let cp = cp_als(
&tensor,
rank = 64,
iters = 50,
tol = 1e-4,
nonneg = false,
)?;
println!("Reconstruction error: {}", cp.error());
println!("Final factors: {:?}", cp.factors());
use tenrso_decomp::{tucker_hosvd, tucker_hooi};
// HOSVD (one-pass, fast)
let tucker = tucker_hosvd(&tensor, &[64, 64, 32])?;
// HOOI (iterative, more accurate)
let tucker = tucker_hooi(&tensor, &[64, 64, 32], max_iters=30, tol=1e-4)?;
println!("Core tensor: {:?}", tucker.core().shape());
println!("Factor matrices: {:?}", tucker.factors());
use tenrso_decomp::tt_svd;
// TT-SVD with truncation tolerance
let tt = tt_svd(&tensor, eps=1e-6)?;
println!("TT-ranks: {:?}", tt.ranks());
println!("Compression ratio: {:.2}×", tt.compression_ratio());
pub fn cp_als<T>(
tensor: &Array<T, IxDyn>,
rank: usize,
max_iters: usize,
tol: f64,
nonneg: bool,
) -> Result<CpDecomposition<T>>
Computes CP decomposition using Alternating Least Squares.
Parameters:
tensor - Input tensorrank - Number of componentsmax_iters - Maximum iterationstol - Convergence tolerancenonneg - Enable non-negative constraintsReturns: CpDecomposition with factor matrices and metadata
pub fn tucker_hosvd<T>(
tensor: &Array<T, IxDyn>,
ranks: &[usize],
) -> Result<TuckerDecomposition<T>>
pub fn tucker_hooi<T>(
tensor: &Array<T, IxDyn>,
ranks: &[usize],
max_iters: usize,
tol: f64,
) -> Result<TuckerDecomposition<T>>
Computes Tucker decomposition via HOSVD or HOOI.
pub fn tt_svd<T>(
tensor: &Array<T, IxDyn>,
eps: f64,
) -> Result<TtDecomposition<T>>
Computes Tensor Train decomposition with SVD truncation.
See examples/ directory:
cp_als.rs - CP decomposition example (TODO)tucker.rs - Tucker decomposition example (TODO)tt.rs - Tensor Train example (TODO)reconstruction.rs - Error analysis (TODO)# Run unit tests
cargo test
# Run benchmarks
cargo bench
# Property tests
cargo test --test properties
See ../../CONTRIBUTING.md for development guidelines.
Apache-2.0