dimforge / dimforge/nalgebra

Add `clear` methods to sparse matrices

Open
#1,009 3 comments 0 reactions 0 assignees View on GitHub
enhancement nalgebra-sparse
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

It is sometimes desirable to reuse the data in a sparse matrix, e.g., in an iterative algorithm, to avoid reallocation. Adding a `clear` method to these types would allow code as in the following:

``` rust
pub struct IterativeAlgo {
a: CsrMatrix
}

impl IterativeAlgo {
pub fn run(&mut self) {
loop {
self.run_iter()
}
}

fn run_iter(&mut self) {
self.populate_a_at_iter_start()

// Use `self.a`
}

fn populate_a_at_iter_start(&mut self) {
// Clear existing memory, but don't deallocate
self.a.clear()

// Write to `self.a`
// ...
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.