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
impl CompositeValidator
Sourcepub fn new(head: &TensorDescriptor) -> Result<Self>
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.
Sourcepub fn push_member(&mut self, member: &TensorDescriptor) -> Result<()>
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.
Sourcepub fn finish(self) -> Result<()>
pub fn finish(self) -> Result<()>
Runs the close-time checks (spec § Validation › Close-time checks) once every member has been pushed.
§Errors
Error::CompositeMemberCountMismatch— the number of members pushed does not equal the head’s declaredmember_count.Error::CompositeOverlayEmpty— an overlay composite received zero members.Error::CompositePartitionGap/Error::CompositePartitionOverlap— partition members do not exactly cover the head’s index space.
§Examples
See the type-level example.