| Crates.io | tenrso-sparse |
| lib.rs | tenrso-sparse |
| version | 0.1.0-alpha.2 |
| created_at | 2025-11-08 08:48:54.160525+00 |
| updated_at | 2025-12-17 06:34:20.838683+00 |
| description | Sparse tensor formats and operations for TenRSo |
| homepage | https://github.com/cool-japan/tenrso |
| repository | https://github.com/cool-japan/tenrso |
| max_upload_size | |
| id | 1922664 |
| size | 898,168 |
Sparse tensor formats and operations for TenRSo.
tenrso-sparse provides efficient sparse tensor storage formats and operations:
Add to your Cargo.toml:
[dependencies]
tenrso-sparse = "0.1"
# Enable CSF/HiCOO formats
tenrso-sparse = { version = "0.1", features = ["csf"] }
use tenrso_sparse::Coo;
// Create sparse tensor from triplets
let indices = vec![[0, 1, 2], [3, 4, 5], [6, 7, 8]];
let values = vec![1.0, 2.0, 3.0];
let shape = vec![10, 10, 10];
let coo = Coo::from_triplets(indices, values, shape)?;
println!("NNZ: {}", coo.nnz());
println!("Density: {:.2}%", coo.density() * 100.0);
use tenrso_sparse::MaskPack;
use tenrso_exec::einsum_ex;
// Create mask for selective computation
let mask = MaskPack::from_indices(sparse_indices);
// Compute only masked elements
let result = einsum_ex::<f32>("ij,jk->ik")
.inputs(&[A, B])
.hints(&ExecHints {
mask: Some(mask),
prefer_sparse: true,
..Default::default()
})
.run()?;
csf feature flagpub struct Coo<T> {
pub indices: Vec<Vec<usize>>,
pub values: Vec<T>,
pub shape: Vec<usize>,
}
impl<T> Coo<T> {
pub fn from_triplets(indices, values, shape) -> Result<Self>;
pub fn nnz(&self) -> usize;
pub fn density(&self) -> f64;
pub fn to_csr(&self) -> Result<Csr<T>>;
}
pub struct MaskPack {
// Sparse mask representation
}
impl MaskPack {
pub fn from_indices(indices: Vec<Vec<usize>>) -> Self;
pub fn from_dense_bool(mask: &Array<bool, IxDyn>) -> Self;
}
See examples/ directory (TODO):
coo_basics.rs - COO format usagecsr_operations.rs - CSR matrix operationsmasked_einsum.rs - Selective computationformat_conversion.rs - Converting between formatsdefault = ["parallel"] - Parallel operationsparallel - Multi-threaded format conversioncsf - Enable CSF and HiCOO formatsApache-2.0