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:
- Reject
index.len() != shape.rank()withError::IndexRankMismatch. - Reject any
DYNAMICdimension withError::DynamicDimInIndexing. - Reject any out-of-bounds index component with
Error::IndexOutOfRange.
§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 = 6Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".