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
impl ShardDescriptor
Sourcepub fn new(parent_shape: Vec<u64>, shard_offset: Vec<u64>) -> Result<Self>
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());Sourcepub fn validate_against_shape(&self, shape: &Shape) -> Result<()>
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
impl Clone for ShardDescriptor
Source§fn clone(&self) -> ShardDescriptor
fn clone(&self) -> ShardDescriptor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShardDescriptor
impl Debug for ShardDescriptor
impl Eq for ShardDescriptor
Source§impl PartialEq for ShardDescriptor
impl PartialEq for ShardDescriptor
Source§fn eq(&self, other: &ShardDescriptor) -> bool
fn eq(&self, other: &ShardDescriptor) -> bool
self and other values to be equal, and is used by ==.