Expand description
Sparse tensor support for TensorLogic.
This module provides comprehensive sparse tensor representations and operations:
- CSR (Compressed Sparse Row) format for efficient row operations
- CSC (Compressed Sparse Column) format for efficient column operations
- COO (Coordinate) format for flexible construction
- Sparse-dense hybrid operations
- Automatic sparsity detection and conversion
- Sparse matrix multiplication and linear algebra
§Example
ⓘ
use tensorlogic_infer::{SparseFormat, SparseTensor, SparseMatrix};
// Create a sparse matrix in COO format
let mut builder = SparseTensor::builder(vec![100, 100], SparseFormat::COO);
builder.add_entry(vec![5, 10], 3.14);
builder.add_entry(vec![20, 30], 2.71);
let sparse = builder.build()?;
// Convert to CSR for efficient operations
let csr = sparse.to_csr()?;
// Sparse-dense multiplication
let dense = vec![1.0; 100];
let result = csr.multiply_dense(&dense)?;
// Detect sparsity
let sparsity = sparse.sparsity_ratio();
println!("Sparsity: {:.2}%", sparsity * 100.0);Structs§
- SparseCOO
- Sparse matrix in COO (Coordinate) format.
- SparseCSC
- Sparse matrix in CSC (Compressed Sparse Column) format.
- SparseCSR
- Sparse matrix in CSR (Compressed Sparse Row) format.
- Sparse
Tensor Builder - Builder for sparse tensors.
Enums§
- Sparse
Error - Sparse tensor errors.
- Sparse
Format - Sparse tensor storage format.
- Sparse
Tensor - Sparse tensor representation.
Functions§
- detect_
sparsity - Detect sparsity in a dense tensor.
- to_
sparse_ if_ beneficial - Convert dense tensor to sparse if beneficial.