pub struct FlatIndexer { /* private fields */ }Expand description
Encodes multi-indices over fixed local dimensions as IndexKey values.
Dimension i occupies ceil(log2(d_i)) bits at a fixed offset, so distinct
multi-indices always produce distinct keys.
§Examples
use tensor4all_core::index_key::FlatIndexer;
let indexer = FlatIndexer::try_new(&[3, 4]).unwrap();
assert_eq!(indexer.width_bits(), 4);
assert_eq!(indexer.len(), 2);
assert!(indexer.encode(&[2, 3]).is_ok());
assert!(indexer.encode(&[3, 0]).is_err());Implementations§
Source§impl FlatIndexer
impl FlatIndexer
Sourcepub fn try_new(local_dims: &[usize]) -> Result<Self, IndexKeyError>
pub fn try_new(local_dims: &[usize]) -> Result<Self, IndexKeyError>
Builds an indexer for local_dims.
§Errors
Returns IndexKeyError::ZeroDimension when any dimension is zero and
IndexKeyError::WidthOverflow when the packed width exceeds what this
build can represent.
§Examples
use tensor4all_core::index_key::FlatIndexer;
assert!(FlatIndexer::try_new(&[2, 3, 4]).is_ok());
assert!(FlatIndexer::try_new(&[2, 0]).is_err());Sourcepub fn width_bits(&self) -> u64
pub fn width_bits(&self) -> u64
Total packed width in bits.
Sourcepub fn encode(&self, idx: &[usize]) -> Result<IndexKey, IndexKeyError>
pub fn encode(&self, idx: &[usize]) -> Result<IndexKey, IndexKeyError>
Encodes a multi-index.
§Errors
Returns IndexKeyError::LengthMismatch when idx has the wrong
length, and IndexKeyError::IndexOutOfRange when a component is not
below its dimension. No input produces a silently wrapped key.
§Examples
use tensor4all_core::index_key::FlatIndexer;
let indexer = FlatIndexer::try_new(&[2, 2]).unwrap();
assert!(indexer.encode(&[1, 1]).is_ok());
assert!(indexer.encode(&[2, 0]).is_err());
assert!(indexer.encode(&[0]).is_err());Trait Implementations§
Source§impl Clone for FlatIndexer
impl Clone for FlatIndexer
Source§fn clone(&self) -> FlatIndexer
fn clone(&self) -> FlatIndexer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FlatIndexer
impl RefUnwindSafe for FlatIndexer
impl Send for FlatIndexer
impl Sync for FlatIndexer
impl Unpin for FlatIndexer
impl UnsafeUnpin for FlatIndexer
impl UnwindSafe for FlatIndexer
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
Casts
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more