Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overflow errors with _get_radial_sum #980

Merged
merged 3 commits into from
Aug 22, 2024
Merged

Conversation

cmaloney111
Copy link
Contributor

The _get_radial_sum function currently overflows for large autocorrelation values. This can lead to negative values for the probability in the two_point_correlation function.

Problem
When using the two_point_correlation function with large autocorrelation values, I encountered overflow errors:

  • When using porespy through Anaconda, the overflow results in negative probability values (see attached screenshot).
  • On my local machine (where I copied the two_point_correlation code), it causes an OverflowError with the message "Python int too large to convert to C long."

Solution
To fix this issue, I:

  • Specified the dtype of radial_sum as float64 to handle large values without overflow.
  • Added a check to avoid division by zero using if np.any(mask).

Two Point Correlation

@jgostick
Copy link
Member

Thanks for this. This reminds me of another bug I fixed recently, where something np.sum(im) would use the dtype of im when doing the sum. I fixed it by specifying the dtype in the sum function, similar to what you did here. Thanks for catching this.

@cmaloney111
Copy link
Contributor Author

No problem!

@jgostick jgostick merged commit d6146fc into PMEAL:dev Aug 22, 2024
1 check 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.

3 participants