Merge pull request #1141 from lsh/sparse-clear-triplet
[Sparse] Add `clear_triplets()`
This commit is contained in:
commit
5cf6afb254
@ -211,6 +211,13 @@ impl<T> CooMatrix<T> {
|
||||
self.values.push(v);
|
||||
}
|
||||
|
||||
/// Clear all triplets from the matrix.
|
||||
pub fn clear_triplets(&mut self) {
|
||||
self.col_indices.clear();
|
||||
self.row_indices.clear();
|
||||
self.values.clear();
|
||||
}
|
||||
|
||||
/// The number of rows in the matrix.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
|
@ -226,6 +226,29 @@ fn coo_push_valid_entries() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coo_clear_triplets_valid_entries() {
|
||||
let mut coo = CooMatrix::new(3, 3);
|
||||
|
||||
coo.push(0, 0, 1);
|
||||
coo.push(0, 0, 2);
|
||||
coo.push(2, 2, 3);
|
||||
assert_eq!(
|
||||
coo.triplet_iter().collect::<Vec<_>>(),
|
||||
vec![(0, 0, &1), (0, 0, &2), (2, 2, &3)]
|
||||
);
|
||||
coo.clear_triplets();
|
||||
assert_eq!(coo.triplet_iter().collect::<Vec<_>>(), vec![]);
|
||||
// making sure everyhting works after clearing
|
||||
coo.push(0, 0, 1);
|
||||
coo.push(0, 0, 2);
|
||||
coo.push(2, 2, 3);
|
||||
assert_eq!(
|
||||
coo.triplet_iter().collect::<Vec<_>>(),
|
||||
vec![(0, 0, &1), (0, 0, &2), (2, 2, &3)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coo_push_out_of_bounds_entries() {
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user