Skip to main content

ShardDescriptor

Struct ShardDescriptor 

Source
pub struct ShardDescriptor {
    pub parent_shape: Vec<u64>,
    pub shard_offset: Vec<u64>,
}
Expand description

Declares that this tensor is a rectangular shard of a larger parent tensor.

The shard descriptor carries the parent tensor’s shape and the starting index of this shard within the parent along each dimension.

§Examples

use hurray_core::descriptor::ShardDescriptor;
use hurray_core::Shape;

let parent = vec![10u64, 20];
let offset = vec![0u64, 5];
let shard  = ShardDescriptor::new(parent, offset).unwrap();
assert_eq!(shard.parent_shape, [10, 20]);
assert_eq!(shard.shard_offset, [0, 5]);

Fields§

§parent_shape: Vec<u64>

Shape of the logical parent tensor. Same length as the tensor rank.

§shard_offset: Vec<u64>

Starting index of this shard within the parent along each dimension.

Implementations§

Source§

impl ShardDescriptor

Source

pub fn new(parent_shape: Vec<u64>, shard_offset: Vec<u64>) -> Result<Self>

Creates a new ShardDescriptor, validating that parent_shape and shard_offset have the same length.

Shape-vs-offset bound checking (offset[k] + shape[k] <= parent[k]) requires the tensor shape and is performed by ShardDescriptor::validate_against_shape.

§Errors

Returns Error::InvalidShape if parent_shape.len() != shard_offset.len().

§Examples
use hurray_core::descriptor::ShardDescriptor;

let s = ShardDescriptor::new(vec![10, 20], vec![0, 5]).unwrap();
assert_eq!(s.parent_shape, [10, 20]);

// Mismatched lengths are rejected.
assert!(ShardDescriptor::new(vec![10], vec![0, 5]).is_err());
Source

pub fn validate_against_shape(&self, shape: &Shape) -> Result<()>

Checks that shard_offset[k] + shape[k] <= parent_shape[k] for every k.

§Errors

Returns Error::ShardOutOfBounds for the first dimension k that violates the constraint.

§Examples
use hurray_core::descriptor::ShardDescriptor;
use hurray_core::Shape;

let shape  = Shape::new(vec![4, 4]).unwrap();
let shard  = ShardDescriptor::new(vec![10, 10], vec![0, 6]).unwrap();

// offset[1]=6 + shape[1]=4 = 10 == parent[1]=10 → valid
assert!(shard.validate_against_shape(&shape).is_ok());

let bad = ShardDescriptor::new(vec![10, 10], vec![0, 7]).unwrap();
// offset[1]=7 + shape[1]=4 = 11 > parent[1]=10 → rejected
assert!(bad.validate_against_shape(&shape).is_err());

Trait Implementations§

Source§

impl Clone for ShardDescriptor

Source§

fn clone(&self) -> ShardDescriptor

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 ShardDescriptor

Source§

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

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

impl Eq for ShardDescriptor

Source§

impl PartialEq for ShardDescriptor

Source§

fn eq(&self, other: &ShardDescriptor) -> 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 ShardDescriptor

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.