pub struct Strided<'a, T> { /* private fields */ }Expand description
A row-major strided matrix.
This is a generalization of the Matrix trait as it does not mandate a dense
layout in memory.
|<------ cstride ----->|
|<-- ncols -->|
+-------------+
slice 0 -> a0 a1 a2 | a3 a4 a5 a6 | ^
slice 1 -> b0 b1 b2 | b3 b4 b4 b5 | |
slice 2 -> c0 c1 c2 | c3 c4 c5 c6 | nrows
slice 3 -> d0 d1 d2 | d3 d4 d5 d6 | |
slice 4 -> e0 e1 e2 | e3 e4 e5 e6 | |
slice 5 -> f0 f1 f2 | f3 f4 f5 f6 | v
+-------------+
^
|
StridedThis abstraction is useful when performing PQ related operations such as training or compression as it provides a convenient abstraction for working with columnar subsets of dense data in-place.
Implementations§
Source§impl<'a, T> Strided<'a, T>
impl<'a, T> Strided<'a, T>
Sourcepub fn try_from_data(
data: &'a [T],
nrows: usize,
ncols: usize,
cstride: usize,
) -> Result<Self, TryFromError>
pub fn try_from_data( data: &'a [T], nrows: usize, ncols: usize, cstride: usize, ) -> Result<Self, TryFromError>
Construct a strided view over data slice, shrinking the slice as needed.
Returns an error if the layout is invalid or data is not at least
Layout::linear_length.
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Return the underlying data as a slice.
§Note
The underlying representation for a strided matrix is not necessarily dense.
Sourcepub unsafe fn element_unchecked(&self, row: usize, col: usize) -> &T
pub unsafe fn element_unchecked(&self, row: usize, col: usize) -> &T
Sourcepub fn get_element(&self, row: usize, col: usize) -> Option<&T>
pub fn get_element(&self, row: usize, col: usize) -> Option<&T>
Return the specified element if row < self.nrows() and col < self.ncols().
Sourcepub unsafe fn row_unchecked(&self, row: usize) -> &[T]
pub unsafe fn row_unchecked(&self, row: usize) -> &[T]
Sourcepub fn get_row(&self, row: usize) -> Option<&[T]>
pub fn get_row(&self, row: usize) -> Option<&[T]>
Return the requested row if row < self.nrows().
Trait Implementations§
impl<T> Copy for Strided<'_, T>
impl<T> Send for Strided<'_, T>where
T: Sync,
impl<T> Sync for Strided<'_, T>where
T: Sync,
Auto Trait Implementations§
impl<'a, T> Freeze for Strided<'a, T>
impl<'a, T> RefUnwindSafe for Strided<'a, T>
impl<'a, T> Unpin for Strided<'a, T>
impl<'a, T> UnsafeUnpin for Strided<'a, T>
impl<'a, T> UnwindSafe for Strided<'a, T>
Blanket Implementations§
impl<T> AsyncFriendly for T
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,
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