DimShapeAPI

Trait DimShapeAPI 

Source
pub trait DimShapeAPI: DimBaseAPI {
    // Required methods
    fn shape_size(&self) -> usize;
    fn stride_f_contig(&self) -> Self::Stride;
    fn stride_c_contig(&self) -> Self::Stride;
    fn stride_contig(&self) -> Self::Stride;
    unsafe fn unravel_index_f(&self, index: usize) -> Self;
    unsafe fn unravel_index_c(&self, index: usize) -> Self;
}

Required Methods§

Source

fn shape_size(&self) -> usize

Total number of elements in tensor.

§Note

For 0-dimension tensor, it contains one element. For multi-dimension tensor with a dimension that have zero length, it contains zero elements.

§Example
use rstsr_core::prelude_dev::*;

let shape = [2, 3];
assert_eq!(shape.shape_size(), 6);

let shape = vec![];
assert_eq!(shape.shape_size(), 1);
Source

fn stride_f_contig(&self) -> Self::Stride

Stride for a f-contiguous tensor using this shape.

§Example
use rstsr_core::prelude_dev::*;

let stride = [2, 3, 5].stride_f_contig();
assert_eq!(stride, [1, 2, 6]);
Source

fn stride_c_contig(&self) -> Self::Stride

Stride for a c-contiguous tensor using this shape.

§Example
use rstsr_core::prelude_dev::*;

let stride = [2, 3, 5].stride_c_contig();
assert_eq!(stride, [15, 5, 1]);
Source

fn stride_contig(&self) -> Self::Stride

Stride for contiguous tensor using this shape.

§Cargo feature dependent

Whether c-contiguous or f-contiguous will depends on cargo feature f_prefer.

Source

unsafe fn unravel_index_f(&self, index: usize) -> Self

Index (col-major) of tensor by list of indexes.

§Safety

This function does not check whether index is out of bounds.

Source

unsafe fn unravel_index_c(&self, index: usize) -> Self

Index (row-major) of tensor by list of indexes.

§Safety

This function does not check whether index is out of bounds.

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.

Implementations on Foreign Types§

Source§

impl<const N: usize> DimShapeAPI for [usize; N]

Source§

fn shape_size(&self) -> usize

Source§

fn stride_f_contig(&self) -> [isize; N]

Source§

fn stride_c_contig(&self) -> [isize; N]

Source§

fn stride_contig(&self) -> [isize; N]

Source§

unsafe fn unravel_index_f(&self, index: usize) -> [usize; N]

Source§

unsafe fn unravel_index_c(&self, index: usize) -> [usize; N]

Implementors§