Added len function to Matrix
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 0.2.1 (unreleased)
|
||||
|
||||
- Added `len` function to `Matrix`
|
||||
|
||||
## 0.2.0 (2021-10-17)
|
||||
|
||||
- Added support for Windows
|
||||
|
||||
@@ -23,6 +23,10 @@ impl Matrix {
|
||||
self.data.push(MfNode { u: row_index, v: column_index, r: value });
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
pub(crate) fn to_problem(&self) -> MfProblem {
|
||||
let data = &self.data;
|
||||
let m = data.iter().map(|x| x.u).max().unwrap_or(-1) + 1;
|
||||
@@ -52,4 +56,12 @@ mod tests {
|
||||
let mut data = Matrix::with_capacity(1);
|
||||
data.push(0, 0, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_len() {
|
||||
let mut data = Matrix::new();
|
||||
assert_eq!(data.len(), 0);
|
||||
data.push(0, 0, 1.0);
|
||||
assert_eq!(data.len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user