Skip to main content

CompositeTensor

Struct CompositeTensor 

Source
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: TensorDescriptor

The composite head descriptor (layout_tag = 0x0B).

§members: Vec<TensorDescriptor>

The ordered member descriptors bound to the head.

Implementations§

Source§

impl CompositeTensor

Source

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.

Source

pub fn rule(&self) -> &CompositionRule

Returns the composition rule declared by the head.

§Examples

See the struct-level example.

Source

pub fn member_count(&self) -> u32

Returns the member count declared by the head.

§Examples

See the struct-level example.

Trait Implementations§

Source§

impl Clone for CompositeTensor

Source§

fn clone(&self) -> CompositeTensor

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 CompositeTensor

Source§

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

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

impl PartialEq for CompositeTensor

Source§

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

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.