Struct Matrix

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

A simple 2-dimensional matrix with basic operations

Implementations§

Source§

impl Matrix

Source

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

Creates a new matrix with the given number of rows and columns, initialized to zero.

Source

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

Creates a new matrix with the given number of rows and columns, initialized with random values between -1.0 and 1.0.

Source

pub fn from_vec(data: Vec<Vec<f64>>) -> Self

Creates a new matrix from a 2D vector. The outer vector represents the rows, and the inner vectors represent the columns. Panics if the inner vectors have different lengths.

Source

pub fn from_col_vec(data: Vec<f64>) -> Self

Creates a new matrix from a column vector.

Source

pub fn transpose(&self) -> Self

Transposes the matrix.

Source

pub fn rows(&self) -> usize

Returns the number of rows in the matrix.

Source

pub fn cols(&self) -> usize

Returns the number of columns in the matrix.

Source

pub fn col(&self, index: usize) -> Vec<f64>

Returns the column at the given index as a vector. Panics if the index is out of bounds.

Source

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

Returns a reference to the data in the matrix.

Source

pub fn data_mut(&mut self) -> &mut Vec<Vec<f64>>

Returns a mutable reference to the data in the matrix.

Source

pub fn get(&self, row: usize, col: usize) -> f64

Returns the value at the given row and column. Panics if the indices are out of bounds.

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> &mut f64

Returns a mutable reference to the value at the given row and column. Panics if the indices are out of bounds.

Source

pub fn set(&mut self, row: usize, col: usize, value: f64)

Sets the value at the given row and column. Panics if the indices are out of bounds.

Source

pub fn map<F>(&self, f: F) -> Matrix
where F: Fn(f64) -> f64,

Returns the matrix resulting from applying the function f to each element of the matrix.

Source

pub fn map_mut<F>(&mut self, f: F)
where F: Fn(f64) -> f64,

Applies the function f to each element of the matrix in place. This is an in-place operation.

Source

pub fn hadamar_product(&mut self, other: &Matrix)

Trait Implementations§

Source§

impl Add<&Matrix> for Matrix

Source§

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

Adds two matrices together, component-wise. Panics if the matrices have different dimensions.

Source§

type Output = Matrix

The resulting type after applying the + operator.
Source§

impl AddAssign<&Matrix> for Matrix

Source§

fn add_assign(&mut self, other: &Matrix)

Adds another matrix to this matrix, component-wise. Panics if the matrices have different dimensions. This is an in-place operation.

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

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

Source§

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

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

impl Mul<&Matrix> for &Matrix

Source§

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

Multiplies two matrices together. Panics if the matrices have incompatible dimensions.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

impl Mul<f64> for Matrix

Source§

fn mul(self, scalar: f64) -> Matrix

Multiplies the matrix by a scalar.

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

impl MulAssign<f64> for Matrix

Source§

fn mul_assign(&mut self, scalar: f64)

Multiplies the matrix by a scalar in-place.

Source§

impl Sub<&Matrix> for Matrix

Source§

fn sub(self, rhs: &Matrix) -> Self::Output

Subtracts another matrix from this matrix, component-wise. Panics if the matrices have different dimensions.

Source§

type Output = Matrix

The resulting type after applying the - operator.

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

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

Source§

fn vzip(self) -> V