addition: funtion for addign columns and rows
This commit is contained in:
33
src/lib.rs
33
src/lib.rs
@@ -157,13 +157,14 @@ impl Matrix {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn add_column(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
pub fn append_column(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
if data.len() != self.columns {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
|
||||
for i in 0..data.len() {
|
||||
self.data.insert((i * self.rows) + self.rows - 1, data[i]);
|
||||
self.data
|
||||
.insert((i * self.rows) + self.rows + i - 1, data[i]);
|
||||
}
|
||||
|
||||
self.columns += 1;
|
||||
@@ -171,7 +172,7 @@ impl Matrix {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn add_row(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
pub fn append_row(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
if data.len() != self.rows {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
@@ -185,6 +186,32 @@ impl Matrix {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn pop_column(&mut self) -> Option<MatrixError> {
|
||||
if self.columns <= 1 {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
|
||||
for i in 0..self.columns {
|
||||
self.data.remove((i * self.rows) + self.rows - i - 1);
|
||||
}
|
||||
|
||||
self.columns -= 1;
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn pop_row(&mut self) -> Option<MatrixError> {
|
||||
if self.rows <= 1 {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
|
||||
for _i in 0..self.rows {
|
||||
self.data.pop();
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn partial_pivoting(&mut self, col: usize, sign: &mut Fraction) -> Result<bool, MatrixError> {
|
||||
if col >= self.columns {
|
||||
return Err(MatrixError::ColumnOutOfRange);
|
||||
|
||||
Reference in New Issue
Block a user