pub struct Matrix(/* private fields */);Expand description
A matrix (in the linear algebra sense) of rational numbers.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn new(m: Vec<Vec<R64>>) -> Self
pub fn new(m: Vec<Vec<R64>>) -> Self
The caller is responsible for making sure the input is valid, meaning that no rows are empty, and each row is the same size. Failing to do so could lead to undefined behaviour or panics later on.
Sourcepub fn from_row_vecs(m: Vec<RowVec>) -> Self
pub fn from_row_vecs(m: Vec<RowVec>) -> Self
The caller is responsible for making sure the input is valid, meaning that no rows are empty, and each row is the same size. Failing to do so could lead to undefined behaviour or panics later on.
Sourcepub fn from_int_vecs(m: Vec<Vec<i64>>) -> Self
pub fn from_int_vecs(m: Vec<Vec<i64>>) -> Self
The caller is responsible for making sure the input is valid, meaning that no rows are empty, and each row is the same size. Failing to do so could lead to undefined behaviour or panics later on.
pub fn zeros(rows: usize, cols: usize) -> Self
pub fn empty() -> Self
Sourcepub fn leader_sort(&mut self)
pub fn leader_sort(&mut self)
Sort the rows of the matrix such the ones with the leftmost leaders (ie, leftmost non-zero entries) come first. All-zero rows are at the bottom.
use aoclib_rs::matrix::Matrix;
let mut m = Matrix::from_int_vecs(vec![
vec![0, 2, 3, 4],
vec![2, 3, 6, 3],
vec![0, 0, 4, 5],
vec![0, 0, 0, 3],
vec![0, 5, 6, 3],
vec![0, 0, 0, 0],
vec![3, 4, 2, 6],
]);
m.leader_sort();
assert_eq!(
m,
Matrix::from_int_vecs(vec![
vec![2, 3, 6, 3],
vec![3, 4, 2, 6],
vec![0, 2, 3, 4],
vec![0, 5, 6, 3],
vec![0, 0, 4, 5],
vec![0, 0, 0, 3],
vec![0, 0, 0, 0],
])
);Sourcepub fn eliminate_below_leader(&mut self, row: usize)
pub fn eliminate_below_leader(&mut self, row: usize)
Perform a step in row reduction by eliminating the entries in the same column as row’s
leader for all rows below row.
Sourcepub fn eliminate(
&mut self,
selected_row: usize,
other_row: usize,
leader_col: usize,
)
pub fn eliminate( &mut self, selected_row: usize, other_row: usize, leader_col: usize, )
Perform a step in row reduction by eliminating the other_row entry corresponding to
leader_col (which is the column of the leader in selected_row).
use aoclib_rs::matrix::Matrix;
let mut m = Matrix::from_int_vecs(vec![vec![0, 2, 3, 4], vec![2, 4, 6, 3]]);
m.eliminate(0, 1, 1);
assert_eq!(
m,
Matrix::from_int_vecs(vec![vec![0, 2, 3, 4], vec![2, 0, 0, -5]])
);Sourcepub fn eliminate_above_leader(&mut self, row: usize)
pub fn eliminate_above_leader(&mut self, row: usize)
Perform a step in row reduction by eliminating the entries in the same column as row’s
leader for all rows above row.
Sourcepub fn add_assign(&mut self, rhs: &Self) -> Result<()>
pub fn add_assign(&mut self, rhs: &Self) -> Result<()>
Implements a “+=” operation (without actually defining the operator) which returns an error
if the 2 Matrixes are of different sizes.
Sourcepub fn add(&self, rhs: &Self) -> Result<Self>
pub fn add(&self, rhs: &Self) -> Result<Self>
Implements a “+” operation (without actually defining the operator) which returns an error
if the 2 Matrixes are of different sizes.
pub fn is_empty(&self) -> bool
Sourcepub fn matrix_mul(&self, rhs: &Self) -> Result<Self>
pub fn matrix_mul(&self, rhs: &Self) -> Result<Self>
Implements matrix multiplication. Returns errors if the two matrices are incorrect sizes for multiplication.
Sourcepub fn append_row(&mut self, r: RowVec)
pub fn append_row(&mut self, r: RowVec)
Appends a RowVec to the bottom of the matrix. Note that the caller is responsible for
ensuring the RowVec is the correct size. Appending RowVecs of the wrong size could lead to
undefined behaviour or panics later on.
Sourcepub fn remove_row(&mut self, i: usize)
pub fn remove_row(&mut self, i: usize)
Remove row i from the Matrix.
pub fn height(&self) -> usize
pub fn width(&self) -> usize
Sourcepub fn iter(&self) -> impl Iterator<Item = &RowVec>
pub fn iter(&self) -> impl Iterator<Item = &RowVec>
Returns an iterator over rows of the Matrix.
pub fn is_zeros(&self) -> bool
Sourcepub fn get_column_copy(&self, c: usize) -> Self
pub fn get_column_copy(&self, c: usize) -> Self
Returns a new matrix with a single column whose contents are a copy of a column c from
the original matrix.
Trait Implementations§
Source§impl IntoIterator for Matrix
impl IntoIterator for Matrix
Source§impl MulAssign<Ratio<i64>> for Matrix
impl MulAssign<Ratio<i64>> for Matrix
Source§fn mul_assign(&mut self, rhs: R64)
fn mul_assign(&mut self, rhs: R64)
*= operation. Read more