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