From c420afde9e31bfc658450560132a30507df0a036 Mon Sep 17 00:00:00 2001 From: Chammika Mannakkara Date: Sun, 2 May 2021 20:43:16 +0900 Subject: [PATCH 1/2] CooMatrix::reserve added --- nalgebra-sparse/src/coo.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nalgebra-sparse/src/coo.rs b/nalgebra-sparse/src/coo.rs index 50c68677..b300327d 100644 --- a/nalgebra-sparse/src/coo.rs +++ b/nalgebra-sparse/src/coo.rs @@ -130,6 +130,30 @@ impl CooMatrix { .map(|((i, j), v)| (*i, *j, v)) } + /// Reserves capacity for COO matrix by at least `additional` elements. + /// + /// This increase the capacities of triplet holding arrays by reserving more space to avoid + /// frequent reallocations, in `push` operations. + /// + /// ## Panics + /// + /// Panics if any of the individual allocation of triplet arrays fail. + /// + /// ## Example + /// + /// ``` + /// # use nalgebra_sparse::coo::CooMatrix; + /// let mut coo = CooMatrix::new(4, 4); + /// // Reserver capacity in advance + /// coo.reserve(10); + /// coo.push(1, 0, 3.0); + /// ``` + pub fn reserve(&mut self, additional: usize) { + self.row_indices.reserve(additional); + self.col_indices.reserve(additional); + self.values.reserve(additional); + } + /// Push a single triplet to the matrix. /// /// This adds the value `v` to the `i`th row and `j`th column in the matrix. From 5d638a32b8070c12244e3ad1794a670779fda545 Mon Sep 17 00:00:00 2001 From: Chammika Mannakkara Date: Tue, 4 May 2021 12:29:25 +0900 Subject: [PATCH 2/2] correct all gramatical mistakes pointed by @Andlon --- nalgebra-sparse/src/coo.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nalgebra-sparse/src/coo.rs b/nalgebra-sparse/src/coo.rs index b300327d..364083a9 100644 --- a/nalgebra-sparse/src/coo.rs +++ b/nalgebra-sparse/src/coo.rs @@ -133,18 +133,18 @@ impl CooMatrix { /// Reserves capacity for COO matrix by at least `additional` elements. /// /// This increase the capacities of triplet holding arrays by reserving more space to avoid - /// frequent reallocations, in `push` operations. + /// frequent reallocations in `push` operations. /// /// ## Panics /// - /// Panics if any of the individual allocation of triplet arrays fail. + /// Panics if any of the individual allocation of triplet arrays fails. /// /// ## Example /// /// ``` /// # use nalgebra_sparse::coo::CooMatrix; /// let mut coo = CooMatrix::new(4, 4); - /// // Reserver capacity in advance + /// // Reserve capacity in advance /// coo.reserve(10); /// coo.push(1, 0, 3.0); /// ```