diff options
Diffstat (limited to 'src/matrix.rs')
-rw-r--r-- | src/matrix.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/matrix.rs b/src/matrix.rs index 9227917..bd6b38f 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -11,17 +11,21 @@ //! ``` //! TODO:: Create matrix multiplication method -use std::{fmt::Display, ops::{Add, Mul, Sub}, str::FromStr}; +use std::{ + fmt::Display, + ops::{Add, Mul, Sub}, + str::FromStr, +}; use crate::error::{MatrixSetValueError, ParseMatrixError}; #[derive(Debug, PartialEq, Eq)] pub struct Matrix { /// Number of rows in matrix. pub nrows: usize, - + /// Number of columns in matrix. pub ncols: usize, - + /// Data stored in the matrix, you should not access this directly data: Vec<Vec<i32>>, } @@ -121,7 +125,6 @@ impl Matrix { } } } - impl FromStr for Matrix { type Err = ParseMatrixError; fn from_str(s: &str) -> Result<Self, Self::Err> { @@ -188,7 +191,7 @@ impl<'a, 'b> Sub<&'b Matrix> for &'a Matrix { fn sub(self, rhs: &'b Matrix) -> Self::Output { todo!() } - } +} impl<'a, 'b> Mul<&'b Matrix> for &'a Matrix { type Output = Matrix; fn mul(self, rhs: &'b Matrix) -> Self::Output { @@ -221,8 +224,7 @@ impl From<Vec<i32>> for Matrix { Matrix { nrows: value.len(), ncols: 1, - data: vec![value], + data: value.iter().map(|v| vec![*v]).collect(), } } } - |