Expand description
Sparse kernel matrix support for large-scale problems.
Provides efficient storage and operations for sparse kernel matrices using Compressed Sparse Row (CSR) format for memory-efficient representation.
§Features
- Efficient Storage: CSR format for sparse matrices with configurable thresholds
- Matrix Operations: SpMV, transpose, addition, scaling, Frobenius norm
- Parallel Construction: Multi-threaded matrix building with rayon
- Iterator Support: Efficient iteration over non-zero entries
- Flexible Builders: Configurable threshold and max entries per row
§Example
use tensorlogic_sklears_kernels::{SparseKernelMatrix, SparseKernelMatrixBuilder};
use tensorlogic_sklears_kernels::tensor_kernels::LinearKernel;
// Build a sparse kernel matrix with parallel computation
let builder = SparseKernelMatrixBuilder::new()
.with_threshold(0.1).unwrap()
.with_max_entries_per_row(100).unwrap();
let kernel = LinearKernel::new();
let data = vec![vec![1.0, 0.0], vec![0.0, 1.0]];
let matrix = builder.build_parallel(&data, &kernel).unwrap();
// Sparse matrix-vector multiplication
let mut matrix = SparseKernelMatrix::new(3);
matrix.set(0, 0, 2.0);
matrix.set(1, 1, 3.0);
let x = vec![1.0, 2.0, 0.0];
let y = matrix.spmv(&x).unwrap();
// Iterate over non-zero entries
for (row, col, value) in matrix.iter_nonzeros() {
println!("({}, {}) = {}", row, col, value);
}Structs§
- Sparse
Kernel Matrix - Sparse kernel matrix using Compressed Sparse Row (CSR) format
- Sparse
Kernel Matrix Builder - Sparse kernel matrix builder with configuration
- Sparse
Matrix Iterator - Iterator for sparse matrix non-zero entries