Expand description
Compact dense tensor primitives for numerical algorithms.
The crate intentionally starts with a small surface area: row-major owned arrays, cheap strided views, checked shape errors, scalar kernels, and matrix primitives that can later delegate to accelerated backends.
§Examples
Matrix slicing and multiplication:
use tensors::{Array2, matmul};
let a = Array2::from_vec([2, 3], vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0])?;
let gram = matmul(a.transpose_view(), a.view())?;
assert_eq!(gram.shape(), [3, 3]);
assert_eq!(gram[(0, 0)], 17.0);Lazy preprocessing for PCA-style workflows:
use tensors::{Array2, LinearOperator, StandardizedOperator, column_means, column_variances};
let a = Array2::from_vec([3, 2], vec![1.0, 2.0, 3.0, 6.0, 5.0, 10.0])?;
let means = column_means(a.view());
let scales = column_variances(a.view(), &means)?
.into_iter()
.map(f64::sqrt)
.collect::<Vec<_>>();
let standardized = StandardizedOperator::new(a, means, scales);
let mut y = [0.0; 3];
standardized.matvec(&[1.0, -1.0], &mut y)?;
assert_eq!(y.len(), 3);Randomized SVD on a dense matrix:
use tensors::{Array2, RandomizedSvdOptions, randomized_svd};
let a = Array2::from_vec([3, 2], vec![3.0, 0.0, 4.0, 0.0, 0.0, 0.0])?;
let result = randomized_svd(
&a,
RandomizedSvdOptions {
rank: 1,
oversampling: 1,
power_iterations: 1,
seed: Some(7),
..RandomizedSvdOptions::default()
},
)?;
assert_eq!(result.s.len(), 1);Structs§
- Array2
- Owned 2D row-major array.
- Array3
- Owned 3D row-major array.
- ArrayN
- Owned dynamic-rank row-major array.
- Array
View2 - Immutable 2D array view.
- Array
View3 - Immutable 3D array view.
- Array
View Mut2 - Mutable 2D array view.
- Array
View Mut3 - Mutable 3D array view.
- Array
View MutN - Mutable dynamic-rank strided view.
- Array
ViewN - Immutable dynamic-rank strided view.
- Centered
Operator - Lazy column-centered operator.
- Column
Scaled Operator - Lazy column-scaled operator representing
A * diag(scales). - CsrMatrix
- Compressed sparse row matrix.
- Eigh
Result - Symmetric eigendecomposition result.
- QrResult
- Thin QR decomposition result.
- Randomized
SvdOptions - Options for randomized SVD.
- RowScaled
Operator - Lazy row-scaled operator representing
diag(scales) * A. - Scratch
Buffer - Reusable one-dimensional scratch storage.
- Standardized
Operator - Lazy column-standardized operator representing
(A - means) * diag(1 / scales). - SvdResult
- Singular value decomposition result.
- Transpose
- Lazy transpose wrapper.
- Workspace
- Workspace for repeated dense matrix algorithms.
Enums§
Traits§
- Float
- Floating point scalar supported by numerical kernels.
- Linear
Operator - Matrix-like object usable by algorithms without requiring materialization.
Functions§
- approx_
reconstruction_ error - Frobenius norm of
A - U diag(S) Vt. - axpy
- Compute
y += alpha * x. - axpy_
f32 - Compute
y += alpha * xusing explicit SIMD for contiguousf32slices. - axpy_
f64 - Compute
y += alpha * xusing explicit SIMD for contiguousf64slices. - batch_
randomized_ svd - Run randomized SVD independently over each 2D slice of a 3D tensor.
- batch_
randomized_ svd_ parallel - Run randomized SVD independently over each 2D slice using Rayon.
- center_
columns_ inplace - Subtract column means in place.
- center_
rows_ inplace - Subtract row means in place.
- centered_
columns - Return a centered copy with column means removed.
- centered_
rows - Return a centered copy with row means removed.
- column_
means - Mean of each column.
- column_
variances - Population variance of each column.
- dot
- Compute a dot product.
- dot_f32
- Compute a dot product using explicit SIMD for contiguous
f32slices. - dot_f64
- Compute a dot product using explicit SIMD for contiguous
f64slices. - eigh_
small - Symmetric eigendecomposition for small dense matrices.
- explained_
variance_ ratio - Fraction of squared singular value energy explained by each value.
- fold_
view - Fold a mode-unfolded matrix back into a 3D tensor with
shape. - gemm
- Checked matrix multiplication with transpose flags:
C = alpha * op(A) * op(B) + beta * C. - gemm_
with_ workspace - Checked matrix multiplication using caller-provided reusable workspace:
C = alpha * op(A) * op(B) + beta * C. - matmul
- Return
A * B. - norm_l2
- Euclidean norm.
- norm_
l2_ f32 - Euclidean norm using explicit SIMD for contiguous
f32slices. - norm_
l2_ f64 - Euclidean norm using explicit SIMD for contiguous
f64slices. - pack_
block - Copy a rectangular view block into compact row-major storage.
- qr
- Modified Gram-Schmidt QR with one reorthogonalization pass.
- randomized_
range_ finder - Randomized range finder returning an orthonormal basis
Q. - randomized_
svd - Pure-Rust randomized SVD entry point.
- randomized_
svd_ with_ error - Run randomized SVD on a dense view and return its reconstruction error.
- reorthogonalize
- Reorthogonalize approximate basis columns.
- row_
means - Mean of each row.
- row_
variances - Population variance of each row.
- scale_
columns_ inplace - Multiply each column by the matching scale.
- scale_
rows_ inplace - Multiply each row by the matching scale.
- standardize_
columns_ inplace - Center and divide columns by their standard deviations in place.
- standardize_
rows_ inplace - Center and divide rows by their standard deviations in place.
- svd_
small - Singular value decomposition for small dense matrices.
- thin_qr
- Modified Gram-Schmidt thin QR. Returns only
Q. - unfold_
view - Unfold a 3D tensor view along
axisinto a row-major matrix. - unpack_
block - Copy a compact row-major block into a destination view at
(row, col).
Type Aliases§
- Result
- Crate-wide result type.