From e11bcdabf7655a78c65c38726de15bb7df8162b9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 13:57:14 +0000 Subject: [PATCH] rustfmt: lane-fold and arm-discovery (unblocks downstream fmt gates) Format-only. 13 files in lance-graph-lane-fold and lance-graph-arm-discovery were not rustfmt-clean on main (landed via #1381). q2's CI runs `cargo fmt --all -- --check` with lance-graph checked out as a sibling, and `--all` reaches these sources, so its Rustfmt gate fails on them (seen on AdaWorldAPI/q2#156). Formatted with the pinned 1.99.0 rustfmt; no code changes. Both crates `cargo check --all-targets` and `cargo fmt -- --check` clean. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017YPZhKpSxN7eSxk7VH2vzB --- .../src/aerial/codebook.rs | 24 ++-- .../src/aerial/extract.rs | 58 ++++++--- .../src/aerial/mod.rs | 19 ++- .../src/aerial/ontology.rs | 22 +++- .../lance-graph-arm-discovery/src/bitset.rs | 5 +- crates/lance-graph-arm-discovery/src/rule.rs | 5 +- crates/lance-graph-arm-discovery/src/simd.rs | 2 +- .../src/translator.rs | 6 +- .../tests/wikidata_landing.rs | 119 +++++++++++++++--- .../src/clifford_fold.rs | 29 ++++- crates/lance-graph-lane-fold/src/lib.rs | 8 +- crates/lance-graph-lane-fold/src/query.rs | 53 ++++++-- crates/lance-graph-lane-fold/src/stars.rs | 6 +- 13 files changed, 282 insertions(+), 74 deletions(-) diff --git a/crates/lance-graph-arm-discovery/src/aerial/codebook.rs b/crates/lance-graph-arm-discovery/src/aerial/codebook.rs index 01c3df836..c2359c6b6 100644 --- a/crates/lance-graph-arm-discovery/src/aerial/codebook.rs +++ b/crates/lance-graph-arm-discovery/src/aerial/codebook.rs @@ -56,10 +56,12 @@ impl MatrixDistance { pub fn new(spec: &FeatureSpec, table: Vec) -> Self { let dim = spec.dim(); assert_eq!(table.len(), dim * dim, "distance table must be dim × dim"); - let offsets: Vec = (0..spec.num_features()) - .map(|f| spec.block(f).0) - .collect(); - Self { dim, offsets, table } + let offsets: Vec = (0..spec.num_features()).map(|f| spec.block(f).0).collect(); + Self { + dim, + offsets, + table, + } } /// The flat code (slot index) of an item. Validates bounds so an invalid @@ -150,11 +152,7 @@ impl CodebookDistance for TopKDistance { /// consequent item: the **nearest** antecedent item wins (min). For a /// single-item antecedent this is just `distance(a, item)`. #[must_use] -pub fn antecedent_distance( - oracle: &dyn CodebookDistance, - antecedent: &[Item], - item: Item, -) -> u32 { +pub fn antecedent_distance(oracle: &dyn CodebookDistance, antecedent: &[Item], item: Item) -> u32 { antecedent .iter() .map(|&a| oracle.distance(a, item)) @@ -169,7 +167,7 @@ mod tests { #[test] fn matrix_distance_is_slot_addressed_and_symmetric_if_built_so() { let spec = FeatureSpec::new(vec![2, 2]); // dim 4 - // 4×4 table; (f0,c0)=slot0 near (f1,c0)=slot2 (dist 1), far from slot3. + // 4×4 table; (f0,c0)=slot0 near (f1,c0)=slot2 (dist 1), far from slot3. #[rustfmt::skip] let table = vec![ 0, 5, 1, 9, @@ -216,7 +214,11 @@ mod tests { let d = TopKDistance::new(spec, 99, &edges); assert_eq!(d.distance(Item::new(0, 0), Item::new(1, 0)), 3); assert_eq!(d.distance(Item::new(1, 0), Item::new(0, 0)), 3, "symmetric"); - assert_eq!(d.distance(Item::new(0, 0), Item::new(1, 1)), 99, "non-neighbour = far"); + assert_eq!( + d.distance(Item::new(0, 0), Item::new(1, 1)), + 99, + "non-neighbour = far" + ); assert_eq!(d.distance(Item::new(0, 0), Item::new(0, 0)), 0, "self = 0"); } diff --git a/crates/lance-graph-arm-discovery/src/aerial/extract.rs b/crates/lance-graph-arm-discovery/src/aerial/extract.rs index 56a629be0..bd15a6fae 100644 --- a/crates/lance-graph-arm-discovery/src/aerial/extract.rs +++ b/crates/lance-graph-arm-discovery/src/aerial/extract.rs @@ -47,7 +47,7 @@ impl Default for ExtractParams { Self { theta: u32::MAX, max_antecedent: 2, - min_support_ppm: 10_000, // 1% + min_support_ppm: 10_000, // 1% min_confidence_ppm: 500_000, // 50% } } @@ -95,7 +95,15 @@ pub fn extract_rules( for size in 1..=params.max_antecedent { for feature_combo in feature_combinations(&candidate_features, size) { for antecedent in item_product(&feature_combo, &frequent_by_feature) { - probe(oracle, data, &masks, &antecedent, &feature_combo, params, &mut rules); + probe( + oracle, + data, + &masks, + &antecedent, + &feature_combo, + params, + &mut rules, + ); } } } @@ -220,8 +228,8 @@ mod tests { /// in codebook space). Data plants f0 == f1 with a little noise; f2 random. fn fixture(noise_every: usize) -> (Dataset, MatrixDistance) { let spec = FeatureSpec::new(vec![2, 2, 2]); // dim 6 - // slots: f0c0=0 f0c1=1 | f1c0=2 f1c1=3 | f2c0=4 f2c1=5 - // near = 1, mid = 5, far = 50. + // slots: f0c0=0 f0c1=1 | f1c0=2 f1c1=3 | f2c0=4 f2c1=5 + // near = 1, mid = 5, far = 50. let near = 1u32; let mid = 5u32; let far = 50u32; @@ -247,12 +255,19 @@ mod tests { let rows: Vec> = (0..600) .map(|i| { let a = (i % 2) as u32; - let b = if noise_every != 0 && i % noise_every == 0 { 1 - a } else { a }; + let b = if noise_every != 0 && i % noise_every == 0 { + 1 - a + } else { + a + }; let c = ((i / 2) % 2) as u32; vec![a, b, c] }) .collect(); - (Dataset::new(spec.clone(), rows), MatrixDistance::new(&spec, table)) + ( + Dataset::new(spec.clone(), rows), + MatrixDistance::new(&spec, table), + ) } #[test] @@ -261,7 +276,7 @@ mod tests { let params = ExtractParams { theta: 2, // codebook prune: only "near" (dist ≤ 2) consequents max_antecedent: 1, - min_support_ppm: 50_000, // 5% + min_support_ppm: 50_000, // 5% min_confidence_ppm: 700_000, // 70% }; let rules = extract_rules(&dist, &data, ¶ms); @@ -273,14 +288,16 @@ mod tests { assert!(has, "planted f0=0 ⇒ f1=0 not recovered: {rules:#?}"); // feature 2 is codebook-far → pruned by theta → never a consequent of f0 - let spurious = rules.iter().any(|r| { - r.antecedent == vec![Item::new(0, 0)] && r.consequent[0].feature == 2 - }); + let spurious = rules + .iter() + .any(|r| r.antecedent == vec![Item::new(0, 0)] && r.consequent[0].feature == 2); assert!(!spurious, "independent feature 2 leaked: {rules:#?}"); let rule = rules .iter() - .find(|r| r.antecedent == vec![Item::new(0, 0)] && r.consequent == vec![Item::new(1, 0)]) + .find(|r| { + r.antecedent == vec![Item::new(0, 0)] && r.consequent == vec![Item::new(1, 0)] + }) .unwrap(); assert!(rule.confidence_ppm() >= 700_000, "confidence below floor"); } @@ -288,10 +305,18 @@ mod tests { #[test] fn fully_deterministic_no_seed() { let (data, dist) = fixture(20); - let p = ExtractParams { theta: 2, max_antecedent: 1, min_support_ppm: 50_000, min_confidence_ppm: 700_000 }; + let p = ExtractParams { + theta: 2, + max_antecedent: 1, + min_support_ppm: 50_000, + min_confidence_ppm: 700_000, + }; let a = extract_rules(&dist, &data, &p); let b = extract_rules(&dist, &data, &p); - assert_eq!(a, b, "codebook probe is bitwise-deterministic by construction"); + assert_eq!( + a, b, + "codebook probe is bitwise-deterministic by construction" + ); } #[test] @@ -299,7 +324,12 @@ mod tests { // With a generous theta the far feature is *tested* (then data-gated); // with a tight theta it is pruned before the data even sees it. let (data, dist) = fixture(0); // no noise: f1==f0 exactly - let tight = ExtractParams { theta: 2, max_antecedent: 1, min_support_ppm: 50_000, min_confidence_ppm: 600_000 }; + let tight = ExtractParams { + theta: 2, + max_antecedent: 1, + min_support_ppm: 50_000, + min_confidence_ppm: 600_000, + }; let rules = extract_rules(&dist, &data, &tight); assert!(rules.iter().all(|r| r.consequent[0].feature != 2)); } diff --git a/crates/lance-graph-arm-discovery/src/aerial/mod.rs b/crates/lance-graph-arm-discovery/src/aerial/mod.rs index c872fa58c..603f12b08 100644 --- a/crates/lance-graph-arm-discovery/src/aerial/mod.rs +++ b/crates/lance-graph-arm-discovery/src/aerial/mod.rs @@ -111,7 +111,10 @@ mod tests { vec![a, a, c] }) .collect(); - (Dataset::new(spec.clone(), rows), MatrixDistance::new(&spec, table)) + ( + Dataset::new(spec.clone(), rows), + MatrixDistance::new(&spec, table), + ) } #[test] @@ -131,7 +134,12 @@ mod tests { #[test] fn mined_rules_serialise_to_spo_ndjson() { let (data, dist) = fixture(); - let params = AerialParams { theta: 2, max_antecedent: 1, min_support_ppm: 50_000, min_confidence_ppm: 700_000 }; + let params = AerialParams { + theta: 2, + max_antecedent: 1, + min_support_ppm: 50_000, + min_confidence_ppm: 700_000, + }; let p = AerialProposer::new(data, dist, params); let rules = p.mine(); assert!(!rules.is_empty()); @@ -151,7 +159,12 @@ mod tests { fn reproducible_no_seed_needed() { let (d1, dist1) = fixture(); let (d2, dist2) = fixture(); - let p = AerialParams { theta: 2, max_antecedent: 1, min_support_ppm: 50_000, min_confidence_ppm: 700_000 }; + let p = AerialParams { + theta: 2, + max_antecedent: 1, + min_support_ppm: 50_000, + min_confidence_ppm: 700_000, + }; let r1 = AerialProposer::new(d1, dist1, p).mine(); let r2 = AerialProposer::new(d2, dist2, p).mine(); assert_eq!(r1, r2); diff --git a/crates/lance-graph-arm-discovery/src/aerial/ontology.rs b/crates/lance-graph-arm-discovery/src/aerial/ontology.rs index fbdeb5cca..b4f403fa1 100644 --- a/crates/lance-graph-arm-discovery/src/aerial/ontology.rs +++ b/crates/lance-graph-arm-discovery/src/aerial/ontology.rs @@ -127,7 +127,10 @@ impl OntologyProjector { is_dolce: true, ..Self::subclass_of( namespace, - DolceCategory::ALL.iter().map(|c| c.iri().to_string()).collect(), + DolceCategory::ALL + .iter() + .map(|c| c.iri().to_string()) + .collect(), ) } } @@ -212,7 +215,11 @@ mod tests { // consequent category == dolce_id == basin (the hub routing key) assert_eq!(proj.dolce_id(&[Item::new(1, 0)]), Some(0)); // Endurant assert_eq!(proj.dolce_id(&[Item::new(1, 1)]), Some(1)); // Perdurant - assert_eq!(proj.dolce_id(&[Item::new(1, 9)]), None, "out-of-range facet"); + assert_eq!( + proj.dolce_id(&[Item::new(1, 9)]), + None, + "out-of-range facet" + ); // a non-DOLCE projector has no dolce_id to emit let plain = OntologyProjector::subclass_of("wd:", vec!["wd:Q5".into()]); assert_eq!(plain.dolce_id(&[Item::new(1, 0)]), None); @@ -226,7 +233,12 @@ mod tests { // feature 0 = occupation (3), feature 1 = DOLCE class (4 facets). let spec = FeatureSpec::new(vec![3, 4]); // Plant occupation k ⇒ class k for k ∈ {0,1,2} (Abstract unused). - let rows: Vec> = (0..300).map(|i| { let k = (i % 3) as u32; vec![k, k] }).collect(); + let rows: Vec> = (0..300) + .map(|i| { + let k = (i % 3) as u32; + vec![k, k] + }) + .collect(); let data = Dataset::new(spec.clone(), rows); // Splat top-k: occupation k is near DOLCE class k (distance 1), else far. @@ -246,7 +258,9 @@ mod tests { // The planted occupation0 ⇒ Endurant(class0) skeleton edge is recovered. let rule = rules .iter() - .find(|r| r.antecedent == vec![Item::new(0, 0)] && r.consequent == vec![Item::new(1, 0)]) + .find(|r| { + r.antecedent == vec![Item::new(0, 0)] && r.consequent == vec![Item::new(1, 0)] + }) .expect("occupation0 → DOLCE class0 not discovered"); let proj = OntologyProjector::dolce_subclass("wd:"); diff --git a/crates/lance-graph-arm-discovery/src/bitset.rs b/crates/lance-graph-arm-discovery/src/bitset.rs index 43c61bdb2..58c44a148 100644 --- a/crates/lance-graph-arm-discovery/src/bitset.rs +++ b/crates/lance-graph-arm-discovery/src/bitset.rs @@ -118,7 +118,10 @@ mod tests { let m = RowMasks::build(&d); // single-item: feature0=0 in 3 rows assert_eq!(m.support_count(Item::new(0, 0)), 3); - assert_eq!(m.support_count(Item::new(0, 0)), d.count_matching(&[Item::new(0, 0)])); + assert_eq!( + m.support_count(Item::new(0, 0)), + d.count_matching(&[Item::new(0, 0)]) + ); // conjunction f0=0 ∧ f1=0 → 2 rows let both = [Item::new(0, 0), Item::new(1, 0)]; assert_eq!(m.and_count(&both), 2); diff --git a/crates/lance-graph-arm-discovery/src/rule.rs b/crates/lance-graph-arm-discovery/src/rule.rs index c3733dc24..32589b475 100644 --- a/crates/lance-graph-arm-discovery/src/rule.rs +++ b/crates/lance-graph-arm-discovery/src/rule.rs @@ -174,6 +174,9 @@ mod tests { fn item_ordering_is_feature_then_category() { let mut items = vec![Item::new(1, 0), Item::new(0, 2), Item::new(0, 1)]; items.sort(); - assert_eq!(items, vec![Item::new(0, 1), Item::new(0, 2), Item::new(1, 0)]); + assert_eq!( + items, + vec![Item::new(0, 1), Item::new(0, 2), Item::new(1, 0)] + ); } } diff --git a/crates/lance-graph-arm-discovery/src/simd.rs b/crates/lance-graph-arm-discovery/src/simd.rs index 445d7a55e..507535c39 100644 --- a/crates/lance-graph-arm-discovery/src/simd.rs +++ b/crates/lance-graph-arm-discovery/src/simd.rs @@ -85,7 +85,7 @@ mod tests { assert_eq!(popcount(&[0u64]), 0); assert_eq!(popcount(&[u64::MAX]), 64); assert_eq!(popcount(&[0b1011, 0b11]), 5); // 3 + 2 set bits - // exercise the 8-word vector chunk + tail + // exercise the 8-word vector chunk + tail assert_eq!(popcount(&[u64::MAX; 9]), 64 * 9); } diff --git a/crates/lance-graph-arm-discovery/src/translator.rs b/crates/lance-graph-arm-discovery/src/translator.rs index 294f6314b..8e901c59c 100644 --- a/crates/lance-graph-arm-discovery/src/translator.rs +++ b/crates/lance-graph-arm-discovery/src/translator.rs @@ -260,7 +260,11 @@ mod tests { #[test] fn triple_projection() { - let t = CandidateTriple::from_rule(&rule(90, 100, 400), &DebugProjector::default(), NARS_PERSONALITY_K); + let t = CandidateTriple::from_rule( + &rule(90, 100, 400), + &DebugProjector::default(), + NARS_PERSONALITY_K, + ); assert_eq!(t.s, "arm:feat0=cat1"); assert_eq!(t.p, "implies"); assert_eq!(t.o, "arm:feat1=cat0"); diff --git a/crates/lance-graph-arm-discovery/tests/wikidata_landing.rs b/crates/lance-graph-arm-discovery/tests/wikidata_landing.rs index e50ec9c7e..222316ed5 100644 --- a/crates/lance-graph-arm-discovery/tests/wikidata_landing.rs +++ b/crates/lance-graph-arm-discovery/tests/wikidata_landing.rs @@ -46,19 +46,63 @@ struct WClass { fn corpus() -> Vec { vec![ - WClass { id: 1, qid: "Q215627", etype: 0, dolce: 0, path: &[0x1], props: &["P21", "P569", "P570"] }, // person - WClass { id: 2, qid: "Q5", etype: 1, dolce: 0, path: &[0x1, 0x2], props: &["P21", "P569", "P570", "P106"] }, // human ⊂ person (+occupation) - WClass { id: 3, qid: "Q515", etype: 2, dolce: 0, path: &[0x3], props: &["P1082", "P625", "P17"] }, // city - WClass { id: 4, qid: "Q11424", etype: 3, dolce: 1, path: &[0x0], props: &["P57", "P577", "P161"] }, // film - WClass { id: 5, qid: "Q5398426", etype: 4, dolce: 1, path: &[0x1], props: &["P57", "P577", "P161"] }, // tv-series ≡ film - WClass { id: 6, qid: "Q1656682", etype: 5, dolce: 1, path: &[0x2], props: &["P585", "P276"] }, // event + WClass { + id: 1, + qid: "Q215627", + etype: 0, + dolce: 0, + path: &[0x1], + props: &["P21", "P569", "P570"], + }, // person + WClass { + id: 2, + qid: "Q5", + etype: 1, + dolce: 0, + path: &[0x1, 0x2], + props: &["P21", "P569", "P570", "P106"], + }, // human ⊂ person (+occupation) + WClass { + id: 3, + qid: "Q515", + etype: 2, + dolce: 0, + path: &[0x3], + props: &["P1082", "P625", "P17"], + }, // city + WClass { + id: 4, + qid: "Q11424", + etype: 3, + dolce: 1, + path: &[0x0], + props: &["P57", "P577", "P161"], + }, // film + WClass { + id: 5, + qid: "Q5398426", + etype: 4, + dolce: 1, + path: &[0x1], + props: &["P57", "P577", "P161"], + }, // tv-series ≡ film + WClass { + id: 6, + qid: "Q1656682", + etype: 5, + dolce: 1, + path: &[0x2], + props: &["P585", "P276"], + }, // event ] } // ── hub landing primitives (the REAL merged contract types) ────────────────── /// The 16ⁿ Abstammung address: basin (DOLCE facet) + P279 descent. fn nibble_path(basin: u8, children: &[u8]) -> NiblePath { - children.iter().fold(NiblePath::root(basin), |p, &c| p.child(c)) + children + .iter() + .fold(NiblePath::root(basin), |p, &c| p.child(c)) } /// Presence bitmask — one bit per present property. fn presence(props: &[&str]) -> FieldMask { @@ -98,7 +142,12 @@ fn discover_dolce_ids(classes: &[WClass]) -> HashMap { let rules = extract_rules( &oracle, &data, - &ExtractParams { theta: 2, max_antecedent: 1, min_support_ppm: 100_000, min_confidence_ppm: 700_000 }, + &ExtractParams { + theta: 2, + max_antecedent: 1, + min_support_ppm: 100_000, + min_confidence_ppm: 700_000, + }, ); // The proposer emits the stable dolce_id (NOT a hardcoded IRI) — Phase-2 fix. @@ -119,7 +168,10 @@ fn discover_dolce_ids(classes: &[WClass]) -> HashMap { // failure names the invariant that regressed (repo guideline: prefer focused // scenarios over broad integration tests). `find_qid` is the shared lookup. fn find_qid<'a>(classes: &'a [WClass], qid: &str) -> &'a WClass { - classes.iter().find(|c| c.qid == qid).expect("qid in corpus") + classes + .iter() + .find(|c| c.qid == qid) + .expect("qid in corpus") } #[test] @@ -146,10 +198,19 @@ fn landing_preserves_basin_and_mask() { for c in &classes { let basin = discovered[&c.etype]; // from DISCOVERY, not hardcoded let path = nibble_path(basin, c.path); // contract::hhtl::NiblePath - let triple: (ClassId, u32, FieldMask) = (c.id, signature(basin, c.props), presence(c.props)); - assert_eq!(path.basin(), Some(basin), "basin survives down the nibble path"); + let triple: (ClassId, u32, FieldMask) = + (c.id, signature(basin, c.props), presence(c.props)); + assert_eq!( + path.basin(), + Some(basin), + "basin survives down the nibble path" + ); assert_eq!(triple.0, c.id); - assert_eq!(triple.2.count(), c.props.len() as u32, "one present bit per property"); + assert_eq!( + triple.2.count(), + c.props.len() as u32, + "one present bit per property" + ); eprintln!( " landed {:>9} → basin {basin} path {:#x} (depth {}) sig {:#010x} mask {:#06b}", c.qid, @@ -165,14 +226,29 @@ fn landing_preserves_basin_and_mask() { fn shape_family_collapse() { // N4 #1: structurally-identical classes collapse to one StructuralSignature. let classes = corpus(); - let sigs: HashSet = classes.iter().map(|c| signature(c.dolce, c.props)).collect(); - assert!(sigs.len() < classes.len(), "shapes must collapse (6 → {})", sigs.len()); + let sigs: HashSet = classes + .iter() + .map(|c| signature(c.dolce, c.props)) + .collect(); + assert!( + sigs.len() < classes.len(), + "shapes must collapse (6 → {})", + sigs.len() + ); assert_eq!(sigs.len(), 5, "film ≡ tv-series is the one twin"); let film = find_qid(&classes, "Q11424"); let tv = find_qid(&classes, "Q5398426"); - assert_eq!(signature(1, film.props), signature(1, tv.props), "film ≡ tv-series share one signature"); + assert_eq!( + signature(1, film.props), + signature(1, tv.props), + "film ≡ tv-series share one signature" + ); let person = find_qid(&classes, "Q215627"); - assert_ne!(signature(0, person.props), signature(1, film.props), "person ≠ film"); + assert_ne!( + signature(0, person.props), + signature(1, film.props), + "person ≠ film" + ); } #[test] @@ -183,8 +259,15 @@ fn subclass_inherits_path_and_mask() { let human = find_qid(&classes, "Q5"); let person_path = nibble_path(0, person.path); let human_path = nibble_path(0, human.path); - assert!(person_path.is_ancestor_of(human_path), "person ⊃ human in the nibble tree"); - assert_eq!(person_path.basin(), human_path.basin(), "subclassing preserves the DOLCE basin"); + assert!( + person_path.is_ancestor_of(human_path), + "person ⊃ human in the nibble tree" + ); + assert_eq!( + person_path.basin(), + human_path.basin(), + "subclassing preserves the DOLCE basin" + ); let delta = FieldMask::from_positions(&[3]); // human's extra property (P106) bit assert_eq!( presence(person.props).inherit(delta), // FieldMask::inherit diff --git a/crates/lance-graph-lane-fold/src/clifford_fold.rs b/crates/lance-graph-lane-fold/src/clifford_fold.rs index 56a8af410..ad59c8f44 100644 --- a/crates/lance-graph-lane-fold/src/clifford_fold.rs +++ b/crates/lance-graph-lane-fold/src/clifford_fold.rs @@ -64,8 +64,16 @@ impl Tableau { pub fn zero() -> Self { Self { rows: [ - Row { r: 0, x: 0, z: 0b01 }, - Row { r: 0, x: 0, z: 0b10 }, + Row { + r: 0, + x: 0, + z: 0b01, + }, + Row { + r: 0, + x: 0, + z: 0b10, + }, ], } } @@ -93,7 +101,10 @@ impl Tableau { /// Parity of a Pauli that is already a stabilizer row. `None` if it is not. pub fn parity(&self, x: u8, z: u8) -> Option { - self.rows.iter().find(|row| row.x == x && row.z == z).map(|row| row.r) + self.rows + .iter() + .find(|row| row.x == x && row.z == z) + .map(|row| row.r) } } @@ -104,8 +115,16 @@ mod tests { #[test] fn bell_zz_parity_is_even() { let bell = Tableau::zero().h(0).cnot(0, 1); - assert_eq!(bell.parity(0b00, 0b11), Some(0), "ZZ even on the Bell state"); - assert_eq!(bell.parity(0b11, 0b00), Some(0), "XX even on the Bell state"); + assert_eq!( + bell.parity(0b00, 0b11), + Some(0), + "ZZ even on the Bell state" + ); + assert_eq!( + bell.parity(0b11, 0b00), + Some(0), + "XX even on the Bell state" + ); } #[test] diff --git a/crates/lance-graph-lane-fold/src/lib.rs b/crates/lance-graph-lane-fold/src/lib.rs index f7051c46a..6de688cdb 100644 --- a/crates/lance-graph-lane-fold/src/lib.rs +++ b/crates/lance-graph-lane-fold/src/lib.rs @@ -6,13 +6,13 @@ #![forbid(unsafe_code)] +mod clifford_fold; +mod optics; mod query; mod stars; -mod optics; -mod clifford_fold; pub use query::{ - Aperture, ApertureId, BestQuery, Hom, LaneId, Query, Refuse, Request, Row, Terminal, N, - MASK_WORDS, + Aperture, ApertureId, BestQuery, Hom, LaneId, Query, Refuse, Request, Row, Terminal, + MASK_WORDS, N, }; pub use stars::{Landing, Map, MapOp, Star, Teleport}; diff --git a/crates/lance-graph-lane-fold/src/query.rs b/crates/lance-graph-lane-fold/src/query.rs index d7141905f..89b59f27a 100644 --- a/crates/lance-graph-lane-fold/src/query.rs +++ b/crates/lance-graph-lane-fold/src/query.rs @@ -143,11 +143,35 @@ impl<'a> Query<'a> { for req in &self.requests { match req { Request::Reduce { hom, lane } => { - push_or_merge(&mut terminals, self.aperture.id, *hom, *lane, 1, 1, &mut collapsed); + push_or_merge( + &mut terminals, + self.aperture.id, + *hom, + *lane, + 1, + 1, + &mut collapsed, + ); } Request::Avg { lane } => { - push_or_merge(&mut terminals, self.aperture.id, Hom::Sum, *lane, 1, 1, &mut collapsed); - push_or_merge(&mut terminals, self.aperture.id, Hom::Count, *lane, 1, 1, &mut collapsed); + push_or_merge( + &mut terminals, + self.aperture.id, + Hom::Sum, + *lane, + 1, + 1, + &mut collapsed, + ); + push_or_merge( + &mut terminals, + self.aperture.id, + Hom::Count, + *lane, + 1, + 1, + &mut collapsed, + ); } Request::Repeat { n } => { let last = terminals.last_mut().ok_or(Refuse::ScaleWithoutTerminal)?; @@ -178,9 +202,10 @@ fn push_or_merge( scale: u32, collapsed: &mut u32, ) { - if let Some(found) = terminals.iter_mut().find(|t| { - t.aperture == aperture && t.hom == hom && t.lane == lane && t.scale == scale - }) { + if let Some(found) = terminals + .iter_mut() + .find(|t| t.aperture == aperture && t.hom == hom && t.lane == lane && t.scale == scale) + { found.consumers = found.consumers.saturating_add(consumers); *collapsed += consumers; return; @@ -212,9 +237,15 @@ mod tests { #[test] fn a_thousand_sums_lower_to_one() { - let best = q(vec![Request::Reduce { hom: Hom::Sum, lane: LaneId(1) }; 1000]) - .collapse() - .unwrap(); + let best = q(vec![ + Request::Reduce { + hom: Hom::Sum, + lane: LaneId(1) + }; + 1000 + ]) + .collapse() + .unwrap(); assert_eq!(best.remaining, 1); assert_eq!(best.terminals[0].consumers, 1000); assert_eq!(best.collapsed, 999); @@ -222,7 +253,9 @@ mod tests { #[test] fn avg_is_a_pair() { - let best = q(vec![Request::Avg { lane: LaneId(2) }]).collapse().unwrap(); + let best = q(vec![Request::Avg { lane: LaneId(2) }]) + .collapse() + .unwrap(); assert_eq!(best.remaining, 2); } diff --git a/crates/lance-graph-lane-fold/src/stars.rs b/crates/lance-graph-lane-fold/src/stars.rs index 80fa9036f..23650f090 100644 --- a/crates/lance-graph-lane-fold/src/stars.rs +++ b/crates/lance-graph-lane-fold/src/stars.rs @@ -58,7 +58,11 @@ impl Map { Landing::Checksum => Star::Proof, Landing::Refuse => Star::Refusal, Landing::Count | Landing::Sum | Landing::Min | Landing::Max | Landing::Exists => { - if self.ops.iter().any(|o| matches!(o, MapOp::RangeSpan { .. })) { + if self + .ops + .iter() + .any(|o| matches!(o, MapOp::RangeSpan { .. })) + { Star::Span } else if self.ops.iter().any(|o| matches!(o, MapOp::Shift { .. })) { Star::Rail