pub struct CompositeTensor {
pub head: TensorDescriptor,
pub members: Vec<TensorDescriptor>,
}Expand description
A composite tensor: a head descriptor plus its ordered member descriptors.
Construct via CompositeTensor::new, which drives a CompositeValidator
across every member and rejects a malformed head+members set — see that type’s
docs for the full per-member and close-time checks performed.
§Nesting depth — a note on this layer’s limitation
A member here is a flat TensorDescriptor, not a further-expanded
CompositeTensor. If a member’s own layout_tag happens to be the composite
tag, CompositeTensor::new counts that as one additional nesting level for
the depth cap, but it cannot recurse into that member’s own members — they
are not available at this layer (Layer 4 sees single descriptors, not a
pre-assembled tree). Full nesting-depth validation therefore cannot be
completed until a higher layer (Layer 5 streaming or Layer 6 file, which do
assemble the full nested tree as they parse it) walks the tree top to bottom.
CompositeTensor::new is depth 0; a pub(crate) depth-aware constructor
is provided for that future recursive caller.
§Examples
use hurray_core::{
composite::CompositeTensor,
descriptor::TensorDescriptor,
layout::{CompositeLayout, CompositionRule, LayoutDescriptor},
BufferHandle, DeviceTag, ElementType, Shape, ShardDescriptor, SyncMode,
MIN_BUFFER_ALIGNMENT,
};
// Head: float32 [8, 8], partition of 2 members.
let head = TensorDescriptor::new(
1, 0, ElementType::Float32, Shape::new(vec![8u64, 8]).unwrap(), 0,
LayoutDescriptor::Composite(CompositeLayout::new(CompositionRule::Partition, 2).unwrap()),
vec![],
None, None, None, None,
).unwrap();
// Two [8, 4] members tiling the head's [8, 8] index space.
let member = |offset: u64| {
let buf = BufferHandle::new(128, MIN_BUFFER_ALIGNMENT, DeviceTag::Cpu, SyncMode::ProducerSynced).unwrap();
let shard = ShardDescriptor::new(vec![8, 8], vec![0, offset]).unwrap();
TensorDescriptor::new(
1, 0, ElementType::Float32, Shape::new(vec![8u64, 4]).unwrap(), 0,
LayoutDescriptor::RowMajor, vec![buf],
None, Some(shard), None, None,
).unwrap()
};
let composite = CompositeTensor::new(head, vec![member(0), member(4)]).unwrap();
assert_eq!(composite.member_count(), 2);
assert_eq!(*composite.rule(), CompositionRule::Partition);Fields§
§head: TensorDescriptorThe composite head descriptor (layout_tag = 0x0B).
members: Vec<TensorDescriptor>The ordered member descriptors bound to the head.
Implementations§
Source§impl CompositeTensor
impl CompositeTensor
Sourcepub fn new(
head: TensorDescriptor,
members: Vec<TensorDescriptor>,
) -> Result<Self>
pub fn new( head: TensorDescriptor, members: Vec<TensorDescriptor>, ) -> Result<Self>
Creates a new CompositeTensor, validating members against head
via CompositeValidator (per-member checks, then close-time checks).
Equivalent to CompositeTensor::new_at_depth(head, members, 0).
§Errors
Propagates any CompositeValidator::push_member / CompositeValidator::finish
error, plus Error::InvalidLayout if head.layout is not
LayoutDescriptor::Composite.
§Examples
See the module-level and struct-level examples.
Sourcepub fn rule(&self) -> &CompositionRule
pub fn rule(&self) -> &CompositionRule
Sourcepub fn member_count(&self) -> u32
pub fn member_count(&self) -> u32
Trait Implementations§
Source§impl Clone for CompositeTensor
impl Clone for CompositeTensor
Source§fn clone(&self) -> CompositeTensor
fn clone(&self) -> CompositeTensor
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 CompositeTensor
impl Debug for CompositeTensor
Source§impl PartialEq for CompositeTensor
impl PartialEq for CompositeTensor
Source§fn eq(&self, other: &CompositeTensor) -> bool
fn eq(&self, other: &CompositeTensor) -> bool
self and other values to be equal, and is used by ==.