pub struct BlockTranspose<const N: usize> { /* private fields */ }Expand description
A representation of 2D data consisting of blocks of tranposes.
The generic parameter N denotes how many rows are in a block.
For example, if the original data is in a row major layout like the following:
a0 a1 a2 a3 ... aK
b0 b1 b2 b3 ... bK
c0 c1 c2 c3 ... cK
d0 d1 d2 d3 ... dK
e0 e1 e2 e3 ... eKand the blocking parameter N = 3, then the blocked-transpose layout (still row major)
will be as follows:
Group Size (3)
<---------->
+----------+ ^
| a0 b0 c0 | |
| a1 b1 c1 | |
| a2 b2 c2 | | Block Size (K + 1)
Block 0 | a3 b3 c3 | |
(Full) | ... | |
| aK bK cK | |
+----------+ v
+----------+
| d0 e0 XX |
| d1 e1 XX |
| d2 e2 XX |
Block 1 | d3 e3 XX |
(Partial) | ... |
| dK eK XX |
+----------+Note the following characteristics:
-
The same dimension of different source rows are store contiguously (this helps with SIMD algorithms).
-
Subsequent groups of the following dimensions are also stored contiguously.
-
Blocks are stored contiguously so all the entire
BlockTransposeconsists of a single allocation. -
Allocation is done at a block-level of granularity with the last block only partially filled if the number of rows does not evenly divide the block-size.
Padding is done as indicated in the diagram. SIMD algorithms are free to load entire rows provided any bookkeeping tracks the partially full status.
Implementations§
Source§impl<const N: usize> BlockTranspose<N>
impl<const N: usize> BlockTranspose<N>
Sourcepub fn new_matrix(nrows: usize, ncols: usize) -> Self
pub fn new_matrix(nrows: usize, ncols: usize) -> Self
Construct a new BlockTranspose sized to contain a matrix of size nrows x ncols.
Data will be zero initialized.
Sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Return the number of physical rows in each data block.
Conceptually, this is the same as the number of columns.
Sourcepub fn group_size(&self) -> usize
pub fn group_size(&self) -> usize
Return the length of each row in a block.
Conceptually, this is the number of source-data rows stored in a block.
Sourcepub const fn const_group_size() -> usize
pub const fn const_group_size() -> usize
Return the length of each row in a block.
Sourcepub fn full_blocks(&self) -> usize
pub fn full_blocks(&self) -> usize
Return the number of completely full data blocks.
This will always be equal to self.nrows() / self.group_size().
Sourcepub fn num_blocks(&self) -> usize
pub fn num_blocks(&self) -> usize
Return the total number of data blocks including any partially full terminal block.
This will always be equal to:
crate::utils::div_round_up(self.nrows(), self.group_size())
Sourcepub fn remainder(&self) -> usize
pub fn remainder(&self) -> usize
Return the number of elements in the last partially full block.
A return value of 0 indicates that all blocks are full.
Sourcepub unsafe fn block_ptr_unchecked(&self, block: usize) -> *const f32
pub unsafe fn block_ptr_unchecked(&self, block: usize) -> *const f32
Return a pointer to the beginning of block.
The caller may assume that for the returned pointer ptr,
[ptr, ptr + self.block_stride()) points to valid memory, even for the remainder
block.
§Safety
Block must be in-bounds (i.e., block < self.num_blocks()).
Sourcepub fn block(&self, block: usize) -> MatrixView<'_, f32>
pub fn block(&self, block: usize) -> MatrixView<'_, f32>
Sourcepub fn remainder_block(&self) -> Option<MatrixView<'_, f32>>
pub fn remainder_block(&self) -> Option<MatrixView<'_, f32>>
Return a view over the remainder block, or None if there is no remainder block.
Sourcepub fn block_mut(&mut self, block: usize) -> MutMatrixView<'_, f32>
pub fn block_mut(&mut self, block: usize) -> MutMatrixView<'_, f32>
Sourcepub fn remainder_block_mut(&mut self) -> Option<MutMatrixView<'_, f32>>
pub fn remainder_block_mut(&mut self) -> Option<MutMatrixView<'_, f32>>
Return a mutable view over the remainder block, or None if there is no remainder block.
Sourcepub fn from_strided(v: StridedView<'_, f32>) -> Self
pub fn from_strided(v: StridedView<'_, f32>) -> Self
Construct a copy of v inside a BlockTranspose.
Sourcepub fn from_matrix_view(v: MatrixView<'_, f32>) -> Self
pub fn from_matrix_view(v: MatrixView<'_, f32>) -> Self
Construct a copy of v inside a BlockTranspose.
Trait Implementations§
Source§impl<const N: usize> Debug for BlockTranspose<N>
impl<const N: usize> Debug for BlockTranspose<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for BlockTranspose<N>
impl<const N: usize> RefUnwindSafe for BlockTranspose<N>
impl<const N: usize> Send for BlockTranspose<N>
impl<const N: usize> Sync for BlockTranspose<N>
impl<const N: usize> Unpin for BlockTranspose<N>
impl<const N: usize> UnwindSafe for BlockTranspose<N>
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
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>
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>
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