Skip to main content

Crate tensor4all_tcicore

Crate tensor4all_tcicore 

Source
Expand description

TCI Core infrastructure

Shared foundation for tensor cross interpolation algorithms.

This crate provides three categories of functionality:

  • Matrix cross interpolation: MatrixLUCI (LU-based), MatrixACA (adaptive cross approximation), and RrLU (rank-revealing LU decomposition). All CI types implement the AbstractMatrixCI trait.
  • Cached function evaluation: CachedFunction wraps expensive multi-index functions with thread-safe memoization and automatic key type selection (up to 1024 bits by default, extensible via CacheKey).
  • Utility types: IndexSet for bidirectional pivot management, Matrix for dense row-major matrices, and Scalar for numeric scalar requirements.

Higher-level crates (tensor4all-tensorci, tensor4all-quanticstci) build on these primitives.

§Examples

Cross-interpolate a rank-2 matrix:

use tensor4all_tcicore::{AbstractMatrixCI, MatrixLUCI, from_vec2d};

let m = from_vec2d(vec![
    vec![1.0_f64, 2.0, 3.0],
    vec![4.0, 5.0, 6.0],
    vec![7.0, 8.0, 9.0],
]);

let ci = MatrixLUCI::from_matrix(&m, None).unwrap();
assert!(ci.rank() <= 3);
assert!(ci.rank() >= 1);

// Reconstruction matches original at pivot positions
for &i in ci.row_indices() {
    for &j in ci.col_indices() {
        assert!((ci.evaluate(i, j) - m[[i, j]]).abs() < 1e-10);
    }
}

Cache an expensive function:

use tensor4all_tcicore::CachedFunction;

let cf = CachedFunction::new(
    |idx: &[usize]| (idx[0] as f64) * (idx[1] as f64),
    &[3, 4],
).unwrap();

assert_eq!(cf.eval(&[2, 3]), 6.0);
assert_eq!(cf.num_evals(), 1);

// Second call hits cache
assert_eq!(cf.eval(&[2, 3]), 6.0);
assert_eq!(cf.num_cache_hits(), 1);

Re-exports§

pub use self::matrixluci::CandidateMatrixSource;
pub use self::matrixluci::CrossFactors;
pub use self::matrixluci::DenseFaerLuKernel;
pub use self::matrixluci::DenseMatrixSource;
pub use self::matrixluci::DenseOwnedMatrix;
pub use self::matrixluci::LazyBlockRookKernel;
pub use self::matrixluci::LazyMatrixSource;
pub use self::matrixluci::MatrixLuciError;
pub use self::matrixluci::PivotKernel;
pub use self::matrixluci::PivotKernelOptions;
pub use self::matrixluci::PivotSelectionCore;
pub use self::matrixluci::Result as MatrixLuciResult;
pub use self::matrixluci::Scalar as MatrixLuciScalar;
pub use cached_function::cache_key::CacheKey;
pub use cached_function::error::CacheKeyError;
pub use cached_function::index_int::IndexInt;
pub use cached_function::CachedFunction;
pub use error::MatrixCIError;
pub use error::Result;
pub use indexset::IndexSet;
pub use indexset::LocalIndex;
pub use indexset::MultiIndex;
pub use matrix::from_vec2d;
pub use matrix::Matrix;
pub use matrixaca::MatrixACA;
pub use matrixlu::rrlu;
pub use matrixlu::rrlu_inplace;
pub use matrixlu::RrLU;
pub use matrixlu::RrLUOptions;
pub use scalar::Scalar;
pub use traits::AbstractMatrixCI;

Modules§

cached_function
Cached function wrapper for expensive function evaluations.
error
Error types for tensor4all-tcicore.
indexset
Index set for managing ordered collections with bidirectional lookup.
matrix
Dense row-major matrix type and utility functions.
matrixaca
Adaptive Cross Approximation (ACA) implementation.
matrixlu
Rank-Revealing LU decomposition (rrLU) implementation.
matrixluci
Low-level LUCI / rrLU substrate.
scalar
Common scalar trait for matrix and tensor operations.
traits
Abstract traits for matrix cross interpolation.

Macros§

scalar_tests
Macro to generate f64 and Complex64 test variants from a generic test function.

Structs§

MatrixLUCI
Matrix LU-based Cross Interpolation.