pub struct Matrix<T> { /* private fields */ }Expand description
A dense 2D matrix in column-major layout.
Access elements with m[[row, col]] syntax. Data is stored contiguously
in column-major order, so flat buffers use row + nrows * col.
§Examples
use tensor4all_tensorbackend::Matrix;
let mut m = Matrix::zeros(2, 3);
m[[0, 1]] = 5.0_f64;
assert_eq!(m[[0, 1]], 5.0);
assert_eq!(m[[0, 0]], 0.0);
assert_eq!(m.nrows(), 2);
assert_eq!(m.ncols(), 3);Implementations§
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn from_col_major_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
pub fn from_col_major_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
Create a matrix from raw column-major data.
§Panics
Panics if data.len() != nrows * ncols.
§Examples
use tensor4all_tensorbackend::Matrix;
let m = Matrix::from_col_major_vec(2, 2, vec![1.0, 3.0, 2.0, 4.0]);
assert_eq!(m[[0, 0]], 1.0);
assert_eq!(m[[0, 1]], 2.0);
assert_eq!(m[[1, 0]], 3.0);
assert_eq!(m[[1, 1]], 4.0);Sourcepub fn as_col_major_slice(&self) -> &[T]
pub fn as_col_major_slice(&self) -> &[T]
View the underlying column-major data as a contiguous slice.
§Examples
use tensor4all_tensorbackend::Matrix;
let m = Matrix::from_col_major_vec(2, 2, vec![1, 3, 2, 4]);
assert_eq!(m.as_col_major_slice(), &[1, 3, 2, 4]);Trait Implementations§
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> UnsafeUnpin for Matrix<T>
impl<T> UnwindSafe for Matrix<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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>
Converts
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>
Converts
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