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_rowreturns valid references for the given row index. This call must be memory safe fori < self.nrows(), provided the caller upholds the contract for the raw pointer. -
The objects implicitly managed by this representation inherit the
SendandSyncattributes ofRepr. That is,Repr: Sendimplies that the objects in backing memory areSend, and likewise withSync. This is necessary to applySendandSyncbounds toMat,MatRef, andMatMut.
Required Associated Types§
Required Methods§
Sourcefn nrows(&self) -> usize
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.
Sourcefn layout(&self) -> Result<Layout, LayoutError>
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.
Sourceunsafe fn get_row<'a>(self, ptr: NonNull<u8>, i: usize) -> Self::Row<'a>
unsafe fn get_row<'a>(self, ptr: NonNull<u8>, i: usize) -> Self::Row<'a>
Returns an immutable reference to the i-th row.
§Safety
ptrmust point to a slice with a layout compatible withRepr::layout.- The entire range for this slice must be within a single allocation.
imust be less thanRepr::nrows.- The memory referenced by the returned
Repr::Rowmust not be mutated for the duration of lifetime'a. - The lifetime for the returned
Repr::Rowis 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.