|
39 | 39 | //! No scan, no index lookup, no serialization. |
40 | 40 | //! One VPOPCNTDQ pass per container per hop. |
41 | 41 |
|
| 42 | +#[cfg(test)] |
42 | 43 | use crate::container::Container; |
43 | 44 | use crate::wide_container::{WideContainer, EmbeddingFormat, WIDE_BYTES}; |
44 | 45 |
|
@@ -113,6 +114,24 @@ impl CogRecord8K { |
113 | 114 | record |
114 | 115 | } |
115 | 116 |
|
| 117 | + // ========================================================================= |
| 118 | + // WIDE METADATA ACCESS (16384-bit expanded schema) |
| 119 | + // ========================================================================= |
| 120 | + |
| 121 | + /// Read-only view into the full 16,384-bit metadata container. |
| 122 | + /// |
| 123 | + /// Provides access to both legacy fields (W0–W127) and expanded schema |
| 124 | + /// fields (W128–W255): SPO Crystal, Hybrid Crystal, extended NARS, |
| 125 | + /// scent index, causal graph, 10-layer activations, DN spine cache. |
| 126 | + pub fn wide_meta(&self) -> crate::wide_meta::WideMetaView<'_> { |
| 127 | + crate::wide_meta::WideMetaView::new(&self.meta.words) |
| 128 | + } |
| 129 | + |
| 130 | + /// Mutable view into the full 16,384-bit metadata container. |
| 131 | + pub fn wide_meta_mut(&mut self) -> crate::wide_meta::WideMetaViewMut<'_> { |
| 132 | + crate::wide_meta::WideMetaViewMut::new(&mut self.meta.words) |
| 133 | + } |
| 134 | + |
116 | 135 | // ========================================================================= |
117 | 136 | // CONTAINER ACCESS |
118 | 137 | // ========================================================================= |
@@ -493,4 +512,66 @@ mod tests { |
493 | 512 | // This means: 4× the data at the same VPOPCNTDQ throughput |
494 | 513 | // as 8 legacy containers (which would be 8 × 16 = 128 iterations) |
495 | 514 | } |
| 515 | + |
| 516 | + #[test] |
| 517 | + fn test_wide_meta_through_cogrecord8k() { |
| 518 | + use crate::wide_meta::SpoTriple; |
| 519 | + |
| 520 | + let mut r = CogRecord8K::new(); |
| 521 | + |
| 522 | + // Write SPO triple via wide_meta_mut |
| 523 | + let triple = SpoTriple { |
| 524 | + subject_dn: 0x0C00, |
| 525 | + predicate_hash: 0xABCD, |
| 526 | + confidence_q8: 200, |
| 527 | + object_dn: 0x0C42, |
| 528 | + evidence_count: 5, |
| 529 | + flags: 0, |
| 530 | + }; |
| 531 | + r.wide_meta_mut().set_spo_triple(0, &triple); |
| 532 | + |
| 533 | + // Write 10-layer activations |
| 534 | + let activations = [0.1, 0.2, 0.9, 0.4, 0.5, 0.6, 0.3, 0.8, 0.7, 0.15]; |
| 535 | + r.wide_meta_mut().set_layer_activations(&activations); |
| 536 | + r.wide_meta_mut().set_calibration_error(0.05); |
| 537 | + |
| 538 | + // Write spine cache |
| 539 | + r.wide_meta_mut().set_spine(&[0xA0, 0xB0, 0xC0]); |
| 540 | + |
| 541 | + // Finalize with checksum |
| 542 | + r.wide_meta_mut().init_wide(); |
| 543 | + |
| 544 | + // Read back via wide_meta |
| 545 | + let wm = r.wide_meta(); |
| 546 | + let read_triple = wm.spo_triple(0); |
| 547 | + assert_eq!(read_triple.subject_dn, 0x0C00); |
| 548 | + assert_eq!(read_triple.object_dn, 0x0C42); |
| 549 | + assert_eq!(read_triple.confidence_q8, 200); |
| 550 | + |
| 551 | + assert_eq!(wm.dominant_layer(), 2); // 0.9 is highest |
| 552 | + assert!((wm.calibration_error() - 0.05).abs() < 1e-12); |
| 553 | + assert_eq!(wm.spine_depth(), 3); |
| 554 | + assert!(wm.verify_wide_checksum()); |
| 555 | + assert!(!wm.is_legacy_only()); |
| 556 | + } |
| 557 | + |
| 558 | + #[test] |
| 559 | + fn test_wide_meta_legacy_compatibility() { |
| 560 | + let mut r = CogRecord8K::new(); |
| 561 | + |
| 562 | + // Write via legacy meta view (through wide_meta_mut) |
| 563 | + r.wide_meta_mut().legacy_mut().set_dn_addr(0xDEAD_BEEF); |
| 564 | + r.wide_meta_mut().legacy_mut().set_rung_level(5); |
| 565 | + |
| 566 | + // Read via wide_meta |
| 567 | + assert_eq!(r.wide_meta().dn_addr(), 0xDEAD_BEEF); |
| 568 | + assert_eq!(r.wide_meta().rung_level(), 5); |
| 569 | + |
| 570 | + // Also readable through legacy MetaView on the container |
| 571 | + let legacy = crate::meta::MetaView::new( |
| 572 | + (&r.meta.words[..128]).try_into().unwrap() |
| 573 | + ); |
| 574 | + assert_eq!(legacy.dn_addr(), 0xDEAD_BEEF); |
| 575 | + assert_eq!(legacy.rung_level(), 5); |
| 576 | + } |
496 | 577 | } |
0 commit comments