pub struct Matrix<T> { /* private fields */ }Expand description
A dense 2D matrix in row-major layout.
Access elements with m[[row, col]] syntax. Data is stored contiguously
in row-major order.
§Examples
use tensor4all_tcicore::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_raw_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
pub fn from_raw_vec(nrows: usize, ncols: usize, data: Vec<T>) -> Self
Create a matrix from raw row-major data.
§Panics
Panics if data.len() != nrows * ncols.
§Examples
use tensor4all_tcicore::Matrix;
let m = Matrix::from_raw_vec(2, 2, vec![1.0, 2.0, 3.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);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§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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>,
§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