Layout

Trait Layout 

Source
pub trait Layout: CubeType<ExpandType: LayoutExpand<Coordinates = Self::Coordinates, SourceCoordinates = Self::SourceCoordinates>> {
    type Coordinates: Coordinates;
    type SourceCoordinates: Coordinates;

    // Required methods
    fn to_source_pos(&self, pos: Self::Coordinates) -> Self::SourceCoordinates;
    fn to_source_pos_checked(
        &self,
        pos: Self::Coordinates,
    ) -> (Self::SourceCoordinates, bool);
    fn shape(&self) -> Self::Coordinates;
    fn is_in_bounds(&self, pos: Self::Coordinates) -> bool;

    // Provided methods
    fn __expand_to_source_pos(
        scope: &mut Scope,
        this: <Self as CubeType>::ExpandType,
        pos: <Self::Coordinates as CubeType>::ExpandType,
    ) -> <Self::SourceCoordinates as CubeType>::ExpandType { ... }
    fn __expand_to_source_pos_checked(
        scope: &mut Scope,
        this: <Self as CubeType>::ExpandType,
        pos: <Self::Coordinates as CubeType>::ExpandType,
    ) -> <(Self::SourceCoordinates, bool) as CubeType>::ExpandType { ... }
    fn __expand_shape(
        scope: &mut Scope,
        this: <Self as CubeType>::ExpandType,
    ) -> <Self::Coordinates as CubeType>::ExpandType { ... }
    fn __expand_is_in_bounds(
        scope: &mut Scope,
        this: <Self as CubeType>::ExpandType,
        pos: <Self::Coordinates as CubeType>::ExpandType,
    ) -> <bool as CubeType>::ExpandType { ... }
}
Expand description

A layout that represents the mapping from a conceptual multi-dimensional tensor to a linear storage. Some layouts may be transformers meant to be composed with others (i.e. swizzling), others will represent the actual underlying structure of the data.

Required Associated Types§

Source

type Coordinates: Coordinates

The coordinate type used by the conceptual tensor represented by this layout, i.e. (u32, u32, u32) for a fixed-rank 3D tensor. This does not have to match the rank of the underlying storage (if applicable). It’s only how the tensor is interpreted (viewed) by the code.

Source

type SourceCoordinates: Coordinates

The coordinate type used by the inner storage wrapped in this layout, i.e. u32 for Array, or (u32, u32) for a 2D view.

Required Methods§

Source

fn to_source_pos(&self, pos: Self::Coordinates) -> Self::SourceCoordinates

Transform a set of n-dimensional coordinates to a source coordinate space. It is recommended to use absolute positions here, and handle the translation into lines at the lowest level (global memory layout).

Source

fn to_source_pos_checked( &self, pos: Self::Coordinates, ) -> (Self::SourceCoordinates, bool)

Transform a set of n-dimensional coordinates to an offset into the underlying storage, and return whether the position is in bounds of this layout. See also Layout::to_source_pos

Source

fn shape(&self) -> Self::Coordinates

The shape of the conceptual tensor represented by this layout. Not necessarily the extent of the underlying storage, but only this view of it.

Source

fn is_in_bounds(&self, pos: Self::Coordinates) -> bool

Provided Methods§

Source

fn __expand_to_source_pos( scope: &mut Scope, this: <Self as CubeType>::ExpandType, pos: <Self::Coordinates as CubeType>::ExpandType, ) -> <Self::SourceCoordinates as CubeType>::ExpandType

Source

fn __expand_to_source_pos_checked( scope: &mut Scope, this: <Self as CubeType>::ExpandType, pos: <Self::Coordinates as CubeType>::ExpandType, ) -> <(Self::SourceCoordinates, bool) as CubeType>::ExpandType

Source

fn __expand_shape( scope: &mut Scope, this: <Self as CubeType>::ExpandType, ) -> <Self::Coordinates as CubeType>::ExpandType

Source

fn __expand_is_in_bounds( scope: &mut Scope, this: <Self as CubeType>::ExpandType, pos: <Self::Coordinates as CubeType>::ExpandType, ) -> <bool as CubeType>::ExpandType

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§