Struct Matrix

Source
pub struct Matrix<T> { /* private fields */ }
Expand description

A column‑major 2D matrix of T. Index as Array(row, column).

Implementations§

Source§

impl<T: Clone> Matrix<T>

Source

pub fn from_cols(cols_data: Vec<Vec<T>>) -> Self

Build from columns (each inner Vec is one column)

Source

pub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> Self

Build from a flat Vec, assuming column-major order.

Source

pub fn from_rows_vec(data: Vec<T>, rows: usize, cols: usize) -> Self

Build from a flat Vec, assuming row-major order.

Source

pub fn data(&self) -> &[T]

Source

pub fn data_mut(&mut self) -> &mut [T]

Source

pub fn into_vec(self) -> Vec<T>

Consumes the Matrix and returns its underlying data Vec.

Source

pub fn to_vec(&self) -> Vec<T>

Creates a new Vec<T> containing the matrix data (cloned).

Source

pub fn rows(&self) -> usize

Source

pub fn cols(&self) -> usize

Source

pub fn shape(&self) -> (usize, usize)

Source

pub fn get(&self, r: usize, c: usize) -> &T

Get element reference (immutable). Panics on out-of-bounds.

Source

pub fn get_mut(&mut self, r: usize, c: usize) -> &mut T

Get element reference (mutable). Panics on out-of-bounds.

Source

pub fn column(&self, c: usize) -> &[T]

Source

pub fn column_mut(&mut self, c: usize) -> &mut [T]

Source

pub fn iter_columns(&self) -> impl Iterator<Item = &[T]>

Source

pub fn iter_rows(&self) -> impl Iterator<Item = MatrixRow<'_, T>>

Source

pub fn swap_columns(&mut self, c1: usize, c2: usize)

Swaps two columns in the matrix. Panics on out-of-bounds.

Source

pub fn delete_column(&mut self, col: usize)

Deletes a column from the matrix. Panics on out-of-bounds. This is O(N) where N is the number of elements.

Source

pub fn row(&self, r: usize) -> Vec<T>

Source

pub fn row_copy_from_slice(&mut self, r: usize, values: &[T])

Source

pub fn delete_row(&mut self, row: usize)

Deletes a row from the matrix. Panics on out-of-bounds. This is O(N) where N is the number of elements, as it rebuilds the data vec.

Source

pub fn transpose(&self) -> Matrix<T>

Source§

impl<T: Clone> Matrix<T>

Source

pub fn add_column(&mut self, index: usize, column: Vec<T>)

Adds a column to the matrix at the specified index. Panics if index > cols or length mismatch. This is O(N) where N is the number of elements.

Source

pub fn add_row(&mut self, index: usize, row: Vec<T>)

Adds a row to the matrix at the specified index. Panics if index > rows or length mismatch. This is O(N) where N is the number of elements, as it rebuilds the data vec.

Source

pub fn repeat_rows(&self, n: usize) -> Matrix<T>
where T: Clone,

Return a new matrix where row 0 of self is repeated n times.

Source

pub fn filled(rows: usize, cols: usize, value: T) -> Self

Creates a new matrix filled with a specific value of the specified size.

Source

pub fn broadcast_row_to_target_shape( &self, target_rows: usize, target_cols: usize, ) -> Matrix<T>

Creates a new matrix by broadcasting a 1-row matrix to a target shape. Panics if self is not a 1-row matrix or if self.cols() does not match target_cols.

Source§

impl Matrix<f64>

Source

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

Creates a new matrix filled with zeros of the specified size.

Source

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

Creates a new matrix filled with ones of the specified size.

Source

pub fn nan(rows: usize, cols: usize) -> Matrix<f64>

Creates a new matrix filled with NaN values of the specified size.

Source§

impl<T: PartialOrd + Clone> Matrix<T>

Source

pub fn eq_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self == rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Source

pub fn ne_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self != rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Source

pub fn lt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self < rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Source

pub fn le_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self <= rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Source

pub fn gt_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self > rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Source

pub fn ge_elem<Rhs>(&self, rhs: Rhs) -> BoolMatrix
where Rhs: Broadcastable<T>,

Element-wise comparison self >= rhs, where rhs may be a Matrix<T> or a scalar T. Returns a BoolMatrix.

Trait Implementations§

Source§

