Skip to main content

BlockTranspose

Struct BlockTranspose 

Source
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 ... eK

and 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 BlockTranspose consists 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>

Source

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.

Source

pub fn nrows(&self) -> usize

Return the number of rows of data stored in self.

Source

pub fn ncols(&self) -> usize

Return the number of columns in each rows of the data in self.

Source

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.

Source

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.

Source

pub const fn const_group_size() -> usize

Return the length of each row in a block.

Source

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().

Source

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())

Source

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.

Source

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()).

Source

pub fn as_ptr(&self) -> *const f32

Return a pointer to the start of data segment.

Source

pub fn block(&self, block: usize) -> MatrixView<'_, f32>

Return a view over a full block.

§Panics

Panics if block >= self.full_blocks().

Source

pub fn remainder_block(&self) -> Option<MatrixView<'_, f32>>

Return a view over the remainder block, or None if there is no remainder block.

Source

pub fn block_mut(&mut self, block: usize) -> MutMatrixView<'_, f32>

Return a mutable view over a full block.

§Panics

Panics if block >= self.full_blocks().

Source

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.

Source

pub fn from_strided(v: StridedView<'_, f32>) -> Self

Construct a copy of v inside a BlockTranspose.

Source

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>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Index<(usize, usize)> for BlockTranspose<N>

Source§

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

Return a reference the the element at the logical (row, col).

§Panics

Panics if row >= self.nrows() or col >= self.ncols().

Source§

type Output = f32

The returned type after indexing.

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> UnsafeUnpin for BlockTranspose<N>

§

impl<const N: usize> UnwindSafe for BlockTranspose<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

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

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,