diff --git a/src/matrix/mat.rs b/src/matrix/mat.rs index dbae21a..c7b0893 100644 --- a/src/matrix/mat.rs +++ b/src/matrix/mat.rs @@ -89,6 +89,10 @@ impl Matrix { self.cols } + pub fn shape(&self) -> (usize, usize) { + (self.rows, self.cols) + } + /// Get element reference (immutable). Panics on out-of-bounds. pub fn get(&self, r: usize, c: usize) -> &T { &self[(r, c)] @@ -1153,6 +1157,14 @@ mod tests { assert_eq!(ma.row(2), &[3, 6, 9]); } + #[test] + fn test_shape(){ + let ma = static_test_matrix_2x4(); + assert_eq!(ma.shape(), (2, 4)); + assert_eq!(ma.rows(), 2); + assert_eq!(ma.cols(), 4); + } + #[test] #[should_panic(expected = "row index 3 out of bounds for 3 rows")] fn test_row_out_of_bounds() {