T-47: M1.2a — Scaffold tools/curate-etl Rust crate: split-factor table + un-adjustment core with local benchmark (no new crates)
This commit is contained in:
parent
ce4b8fa91c
commit
4c8a621e48
4 changed files with 161 additions and 41 deletions
|
|
@ -184,7 +184,11 @@ where
|
|||
let mut coalesced: Vec<(i32, f64)> = Vec::new();
|
||||
|
||||
for (key, mut key_events) in grouped {
|
||||
key_events.sort_unstable_by_key(|ev| ev.ex_date);
|
||||
key_events.sort_unstable_by(|a, b| {
|
||||
a.ex_date
|
||||
.cmp(&b.ex_date)
|
||||
.then_with(|| a.ratio.total_cmp(&b.ratio))
|
||||
});
|
||||
coalesced.clear();
|
||||
|
||||
for ev in key_events {
|
||||
|
|
@ -573,6 +577,33 @@ mod tests {
|
|||
assert_eq!(table.cum_factor_after("DUP", d1), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_date_events_produce_bitwise_identical_factors_across_permutations() {
|
||||
let d1 = ymd_to_epoch_days(2023, 3, 15).unwrap();
|
||||
let permutations = [[10.0, 0.1, 0.1], [0.1, 10.0, 0.1], [0.1, 0.1, 10.0]];
|
||||
|
||||
let mut baseline_bits: Option<u64> = None;
|
||||
for ratios in permutations {
|
||||
let table = SplitTable::from_events(
|
||||
ratios
|
||||
.into_iter()
|
||||
.map(|ratio| ("PERM".to_string(), SplitEvent { ex_date: d1, ratio })),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let factor = table.cum_factor_after("PERM", d1 - 1);
|
||||
assert_rel_eq(factor, 0.1, 1e-12);
|
||||
match baseline_bits {
|
||||
None => baseline_bits = Some(factor.to_bits()),
|
||||
Some(expected) => assert_eq!(
|
||||
factor.to_bits(),
|
||||
expected,
|
||||
"same-date ratio permutation changed factor bits"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_i32_listing_id_keys_and_date_boundaries() {
|
||||
let table: SplitTable<i32> = SplitTable::from_events([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue