Deduplicate PDT helper and flaw generators - #5
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Small hygiene refactor: remove duplicated statistics helpers, following the code-quality pass.
The duplication (and a real drift bug)
(mu, sigma) → (support, probs)helper was written four times:_pdt_arraysin bothcalibration.pyandscripts/run_extensive_calibration.py(identical),pdt_arraysinunivariate_tests.py, andmake_pdtingenerate_test_vectors.py.gen_*) were copy-pasted betweencalibration.py(8) andrun_extensive_calibration.py(10).The copies had already drifted:
gen_table_error's bounds guard (min(mode_idx + 2, len(p) - 1)—mode_idx + 2can run past the support edge) existed in only one copy. The other has a latentIndexErrorat small/asymmetric supports — exactly the hazard copy-paste invites, and something no linter or package swap would catch.Change
distributions.py— one canonicalpdt_arrays, delegating tomake_gaussian_pdtso the output is byte-identical to the former helpers (no float changes → no test drift).flaws.py— the tengen_*generators, with the bounds guard kept everywhere.calibration.py,run_extensive_calibration.py,univariate_tests.pynow 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 F401clean on the touched files;run_extensive_calibration.pystill imports/runs.🤖 Generated with Claude Code