Crate tenferro_tensor_compute

Crate tenferro_tensor_compute 

Source
Expand description

Typed tensor computation facade for tenferro-rs.

This crate re-exports the most commonly used items from the lower-level tenferro crates so that downstream users need only a single dependency for typed Tensor<T> computation with einsum and linear algebra.

§When to use this crate

CrateUse when
tenferro-tensor-computeYou want typed Tensor<T> with einsum and linalg
tenferroYou need automatic differentiation (VJP/JVP)
tenferro-tensorYou only need the data type (library/crate authors)

§Examples

Matrix multiplication via einsum, then SVD:

use tenferro_tensor_compute::{
    einsum, CpuBackend, CpuContext, MemoryOrder, Standard, Tensor,
};

let col = MemoryOrder::ColumnMajor;
// 4 threads for parallel operations
let mut ctx = CpuContext::new(4);

// Column-major: data is stored column-first.
// Use Tensor::from_row_major_slice if your data is row-major.
let a = Tensor::<f64>::from_slice(&[1.0, 2.0, 3.0, 4.0], &[2, 2], col).unwrap();
let b = Tensor::<f64>::from_slice(&[5.0, 6.0, 7.0, 8.0], &[2, 2], col).unwrap();

// Standard<f64> = standard arithmetic (multiply and add) over f64
let c = einsum::<Standard<f64>, CpuBackend>(
    &mut ctx, "ij,jk->ik", &[&a, &b], None,
).unwrap();

// Read values back
assert_eq!(c.dims(), &[2, 2]);
assert_eq!(c.get(&[0, 0]), Some(&23.0));
let values = c.to_vec(); // column-major order
assert_eq!(values, vec![23.0, 34.0, 31.0, 46.0]);

SVD decomposition (requires linalg feature, enabled by default):

use tenferro_tensor_compute::{svd, CpuContext, MemoryOrder, Tensor};

let mut ctx = CpuContext::new(1);
let a = Tensor::<f64>::from_slice(
    &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3], MemoryOrder::ColumnMajor,
).unwrap();
let result = svd(&mut ctx, &a, None).unwrap();
assert_eq!(result.u.dims(), &[2, 2]);
assert_eq!(result.s.dims(), &[2]);
assert_eq!(result.vt.dims(), &[2, 3]);

Structs§

CholeskyExResult
Structured Cholesky result with numerical status information.
CpuBackend
CPU backend using strided-kernel and GEMM.
CpuContext
CPU execution context.
EigResult
Result of general eigendecomposition (always complex-valued).
EigenResult
Eigendecomposition result: A * V = V * diag(values).
LstsqResult
Least-squares result.
LuFactorExResult
Packed LU factorization result with numerical status information.
LuFactorResult
Packed LU factorization result.
LuResult
LU decomposition result: A = P * L * U.
QrResult
QR decomposition result: A = Q * R.
SlogdetResult
Sign-and-log-determinant result: det(A) = sign * exp(logabsdet).
SolveExResult
Structured solve result with numerical status information.
Standard
Typed standard arithmetic algebra (add = +, mul = *).
StructuredTensor
Structured tensor payload with logical axis metadata.
Subscripts
Einsum subscripts using integer labels (omeinsum-rs compatible).
SvdOptions
Options for truncated SVD.
SvdResult
SVD result: A = U * diag(S) * Vt.
Tensor
Multi-dimensional dense tensor.

Enums§

LogicalMemorySpace
Logical memory space where tensor data resides.
MemoryOrder
Memory ordering for new allocations.
NormKind
Norm kind for crate::norm.

Functions§

cholesky
Compute the Cholesky decomposition of a Hermitian positive-definite matrix.
cross
Compute the cross product along the leading vector axis.
det
Compute the determinant of a square matrix.
eig
Compute the eigendecomposition of a general (non-symmetric) square matrix.
eigen
Compute the eigendecomposition of a batched square matrix.
einsum
Execute einsum using string notation.
einsum_into
Execute einsum using string notation, accumulating into an existing output.
einsum_with_subscripts
Execute einsum with pre-built Subscripts.
inv
Compute the inverse of a square matrix.
lstsq
Solve the least squares problem: x = argmin ||Ax - b||².
lu
Compute the LU decomposition of a batched matrix.
lu_factor
Compute the packed LU factorization of a batched matrix.
lu_solve
Solve A x = b from a packed LU factorization.
matrix_exp
Compute the matrix exponential exp(A) of a square matrix.
matrix_power
Raise a square matrix to an integer power.
norm
Compute a norm.
pinv
Compute the Moore-Penrose pseudoinverse of a matrix.
qr
Compute the QR decomposition of a batched matrix.
slogdet
Compute sign and log-absolute-determinant of a square matrix.
solve
Solve a square linear system A x = b.
solve_triangular
Solve a triangular linear system A x = b.
svd
Compute the SVD of a batched matrix.
svdvals
Compute singular values only for a batched matrix.
tensorinv
Invert a tensorized square operator.
tensorsolve
Solve a tensorized linear system.
vander
Build a Vandermonde matrix from leading-dimension vectors.

Type Aliases§

BackendContext
Context type used by public einsum APIs for a backend/algebra pair.