Skip to content

Stabilize piecewise-constant extreme-weight normalization - #5377

Merged
FlorianPfaff merged 3 commits into
mainfrom
fix/piecewise-constant-extreme-weight-normalization
Aug 21, 2026
Merged

Stabilize piecewise-constant extreme-weight normalization#5377
FlorianPfaff merged 3 commits into
mainfrom
fix/piecewise-constant-extreme-weight-normalization

Conversation

@FlorianPfaff

@FlorianPfaff FlorianPfaff commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Bug

PiecewiseConstantDistribution accepts arbitrary nonnegative finite interval weights and normalizes them internally. The constructor currently computes mean(w) before normalization. For valid weights near the backend dtype maximum, that reduction can overflow to inf; the subsequent division then collapses the represented density toward zero instead of preserving the input weight ratios.

For example, [max_float, max_float / 2, 0] has a perfectly well-defined normalized density, but the direct mean can overflow even though every input is finite.

Fix

Normalize after scaling by the largest input weight. The scaling division is split through sqrt(max_weight) so backends that lower division through reciprocals do not underflow the reciprocal of a near-maximum finite value.

This preserves the existing normalization formula and all ordinary-scale behavior while avoiding the unnecessary large intermediate reduction.

Regression coverage

Adds tests/distributions/test_piecewise_constant_extreme_weights.py, which constructs the distribution from backend-dtype maximum finite weights and verifies:

  • the normalized density heights preserve the expected 2:1 ratio;
  • the exact piecewise integral remains one;
  • construction succeeds under NumPy overflow/invalid/divide traps.

Scope

  • based directly on main at baac3b1736bb8e81eafc1e3f69e10104636103b9;
  • 3 small commits ahead / 0 behind at the current head;
  • one production file changed (16 additions / 4 deletions);
  • one focused 32-line regression test added;
  • no overlap found with the currently open PyRecEst bug-fix PRs.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.41s
✅ JSON prettier 7 0 0 0 0.78s
✅ JSON v8r 7 0 0 5.79s
✅ MARKDOWN markdownlint 68 0 0 0 2.01s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.4s
✅ PYTHON black 1989 15 0 0 58.01s
✅ PYTHON isort 1989 28 0 0 2.79s
✅ REPOSITORY betterleaks yes no no 1.04s
✅ REPOSITORY checkov yes no no 34.07s
✅ REPOSITORY git_diff yes no no 0.15s
✅ REPOSITORY secretlint yes no no 98.38s
✅ REPOSITORY syft yes no no 2.72s
✅ REPOSITORY trivy-sbom yes no no 2.61s
✅ YAML prettier 11 0 0 0 0.61s
✅ YAML v8r 11 0 0 16.33s
✅ YAML yamllint 11 0 0 0.83s

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: MAKEFILE_CHECKMAKE. See Removed linters to find their replacements.

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.0.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff
FlorianPfaff marked this pull request as ready for review August 21, 2026 06:41
@FlorianPfaff
FlorianPfaff merged commit fc35907 into main Aug 21, 2026
15 of 26 checks passed
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