Structures to store and retrieve N-dimensional sparse data. Well, not any N ∈ ℕ
but any natural number that fits into the pointer size of the machine that you are using. E.g., an 8-bit microcontroller can manipulate any sparse structure with up to 255 dimensions.
For those that might be wondering about why this crate should be used, it generally comes down to space-efficiency, ergometrics and retrieving speed. The following snippet shows some use-cases for potential replacement with _cube_of_vecs
being the most inefficient of all.
rust
let _vec_of_options: Vec<Option<i32>> = Default::default();
let _matrix_of_options: [Option<Option<[Option<i32>; 8]>>; 16] = Default::default();
let _cube_of_vecs: Vec<Vec<Vec<i32>>> = Default::default();
// The list worsens exponentially for higher dimensions
See this blog post for more information.
```rust use ndsparse::{coo::CooArray, csl::CslVec};
fn main() { // A CSL and COO cube. // // _ // / / /\ // /// /\ // / 1 / /\/2/ // /1// /\/ // _1_\/ / // __\/ let coo = CooArray::new([2, 2, 2], [([0, 0, 0].into(), 1.0), ([1, 1, 1].into(), 2.0)]); let mut csl = CslVec::default(); csl .constructor() .nextoutermostdim(2) .pushline(&[1.0], &[0]) .nextoutermostdim(2) .pushemptyline() .nextoutermostdim(2) .pushemptyline() .pushline(&[2.0], &[1]); asserteq!(coo.value([0, 0, 0]), csl.value([0, 0, 0])); assert_eq!(coo.value([1, 1, 1]), csl.value([1, 1, 1])); } ```
alloc
and std
If dimensions or array storages with more than 32 elements are needed, then it is necessary to include the const-generics
feature that is only available when using a nightly Rustc compiler.
Although CSR and COO are general sparse structures, they aren't good enough for certain situations, threfore, the existence of DIA, JDS, ELL, LIL, DOK and many others.
If there are enough interest, the mentioned sparse storages might be added at some point in the future.
This project isn't and will never be a sparse algebra library because of its own self-contained responsability and complexity. Futhermore, a good implementation of such library would require a titanic amout of work and research for different algorithms, operations, decompositions, solvers and hardwares.
One of these libraries might suit you better: