Skip to content

Stabilize ellipse covariance symmetrization - #5118

Closed
FlorianPfaff wants to merge 4 commits into
mainfrom
agent/stabilize-ellipse-symmetrization
Closed

Stabilize ellipse covariance symmetrization#5118
FlorianPfaff wants to merge 4 commits into
mainfrom
agent/stabilize-ellipse-symmetrization

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • compute the symmetric part as the sum of two half-scaled operands
  • avoid overflow when finite covariance entries are already near the floating-point limit
  • add regressions for direct symmetrization and PSD covariance projection under strict NumPy error handling

Bug

tracking.ellipse_geometry.symmetrize() evaluated matrix + matrix.T before multiplying by 0.5.

For an already symmetric finite covariance such as diag([1e308, 2e307]), the diagonal entries are doubled first. That intermediate exceeds the float64 range, so the helper raises FloatingPointError under strict NumPy settings or returns infinities under ordinary settings, even though the requested symmetric result is exactly the original finite matrix.

The failure propagates into project_symmetric_covariance() and the shared ellipse canonicalization paths that rely on this helper.

Fix

Use the algebraically equivalent form

0.5 * matrix + 0.5 * matrix.T

Each finite operand is scaled before addition, so the representable average remains finite. Ordinary-scale behavior and backend-neutral operations are unchanged.

Validation

  • reproduced the old overflow encountered in add failure with diag([1e308, 2e307])
  • verified the scale-first expression preserves the matrix exactly under numpy.errstate(over="raise", invalid="raise")
  • added focused tests for both symmetrize() and project_symmetric_covariance()
  • branch comparison against current main: 4 commits ahead, 0 behind; final diff is limited to 2 files, 29 additions, and 1 deletion

Repository CI is the authoritative full backend, lint, packaging, documentation, dependency, security, and CodeQL validation.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 17.81s
✅ JSON prettier 7 0 0 0 0.96s
✅ JSON v8r 7 0 0 3.54s
✅ MARKDOWN markdownlint 68 0 0 0 1.39s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.35s
✅ PYTHON black 1859 84 0 0 68.74s
✅ PYTHON isort 1859 136 0 0 2.04s
✅ REPOSITORY betterleaks yes no no 2.1s
✅ REPOSITORY checkov yes no no 53.57s
✅ REPOSITORY gitleaks yes no no 14.29s
✅ REPOSITORY git_diff yes no no 0.17s
✅ REPOSITORY secretlint yes no no 58.08s
✅ REPOSITORY syft yes no no 3.99s
✅ REPOSITORY trivy-sbom yes no no 4.74s
✅ REPOSITORY trufflehog yes no no 20.14s
✅ YAML prettier 11 0 0 0 0.58s
✅ YAML v8r 11 0 0 8.73s
✅ YAML yamllint 11 0 0 0.38s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

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@9.6.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_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

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

Copy link
Copy Markdown
Owner Author

Closing as superseded by #5178. Both PRs make the identical production change in tracking/ellipse_geometry.py (0.5 * matrix + 0.5 * matrix.T); #5178 is the newer current-main branch with focused overflow regression coverage.

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