Make CsrMatrix/CscMatrix::pattern() return reference

This commit is contained in:
Andreas Longva 2020-12-09 14:16:27 +01:00
parent 4420237ede
commit 8b7b836a37
3 changed files with 9 additions and 9 deletions

View File

@ -275,8 +275,8 @@ impl<T> CscMatrix<T> {
// 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<T> CscMatrix<T> {
/// 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<SparsityPattern> {
Arc::clone(&self.sparsity_pattern)
pub fn pattern(&self) -> &Arc<SparsityPattern> {
&self.sparsity_pattern
}
}

View File

@ -275,8 +275,8 @@ impl<T> CsrMatrix<T> {
// 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<T> CsrMatrix<T> {
/// 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<SparsityPattern> {
Arc::clone(&self.sparsity_pattern)
pub fn pattern(&self) -> &Arc<SparsityPattern> {
&self.sparsity_pattern
}
}

View File

@ -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());
}
}