tenferro_tensor_compute/lib.rs
1//! Typed tensor computation facade for tenferro-rs.
2//!
3//! This crate re-exports the most commonly used items from the lower-level
4//! tenferro crates so that downstream users need only a single dependency
5//! for typed `Tensor<T>` computation with einsum and linear algebra.
6//!
7//! # When to use this crate
8//!
9//! | Crate | Use when |
10//! |-------|----------|
11//! | **`tenferro-tensor-compute`** | You want typed `Tensor<T>` with einsum and linalg |
12//! | `tenferro` | You need automatic differentiation (VJP/JVP) |
13//! | `tenferro-tensor` | You only need the data type (library/crate authors) |
14//!
15//! # Examples
16//!
17//! Matrix multiplication via einsum, then SVD:
18//!
19//! ```
20//! use tenferro_tensor_compute::{
21//! einsum, CpuBackend, CpuContext, MemoryOrder, Standard, Tensor,
22//! };
23//!
24//! let col = MemoryOrder::ColumnMajor;
25//! // 4 threads for parallel operations
26//! let mut ctx = CpuContext::new(4);
27//!
28//! // Column-major: data is stored column-first.
29//! // Use Tensor::from_row_major_slice if your data is row-major.
30//! let a = Tensor::<f64>::from_slice(&[1.0, 2.0, 3.0, 4.0], &[2, 2], col).unwrap();
31//! let b = Tensor::<f64>::from_slice(&[5.0, 6.0, 7.0, 8.0], &[2, 2], col).unwrap();
32//!
33//! // Standard<f64> = standard arithmetic (multiply and add) over f64
34//! let c = einsum::<Standard<f64>, CpuBackend>(
35//! &mut ctx, "ij,jk->ik", &[&a, &b], None,
36//! ).unwrap();
37//!
38//! // Read values back
39//! assert_eq!(c.dims(), &[2, 2]);
40//! assert_eq!(c.get(&[0, 0]), Some(&23.0));
41//! let values = c.to_vec(); // column-major order
42//! assert_eq!(values, vec![23.0, 34.0, 31.0, 46.0]);
43//! ```
44//!
45//! SVD decomposition (requires `linalg` feature, enabled by default):
46//!
47//! ```
48//! # #[cfg(feature = "linalg")]
49//! # {
50//! use tenferro_tensor_compute::{svd, CpuContext, MemoryOrder, Tensor};
51//!
52//! let mut ctx = CpuContext::new(1);
53//! let a = Tensor::<f64>::from_slice(
54//! &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3], MemoryOrder::ColumnMajor,
55//! ).unwrap();
56//! let result = svd(&mut ctx, &a, None).unwrap();
57//! assert_eq!(result.u.dims(), &[2, 2]);
58//! assert_eq!(result.s.dims(), &[2]);
59//! assert_eq!(result.vt.dims(), &[2, 3]);
60//! # }
61//! ```
62
63// --- Tensor type and layout ---
64pub use tenferro_tensor::{MemoryOrder, StructuredTensor, Tensor};
65
66// --- Device / memory ---
67pub use tenferro_device::LogicalMemorySpace;
68
69// --- Algebra ---
70pub use tenferro_algebra::Standard;
71
72// --- Backend ---
73pub use tenferro_einsum::BackendContext;
74pub use tenferro_prims::{CpuBackend, CpuContext};
75
76// --- Einsum ---
77pub use tenferro_einsum::{einsum, einsum_into, einsum_with_subscripts, Subscripts};
78
79// --- Linalg (behind feature flag) ---
80#[cfg(feature = "linalg")]
81pub use tenferro_linalg::{
82 cholesky, cross, det, eig, eigen, inv, lstsq, lu, lu_factor, lu_solve, matrix_exp,
83 matrix_power, norm, pinv, qr, slogdet, solve, solve_triangular, svd, svdvals, tensorinv,
84 tensorsolve, vander, CholeskyExResult, EigResult, EigenResult, LstsqResult, LuFactorExResult,
85 LuFactorResult, LuResult, NormKind, QrResult, SlogdetResult, SolveExResult, SvdOptions,
86 SvdResult,
87};