pub struct Matrix { /* private fields */ }Expand description
A simple 2-dimensional matrix with basic operations
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn new(rows: usize, cols: usize) -> Self
pub fn new(rows: usize, cols: usize) -> Self
Creates a new matrix with the given number of rows and columns, initialized to zero.
Sourcepub fn random(rng: &mut StdRng, rows: usize, cols: usize) -> Self
pub fn random(rng: &mut StdRng, 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.
Sourcepub fn random_range(
rng: &mut StdRng,
rows: usize,
cols: usize,
min: f64,
max: f64,
) -> Self
pub fn random_range( rng: &mut StdRng, rows: usize, cols: usize, min: f64, max: f64, ) -> Self
Creates a new matrix with the given number of rows and columns, initialized with random values in the provided half-open range.
Sourcepub fn from_vec(rows: usize, cols: usize, data: Vec<f64>) -> Self
pub fn from_vec(rows: usize, cols: usize, data: 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.
Sourcepub fn from_col_vec(data: Vec<f64>) -> Self
pub fn from_col_vec(data: Vec<f64>) -> Self
Creates a new matrix from a column vector.
Sourcepub fn col(&self, col: usize) -> Vec<f64>
pub fn col(&self, col: usize) -> Vec<f64>
Returns the column at the given index as a vector. Panics if the index is out of bounds.
Sourcepub fn data_mut(&mut self) -> &mut Vec<f64>
pub fn data_mut(&mut self) -> &mut Vec<f64>
Returns a mutable reference to the data in the matrix.
Sourcepub fn get(&self, row: usize, col: usize) -> f64
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.
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> &mut f64
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.
Sourcepub fn set(&mut self, row: usize, col: usize, value: f64)
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.
pub fn apply<F>(&mut self, f: F)
pub fn hadamard_product(&mut self, other: &Matrix)
pub fn multiply_matrix(&self, other: &Matrix) -> Matrix
Trait Implementations§
Source§impl AddAssign<&Matrix> for Matrix
impl AddAssign<&Matrix> for Matrix
Source§fn add_assign(&mut self, other: &Matrix)
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<'de> Deserialize<'de> for Matrix
impl<'de> Deserialize<'de> for Matrix
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl MulAssign<f64> for Matrix
impl MulAssign<f64> for Matrix
Source§fn mul_assign(&mut self, scalar: f64)
fn mul_assign(&mut self, scalar: f64)
Multiplies the matrix by a scalar in-place.
Source§impl SubAssign<&Matrix> for Matrix
impl SubAssign<&Matrix> for Matrix
Source§fn sub_assign(&mut self, other: &Matrix)
fn sub_assign(&mut self, other: &Matrix)
-= operation. Read moreimpl 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 UnsafeUnpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more