Matrix2D

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>

pub fn empty() -> Self

Construct an empty matrix (0 × 0).

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>

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 rows(&self) -> usize

Number of rows.

pub fn cols(&self) -> usize

Number of columns.

pub fn as_flat_slice(&self) -> &[T]

Flat backing buffer (row-major).

pub fn as_mut_flat_slice(&mut self) -> &mut [T]

Mutable flat backing buffer (row-major).

pub fn len(&self) -> usize

Number of elements (rows * cols).

pub fn is_empty(&self) -> bool

True when the backing buffer is empty.

pub fn iter(&self) -> Iter<'_, T>

Iterate the flat backing buffer.

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Iterate the flat backing buffer mutably.

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]> + '_

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.

pub fn get(&self, row: usize, col: usize) -> Option<&T>

Element at (row, col) if in bounds.

pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>

Mutable element at (row, col) if in bounds.

pub fn row(&self, row: usize) -> Option<&[T]>

Contiguous row slice.

pub fn row_mut(&mut self, row: usize) -> Option<&mut [T]>

Contiguous mutable row slice.

§

impl<T: Clone> Matrix2D<T>

pub fn to_rows(&self) -> Vec<Vec<T>>

Materialize as Vec<Vec<T>> for callers that expect the nested form.

pub fn resize(&mut self, rows: usize, cols: usize, value: T)

Reset shape and fill every cell with value.

Trait Implementations§

§

impl<T: Clone> Clone for Matrix2D<T>

§

fn clone(&self) -> Matrix2D<T>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T: Debug> Debug for Matrix2D<T>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl<T> Index<(usize, usize)> for Matrix2D<T>

§

type Output = T

The returned type after indexing.
§

fn index(&self, index: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
§

impl<T> IndexMut<(usize, usize)> for Matrix2D<T>

§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoEither for T

§

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 more
§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,