1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Tensor decompositions: Tucker, PARAFAC/CP, Tensor Train, HOSVD.
//!
//! This module provides a self-contained, lightweight API for 3-D tensor
//! decompositions using a simple [`Tensor3D`] type backed by `Vec<f64>`.
//!
//! ## Modules
//!
//! | Module | Description |
//! |--------|-------------|
//! | [`tensor_utils`] | Core [`Tensor3D`] type, mode unfolding/folding, Khatri-Rao product, mode-n product |
//! | [`parafac`] | PARAFAC/CP decomposition via ALS and regularised ALS |
//! | [`hosvd`] | Higher-Order SVD (HOSVD) and Higher-Order Orthogonal Iteration (HOOI) |
//! | [`tucker`] | Tucker decomposition via HOOI and core consistency diagnostic |
//! | [`tensor_train`] | Tensor Train (TT-SVD), rounding, addition, Hadamard product, inner product |
//!
//! ## Quick Example
//!
//! ```rust
//! use scirs2_linalg::tensor_decomp::tensor_utils::Tensor3D;
//! use scirs2_linalg::tensor_decomp::parafac::fit_als;
//! use scirs2_linalg::tensor_decomp::tucker::tucker_als;
//! use scirs2_linalg::tensor_decomp::tensor_train::tt_svd;
//!
//! // Build a simple 2×3×4 tensor
//! let data: Vec<f64> = (0..24).map(|x| x as f64 + 1.0).collect();
//! let x = Tensor3D::new(data.clone(), [2, 3, 4]).expect("valid");
//!
//! // CP decomposition (rank 4)
//! let cp = fit_als(&x, 4, 200, 1e-6).expect("cp_als");
//! let err = cp.relative_error(&x).expect("err");
//! println!("CP relative error: {err:.2e}");
//!
//! // Tucker decomposition (ranks 2, 2, 3)
//! let tucker = tucker_als(&x, [2, 2, 3], 30, 1e-8).expect("tucker_als");
//! println!("Tucker core shape: {:?}", tucker.g.shape);
//!
//! // Tensor Train decomposition
//! let tt = tt_svd(&data, &[2, 3, 4], 10, 1e-8).expect("tt_svd");
//! println!("TT ranks: {:?}", tt.ranks());
//! ```
// Convenience re-exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// N-dimensional tensor support (generalizes beyond 3D)
pub use ;