pub struct ValidatedEmbedding { /* private fields */ }Expand description
Validated embedding tensor - compile-time guarantee of data quality
This type can ONLY be constructed via new(), which enforces:
- Correct element count (vocab_size * hidden_dim)
- Density check (<50% zeros) - catches PMAT-234 bug
- No NaN or Inf values
- Non-degenerate distribution (L2 > 1e-6, values vary)
- Spot check at 10%/50%/90% of vocab
§Poka-Yoke Guarantee
The inner data field is private. There is no way to construct this type
without passing validation. This makes the PMAT-234 bug (94.5% zeros)
impossible at compile time.
Implementations§
Source§impl ValidatedEmbedding
impl ValidatedEmbedding
Sourcepub fn new(
data: Vec<f32>,
vocab_size: usize,
hidden_dim: usize,
) -> Result<ValidatedEmbedding, ContractValidationError>
pub fn new( data: Vec<f32>, vocab_size: usize, hidden_dim: usize, ) -> Result<ValidatedEmbedding, ContractValidationError>
Construct a validated embedding tensor
This is the ONLY way to create a ValidatedEmbedding. All contract rules are enforced here.
§Errors
Returns ContractValidationError if any validation rule fails:
- Wrong element count
-
50% zeros (F-DATA-QUALITY-001)
- Contains NaN (F-DATA-QUALITY-002)
- Contains Inf (F-DATA-QUALITY-002)
- L2 norm ~0 (F-DATA-QUALITY-003)
- All values identical (F-DATA-QUALITY-003)
- Spot check fails (F-DATA-QUALITY-004)
Sourcepub fn into_inner(self) -> Vec<f32>
pub fn into_inner(self) -> Vec<f32>
Consume and return the inner data
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get vocab size
Get hidden dimension
Sourcepub fn stats(&self) -> &TensorStats
pub fn stats(&self) -> &TensorStats
Get validation statistics
Trait Implementations§
Source§impl Clone for ValidatedEmbedding
impl Clone for ValidatedEmbedding
Source§fn clone(&self) -> ValidatedEmbedding
fn clone(&self) -> ValidatedEmbedding
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ValidatedEmbedding
impl RefUnwindSafe for ValidatedEmbedding
impl Send for ValidatedEmbedding
impl Sync for ValidatedEmbedding
impl Unpin for ValidatedEmbedding
impl UnsafeUnpin for ValidatedEmbedding
impl UnwindSafe for ValidatedEmbedding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more