Skip to main content

Matrix

Struct Matrix 

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

A simple matrix struct storing data in row-major format

Implementations§

Source§

impl Matrix

Source

pub fn new(data: Vec<Vec<f64>>) -> Result<Self, String>

Create a new matrix from a vector of vectors

Source

pub fn rows(&self) -> usize

Get the number of rows

Source

pub fn cols(&self) -> usize

Get the number of columns

Source

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

Get the shape as (rows, cols)

Source

pub fn data(&self) -> &Vec<Vec<f64>>

Get a reference to the underlying data

Source

pub fn get(&self, i: usize, j: usize) -> Option<f64>

Get the element at position (i, j)

Source

pub fn add(&self, other: &Matrix) -> Result<Matrix, String>

Matrix addition

Source

pub fn sub(&self, other: &Matrix) -> Result<Matrix, String>

Matrix subtraction

Source

pub fn scalar_mul(&self, scalar: f64) -> Result<Matrix, String>

Scalar multiplication

Source

pub fn mul(&self, other: &Matrix) -> Result<Matrix, String>

Matrix multiplication

Source

pub fn determinant(&self) -> Result<f64, String>

Calculate determinant using cofactor expansion

Source

pub fn is_square(&self) -> bool

Check if matrix is square

Source

pub fn is_invertible(&self) -> Result<bool, String>

Check if matrix is invertible

Source

pub fn inverse(&self) -> Result<Matrix, String>

Calculate matrix inverse using adjugate method

Source

pub fn transpose(&self) -> Result<Matrix, String>

Transpose the matrix

Source

pub fn frobenius_norm(&self) -> f64

Calculate the Frobenius norm

Source

pub fn trace(&self) -> Result<f64, String>

Calculate the trace (sum of diagonal elements)

Source

pub fn identity(n: usize) -> Result<Matrix, String>

Create an identity matrix of size n×n

Source

pub fn zeros(rows: usize, cols: usize) -> Result<Matrix, String>

Create a zero matrix of size rows×cols

Source

pub fn ones(rows: usize, cols: usize) -> Result<Matrix, String>

Create a matrix of ones

Trait Implementations§

Source§

impl Add for &Matrix

Source§

type Output = Result<Matrix, String>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Matrix) -> Result<Matrix, String>

Performs the + operation. Read more
Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 = f64

The returned type after indexing.
Source§

fn index(&self, (i, j): (usize, usize)) -> &f64

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

impl Mul for &Matrix

Source§

type Output = Result<Matrix, String>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Matrix) -> Result<Matrix, String>

Performs the * operation. Read more
Source§

impl Sub for &Matrix

Source§

type Output = Result<Matrix, String>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Matrix) -> Result<Matrix, String>

Performs the - operation. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V