Skip to content

fix: guard against division by zero in correlation() - #3170

Merged
davisking merged 2 commits into
davisking:masterfrom
lippinj:upstream-fix-2
Oct 17, 2026
Merged

davisking merged 2 commits into
davisking:masterfrom
lippinj:upstream-fix-2

Conversation

@lippinj

@lippinj lippinj commented Oct 16, 2026

Copy link
Copy Markdown

When both variances are near zero, sqrt(variance_x * variance_y) can underflow to zero and cause a division by zero. Clamp the divisor to epsilon instead.

Joonas Lipping and others added 2 commits October 16, 2026 08:25
When both variances are near zero, sqrt(variance_x * variance_y) can
underflow to zero and cause a division by zero. Clamp the divisor to
epsilon instead.

Copy link
Copy Markdown
Owner

Thanks @lippinj for identifying this underflow. I followed up with normalization that divides by the smaller standard deviation first and then the larger, avoiding the scale dependence of an epsilon clamp. I also documented the zero-variance result and added regression tests for tiny, large, and asymmetric scales.

@davisking
davisking merged commit 6baa5c5 into davisking:master Oct 17, 2026
19 of 20 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.

2 participants