Skip to main content

CompositeValidator

Struct CompositeValidator 

Source
pub struct CompositeValidator { /* private fields */ }
Expand description

Stateful, bounded validator for a composite head’s members.

Drive it with CompositeValidator::new (extracts the composition rule from the head), then CompositeValidator::push_member once per member in stream order, then CompositeValidator::finish to run the close-time checks. This mirrors docs/spec/layouts/composite.md § Validation exactly: “a reader accumulates state only up to N, reaches one verdict at the Nth member, and is done” — every v1.0 composition rule uses a definite member_count.

CompositeTensor::new drives one of these internally; construct one directly only if you need to validate members incrementally as they arrive (e.g. a future streaming reader) rather than from an already-collected Vec.

§Decoded-type checking and quantized members

Per-member check 2 (member decoded type == head type_tag) is only fully checkable for unquantized members at this layer: TensorDescriptor stores quantization as raw Option<Vec<u8>> bytes with no typed schema at Layer 4 (see its quantization field docs), so a quantized member’s decoded type cannot be resolved here. When a member carries a quantization section, this check is skipped; verifying that its dequantized type agrees with the head is deferred to a higher layer that has quantization-scheme context.

§Examples

use hurray_core::{
    composite::CompositeValidator,
    descriptor::TensorDescriptor,
    layout::{CompositeLayout, CompositionRule, LayoutDescriptor},
    BufferHandle, DeviceTag, ElementType, Shape, SyncMode, MIN_BUFFER_ALIGNMENT,
};

// A group composite: members need no shard section and may differ arbitrarily.
let head = TensorDescriptor::new(
    1, 0, ElementType::Float32, Shape::new(vec![1u64]).unwrap(), 0,
    LayoutDescriptor::Composite(CompositeLayout::new(CompositionRule::Group, 1).unwrap()),
    vec![],
    None, None, None, None,
).unwrap();

let buf = BufferHandle::new(4, MIN_BUFFER_ALIGNMENT, DeviceTag::Cpu, SyncMode::ProducerSynced).unwrap();
let member = TensorDescriptor::new(
    1, 0, ElementType::Int8, Shape::new(vec![100u64]).unwrap(), 0,
    LayoutDescriptor::RowMajor, vec![buf],
    None, None, None, None,
).unwrap();

let mut validator = CompositeValidator::new(&head).unwrap();
validator.push_member(&member).unwrap();
assert!(validator.finish().is_ok());

Implementations§

Source§

impl CompositeValidator

Source

pub fn new(head: &TensorDescriptor) -> Result<Self>

Creates a validator seeded from head.

§Errors

Returns Error::InvalidLayout if head.layout is not LayoutDescriptor::Composite, or if head.shape contains a DYNAMIC dimension while the rule is partition or overlay — coverage/volume math is undefined for a dynamic shape, so both rules require a fully static head. This is the same check LayoutDescriptor::validate_against_shape performs for a composite layout; re-checked here because that method is opt-in and this validator is the layer that actually gates composite assembly.

§Examples

See the type-level example.

Source

pub fn push_member(&mut self, member: &TensorDescriptor) -> Result<()>

Runs the per-member checks (spec § Validation › Per-member checks) for one member, in the order it arrives.

§Errors

See the crate Error variants prefixed Composite, plus Error::ShardOutOfBounds (reused from ADR-004 for the box-in-bounds check).

§Examples

See the type-level example.

Source

pub fn finish(self) -> Result<()>

Runs the close-time checks (spec § Validation › Close-time checks) once every member has been pushed.

§Errors
§Examples

See the type-level example.

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> 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, 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.