Skip to content

Add clear methods to sparse matrices #1009

Open
@2pt0

Description

@2pt0

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:

pub struct IterativeAlgo {
    a: CsrMatrix<f64>
}

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`
        // ...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions