From 8b7b836a37504e1769b4f26c6daf38239da1e430 Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Wed, 9 Dec 2020 14:16:27 +0100 Subject: [PATCH] Make CsrMatrix/CscMatrix::pattern() return reference --- nalgebra-sparse/src/csc.rs | 8 ++++---- nalgebra-sparse/src/csr.rs | 8 ++++---- nalgebra-sparse/tests/unit_tests/ops.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nalgebra-sparse/src/csc.rs b/nalgebra-sparse/src/csc.rs index 1a3f0639..941fb4c9 100644 --- a/nalgebra-sparse/src/csc.rs +++ b/nalgebra-sparse/src/csc.rs @@ -275,8 +275,8 @@ impl CscMatrix { // Take an Arc to the pattern, which might be the sole reference to the data after // taking the values. This is important, because it might let us avoid cloning the data // further below. - let pattern = self.pattern(); - let values = self.take_values(); + let pattern = self.sparsity_pattern; + let values = self.values; // Try to take the pattern out of the `Arc` if possible, // otherwise clone the pattern. @@ -292,8 +292,8 @@ impl CscMatrix { /// The sparsity pattern is stored internally inside an `Arc`. This allows users to re-use /// the same sparsity pattern for multiple matrices without storing the same pattern multiple /// times in memory. - pub fn pattern(&self) -> Arc { - Arc::clone(&self.sparsity_pattern) + pub fn pattern(&self) -> &Arc { + &self.sparsity_pattern } } diff --git a/nalgebra-sparse/src/csr.rs b/nalgebra-sparse/src/csr.rs index 3adc25bd..01d7533e 100644 --- a/nalgebra-sparse/src/csr.rs +++ b/nalgebra-sparse/src/csr.rs @@ -275,8 +275,8 @@ impl CsrMatrix { // Take an Arc to the pattern, which might be the sole reference to the data after // taking the values. This is important, because it might let us avoid cloning the data // further below. - let pattern = self.pattern(); - let values = self.take_values(); + let pattern = self.sparsity_pattern; + let values = self.values; // Try to take the pattern out of the `Arc` if possible, // otherwise clone the pattern. @@ -292,8 +292,8 @@ impl CsrMatrix { /// The sparsity pattern is stored internally inside an `Arc`. This allows users to re-use /// the same sparsity pattern for multiple matrices without storing the same pattern multiple /// times in memory. - pub fn pattern(&self) -> Arc { - Arc::clone(&self.sparsity_pattern) + pub fn pattern(&self) -> &Arc { + &self.sparsity_pattern } } diff --git a/nalgebra-sparse/tests/unit_tests/ops.rs b/nalgebra-sparse/tests/unit_tests/ops.rs index 4fb9c232..14eb4aec 100644 --- a/nalgebra-sparse/tests/unit_tests/ops.rs +++ b/nalgebra-sparse/tests/unit_tests/ops.rs @@ -202,6 +202,6 @@ proptest! { let c_dense = a_dense + b_dense; let c_csr = CsrMatrix::from(&c_dense); - prop_assert_eq!(&pattern_result, &*c_csr.pattern()); + prop_assert_eq!(&pattern_result, c_csr.pattern().as_ref()); } } \ No newline at end of file