impl<'a, 'b, T> Add<&'b Matrix<T>> for &'a Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<'b, T> Add<&'b Matrix<T>> for Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<Matrix<T>> for &'a Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<T>) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<T> for &'a Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<T> Add<T> for Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<T> Add for Matrix<T>
where T: Clone + Add<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<T>) -> Matrix<T>

Performs the + operation. Read more
Source§

impl<'a, 'b> BitAnd<&'b Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the & operation. Read more
Source§

impl<'b> BitAnd<&'b Matrix<bool>> for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the & operation. Read more
Source§

impl<'a> BitAnd<Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the & operation. Read more
Source§

impl BitAnd for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the & operation. Read more
Source§

impl<'a, 'b> BitOr<&'b Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the | operation. Read more
Source§

impl<'b> BitOr<&'b Matrix<bool>> for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the | operation. Read more
Source§

impl<'a> BitOr<Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the | operation. Read more
Source§

impl BitOr for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the | operation. Read more
Source§

impl<'a, 'b> BitXor<&'b Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the ^ operation. Read more
Source§

impl<'b> BitXor<&'b Matrix<bool>> for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &'b Matrix<bool>) -> Matrix<bool>

Performs the ^ operation. Read more
Source§

impl<'a> BitXor<Matrix<bool>> for &'a Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the ^ operation. Read more
Source§

impl BitXor for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Matrix<bool>) -> Matrix<bool>

Performs the ^ operation. Read more
Source§

impl<T: Clone> Broadcastable<T> for Matrix<T>

Source§

fn to_vec(&self, rows: usize, cols: usize) -> Vec<T>

Source§

impl<T: Clone> Clone for Matrix<T>

Source§

fn clone(&self) -> Matrix<T>

Returns a copy 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<T: Debug> Debug for Matrix<T>

Source§

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

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

impl<'a, 'b, T> Div<&'b Matrix<T>> for &'a Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<'b, T> Div<&'b Matrix<T>> for Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<'a, T> Div<Matrix<T>> for &'a Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Matrix<T>) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<'a, T> Div<T> for &'a Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<T> Div<T> for Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<T> Div for Matrix<T>
where T: Clone + Div<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Matrix<T>) -> Matrix<T>

Performs the / operation. Read more
Source§

impl<T> Index<(usize, usize)> for Matrix<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, (r, c): (usize, usize)) -> &T

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

impl<T> IndexMut<(usize, usize)> for Matrix<T>

Source§

fn index_mut(&mut self, (r, c): (usize, usize)) -> &mut T

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

impl<'a, 'b, T> Mul<&'b Matrix<T>> for &'a Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the * operation. Read more
Source§

impl<'b, T> Mul<&'b Matrix<T>> for Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<Matrix<T>> for &'a Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<T>) -> Matrix<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<T> for &'a Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Matrix<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Matrix<T>

Performs the * operation. Read more
Source§

impl<T> Mul for Matrix<T>
where T: Clone + Mul<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<T>) -> Matrix<T>

Performs the * operation. Read more
Source§

impl Not for &Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Matrix<bool>

Performs the unary ! operation. Read more
Source§

impl Not for Matrix<bool>

Source§

type Output = Matrix<bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Matrix<bool>

Performs the unary ! operation. Read more
Source§

impl<T: PartialEq> PartialEq for Matrix<T>

Source§

fn eq(&self, other: &Matrix<T>) -> 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<'a, 'b, T> Sub<&'b Matrix<T>> for &'a Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<'b, T> Sub<&'b Matrix<T>> for Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'b Matrix<T>) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<Matrix<T>> for &'a Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<T>) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<T> for &'a Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<T> Sub<T> for Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<T> Sub for Matrix<T>
where T: Clone + Sub<Output = T>,

Source§

type Output = Matrix<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<T>) -> Matrix<T>

Performs the - operation. Read more
Source§

impl<T: Eq> Eq for Matrix<T>

Source§

impl<T> StructuralPartialEq for Matrix<T>

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>

§

impl<T> RefUnwindSafe for Matrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for Matrix<T>
where T: Send,

§

impl<T> Sync for Matrix<T>
where T: Sync,

§

impl<T> Unpin for Matrix<T>
where T: Unpin,

§

impl<T> UnwindSafe for Matrix<T>
where T: UnwindSafe,

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> Broadcastable<T> for T
where T: Clone,

Source§

fn to_vec(&self, rows: usize, cols: usize) -> Vec<T>

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, 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.