Skip to main content

HilbertLayout

Struct HilbertLayout 

Source
#[non_exhaustive]
pub struct HilbertLayout { pub hilbert_order: u32, pub hilbert_rank: u32, }
Expand description

Descriptor for the Hilbert space-filling curve layout.

Elements are ordered according to a Hilbert curve, which provides better spatial locality than Morton (Z-order): consecutive Hilbert indices always differ by exactly 1 in exactly one coordinate (L∞ distance = 1).

Constraints (enforced by HilbertLayout::new):

  • hilbert_order > 0
  • hilbert_rank >= 2
  • Every tensor dimension must equal 2^hilbert_order (validated at shape-binding time via [LayoutDescriptor::validate_against_shape])

The normative index mapping is the Skilling (2004) algorithm; see docs/spec/layouts/hilbert.md § Normative Index Mapping.

§Examples

use hurray_core::layout::{LayoutDescriptor, HilbertLayout};

// 2-D Hilbert curve, order 2 (4×4 tensor).
let layout = LayoutDescriptor::Hilbert(HilbertLayout::new(2, 2).unwrap());
assert_eq!(layout.tag(), 0x40);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§hilbert_order: u32

Order of the Hilbert curve. MUST be > 0. Each tensor dimension must equal 2^hilbert_order.

§hilbert_rank: u32

Number of curve dimensions. MUST equal the tensor rank. MUST be >= 2.

Implementations§

Source§

impl HilbertLayout

Source

pub fn new(hilbert_order: u32, hilbert_rank: u32) -> Result<Self>

Creates a new HilbertLayout, validating that hilbert_order > 0 and hilbert_rank >= 2.

Shape consistency (shape[k] == 2^hilbert_order for all k) is deferred to [LayoutDescriptor::validate_against_shape] because the layout descriptor does not carry the shape.

§Errors

Returns Error::InvalidLayout if hilbert_order == 0 or hilbert_rank < 2.

§Examples
use hurray_core::layout::HilbertLayout;

let h = HilbertLayout::new(3, 2).unwrap(); // 8×8 tensor
assert_eq!(h.hilbert_order, 3);
assert_eq!(h.hilbert_rank, 2);

assert!(HilbertLayout::new(0, 2).is_err()); // order must be > 0
assert!(HilbertLayout::new(2, 1).is_err()); // rank must be >= 2

Trait Implementations§

Source§

impl Clone for HilbertLayout

Source§

fn clone(&self) -> HilbertLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HilbertLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ElementAddress for HilbertLayout

Source§

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

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

impl Eq for HilbertLayout

Source§

impl Hash for HilbertLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HilbertLayout

Source§

fn eq(&self, other: &HilbertLayout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for HilbertLayout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.