Struct Matrix2D
pub struct Matrix2D<T> { /* private fields */ }Expand description
Flat row-major 2D matrix.
Storage is a single Vec<T> of length rows * cols, indexed
row * cols + col. Per-row access via Matrix2D::row is a contiguous
slice; column access requires a strided walk.
Implementations§
§impl<T> Matrix2D<T>
impl<T> Matrix2D<T>
pub fn empty() -> Self
pub fn empty() -> Self
Construct an empty matrix (0 × 0).
pub fn from_flat(data: Vec<T>, rows: usize, cols: usize) -> Result<Self>
pub fn from_flat(data: Vec<T>, rows: usize, cols: usize) -> Result<Self>
Construct from a row-major flat buffer.
§Errors
WaveletError::InvalidLength when data.len() != rows * cols.
pub fn from_rows(rows_in: Vec<Vec<T>>) -> Result<Self>
pub fn from_rows(rows_in: Vec<Vec<T>>) -> Result<Self>
Construct from a Vec<Vec<T>>. All inner rows must have equal length.
An empty outer vector yields an empty matrix.
§Errors
WaveletError::InvalidLength when row lengths are not uniform.
pub fn as_flat_slice(&self) -> &[T]
pub fn as_flat_slice(&self) -> &[T]
Flat backing buffer (row-major).
pub fn as_mut_flat_slice(&mut self) -> &mut [T]
pub fn as_mut_flat_slice(&mut self) -> &mut [T]
Mutable flat backing buffer (row-major).
pub fn iter_rows(&self) -> impl ExactSizeIterator<Item = &[T]> + '_
pub fn iter_rows(&self) -> impl ExactSizeIterator<Item = &[T]> + '_
Iterate rows as contiguous slices. Yields exactly Matrix2D::rows
items — including rows empty slices when cols == 0.
Each yielded slice goes through a bounds-checked &data[start..end],
which costs ~1 ns per row vs Vec<Vec>::iter walking pointers
(measurable on bench cwt/energy_by_scale/256 as +4 %). For any
consumer doing real work per row the cost vanishes; only worth
revisiting (e.g. via an unsafe { get_unchecked } path) if a SIMD
kernel ever loops this iterator with nanosecond-scale per-row work.
pub fn iter_rows_mut(&mut self) -> impl Iterator<Item = &mut [T]> + '_
pub fn iter_rows_mut(&mut self) -> impl Iterator<Item = &mut [T]> + '_
Iterate rows mutably. Yields exactly Matrix2D::rows items —
including rows empty slices when cols == 0. Not
ExactSizeIterator (the underlying std::iter::from_fn adapter
can’t carry the length); use Matrix2D::rows for the count.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Matrix2D<T>
impl<T> RefUnwindSafe for Matrix2D<T>where
T: RefUnwindSafe,
impl<T> Send for Matrix2D<T>where
T: Send,
impl<T> Sync for Matrix2D<T>where
T: Sync,
impl<T> Unpin for Matrix2D<T>where
T: Unpin,
impl<T> UnwindSafe for Matrix2D<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T> IntoEither for T
impl<T> IntoEither for T
§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 more§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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.