Skip to main content

Repr

Trait Repr 

Source
pub unsafe trait Repr: Copy {
    type Row<'a>
       where Self: 'a;

    // Required methods
    fn nrows(&self) -> usize;
    fn layout(&self) -> Result<Layout, LayoutError>;
    unsafe fn get_row<'a>(self, ptr: NonNull<u8>, i: usize) -> Self::Row<'a>;
}
Expand description

Representation trait describing the layout and access patterns for a matrix.

Implementations define how raw bytes are interpreted as typed rows. This enables matrices over different storage formats (dense, quantized, etc.) using a single generic Mat type.

§Associated Types

  • Row<'a>: The immutable row type (e.g., &[f32], &[f16]).

§Safety

Implementations must ensure:

  • get_row returns valid references for the given row index. This call must be memory safe for i < self.nrows(), provided the caller upholds the contract for the raw pointer.

  • The objects implicitly managed by this representation inherit the Send and Sync attributes of Repr. That is, Repr: Send implies that the objects in backing memory are Send, and likewise with Sync. This is necessary to apply Send and Sync bounds to Mat, MatRef, and MatMut.

Required Associated Types§

Source

type Row<'a> where Self: 'a

Immutable row reference type.

Required Methods§

Source

fn nrows(&self) -> usize

Returns the number of rows in the matrix.

§Safety Contract

This function must be loosely pure in the sense that for any given instance of self, self.nrows() must return the same value.

Source

fn layout(&self) -> Result<Layout, LayoutError>

Returns the memory layout for a memory allocation containing Repr::nrows vectors each with vector dimension [Repr::ncols].

§Safety Contract

The Layout returned from this method must be consistent with the contract of Repr::get_row.

Source

unsafe fn get_row<'a>(self, ptr: NonNull<u8>, i: usize) -> Self::Row<'a>

Returns an immutable reference to the i-th row.

§Safety
  • ptr must point to a slice with a layout compatible with Repr::layout.
  • The entire range for this slice must be within a single allocation.
  • i must be less than Repr::nrows.
  • The memory referenced by the returned Repr::Row must not be mutated for the duration of lifetime 'a.
  • The lifetime for the returned Repr::Row is inferred from its usage. Correct usage must properly tie the lifetime to a source.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Copy> Repr for Standard<T>

Source§

type Row<'a> = &'a [T] where T: 'a

Source§

impl<const NBITS: usize> Repr for MinMaxMeta<NBITS>
where Unsigned: Representation<NBITS>,

Source§

type Row<'a> = VectorBase<NBITS, Unsigned, SlicePtr<'a, u8>, Ref<'a, MinMaxCompensation>>