pub struct Matrix {
pub data: Vec<f64>,
pub rows: usize,
pub cols: usize,
}Expand description
A dense row-major matrix of f64 values.
Data is stored in a flat Vec<f64> of length rows * cols.
§Examples
use pc_rl_core::matrix::Matrix;
let m = Matrix::zeros(2, 3);
assert_eq!(m.rows, 2);
assert_eq!(m.cols, 3);Fields§
§data: Vec<f64>Flat row-major storage.
rows: usizeNumber of rows.
cols: usizeNumber of columns.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn xavier(rows: usize, cols: usize, rng: &mut impl Rng) -> Self
pub fn xavier(rows: usize, cols: usize, rng: &mut impl Rng) -> Self
Creates a matrix with Xavier-uniform initialization.
Elements are drawn uniformly from [-limit, limit] where
limit = sqrt(6.0 / (rows + cols)).
§Arguments
rows- Number of rows.cols- Number of columns.rng- Mutable reference to a random number generator.
§Returns
A Matrix with Xavier-initialized values.
Sourcepub fn get(&self, row: usize, col: usize) -> f64
pub fn get(&self, row: usize, col: usize) -> f64
Returns the element at (row, col).
Defaults to 0.0 if indices are out of bounds.
§Arguments
row- Row index.col- Column index.
Sourcepub fn set(&mut self, row: usize, col: usize, val: f64)
pub fn set(&mut self, row: usize, col: usize, val: f64)
Sets the element at (row, col) to val.
Does nothing if indices are out of bounds.
§Arguments
row- Row index.col- Column index.val- Value to set.
Trait Implementations§
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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more