Matrix

Struct Matrix 

Source
pub struct Matrix(/* private fields */);
Expand description

A matrix (in the linear algebra sense) of rational numbers.

Implementations§

Source§

impl Matrix

Source

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.

Source

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.

Source

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.

Source

pub fn zeros(rows: usize, cols: usize) -> Self

Source

pub fn empty() -> Self

Source

pub fn rref(&mut self)

Puts the matrix into Reduced Row Echelon Form.

Source

pub fn ref(&mut self)

Puts the matrix into (unreduced) Row Echelon Form.

Source

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],
    ])
);
Source

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.

Source

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]])
);
Source

pub fn normalize(&mut self)

Divides rows to ensure that each leader is 1.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Source

pub fn matrix_mul(&self, rhs: &Self) -> Result<Self>

Implements matrix multiplication. Returns errors if the two matrices are incorrect sizes for multiplication.

Source

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.

Source

pub fn remove_row(&mut self, i: usize)

Remove row i from the Matrix.

Source

pub fn height(&self) -> usize

Source

pub fn width(&self) -> usize

Source

pub fn iter(&self) -> impl Iterator<Item = &RowVec>

Returns an iterator over rows of the Matrix.

Source

pub fn is_zeros(&self) -> bool

Source

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 Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<(usize, usize)> for Matrix

Source§

type Output = Ratio<i64>

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for Matrix

Source§

type Output = RowVec

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<(usize, usize)> for Matrix

Source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Matrix

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoIterator for Matrix

Source§

type Item = RowVec

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Matrix as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Mul<Ratio<i64>> for Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: R64) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<Ratio<i64>> for Matrix

Source§

fn mul_assign(&mut self, rhs: R64)

Performs the *= operation. Read more
Source§

impl PartialEq for Matrix

Source§

fn eq(&self, other: &Matrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Matrix

Auto Trait Implementations§

§

impl Freeze for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnwindSafe for Matrix

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.