Skip to content

Deduplicate PDT helper and flaw generators - #5

Merged
tprest merged 1 commit into
masterfrom
saga-dedup-pdt-flaws
Jul 9, 2026
Merged

Deduplicate PDT helper and flaw generators#5
tprest merged 1 commit into
masterfrom
saga-dedup-pdt-flaws

Conversation

@tprest

@tprest tprest commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Small hygiene refactor: remove duplicated statistics helpers, following the code-quality pass.

The duplication (and a real drift bug)

  • The (mu, sigma) → (support, probs) helper was written four times: _pdt_arrays in both calibration.py and scripts/run_extensive_calibration.py (identical), pdt_arrays in univariate_tests.py, and make_pdt in generate_test_vectors.py.
  • The univariate flaw generators (gen_*) were copy-pasted between calibration.py (8) and run_extensive_calibration.py (10).

The copies had already drifted: gen_table_error's bounds guard (min(mode_idx + 2, len(p) - 1)mode_idx + 2 can run past the support edge) existed in only one copy. The other has a latent IndexError at small/asymmetric supports — exactly the hazard copy-paste invites, and something no linter or package swap would catch.

Change

  • distributions.py — one canonical pdt_arrays, delegating to make_gaussian_pdt so the output is byte-identical to the former helpers (no float changes → no test drift).
  • flaws.py — the ten gen_* generators, with the bounds guard kept everywhere.
  • calibration.py, run_extensive_calibration.py, univariate_tests.py now import from these.

Net: ~166 lines of duplicated code → 124 lines of single source, plus the guard is now consistent.

Verification

Suite unchanged: 134 passed, 1 skipped; ruff --select F401 clean on the touched files; run_extensive_calibration.py still imports/runs.

🤖 Generated with Claude Code

The (mu, sigma) -> (support, probs) helper was reimplemented four times
(_pdt_arrays x2, pdt_arrays, plus make_pdt in generate_test_vectors) and the
univariate flaw generators were copy-pasted between calibration.py and
scripts/run_extensive_calibration.py. The copies had already drifted:
gen_table_error's bounds guard (mode_idx + 2 can exceed the support) existed in
only one of them -- a latent IndexError in the other, and exactly the hazard
duplication invites.

- distributions.py: single canonical pdt_arrays (delegates to
  make_gaussian_pdt, so output is byte-identical to the former helpers).
- flaws.py: the ten gen_* generators, with the bounds guard kept everywhere.
- calibration.py, run_extensive_calibration.py, univariate_tests.py import from
  these instead of redefining them.

Removes ~166 lines of duplicated code for 124 lines of single-source code, and
makes the bounds guard consistent. Suite unchanged: 134 passed, 1 skipped
(the helper swap changes no floats).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tprest
tprest merged commit 5117e58 into master Jul 9, 2026
4 checks passed
@tprest
tprest deleted the saga-dedup-pdt-flaws branch July 9, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant