Skip to main content

ElementAddress

Trait ElementAddress 

Source
pub trait ElementAddress {
    // Required method
    fn element_offset(&self, index: &[u64], shape: &Shape) -> Result<u64>;
}
Expand description

Implemented by every dense layout descriptor.

Converts a multi-dimensional logical index into a linear element offset. The offset is relative to byte_offset in the tensor descriptor, and may be negative for strided layouts (encoded as a signed two’s-complement u64).

§Contract

Implementations MUST:

§Examples

use hurray_core::layout::{LayoutDescriptor, addressing::ElementAddress};
use hurray_core::Shape;

let shape = Shape::new(vec![3, 4]).unwrap();
let offset = LayoutDescriptor::RowMajor
    .element_offset(&[1, 2], &shape)
    .unwrap();
assert_eq!(offset, 6); // 1*4 + 2*1 = 6

Required Methods§

Source

fn element_offset(&self, index: &[u64], shape: &Shape) -> Result<u64>

Returns the linear element offset (in logical elements) for the given index.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§