SMU-clusters / ssptools

MIT License
2 stars 0 forks source link

fix divide-by-zero bug in `Pk` helper function #4

Closed nmdickson closed 1 year ago

nmdickson commented 1 year ago

Pk is a helper function representing the analytic solution of the integral over the mass. This solution takes a different form when a == k, as the typical solution would have a divide by zero error.

The previous fix for this assumed a couple erroneous things; firstly that one or the other solution would be valid for all inputs submitted to the method in a single call, and secondly that, when called on arrays, numpy would raise a divide by zero array, rather than just giving a nan.

This commit adds a more robust, but hopefully still efficient, fix.

This fix works by first computing the typical solution for all, even when it errors (thus the ignore warnings). This requires coercing all inputs to numpy arrays or floats, to avoid the base python ZeroDivisionError. Then the other solution is used to fill in any gaps where a==k, if it is necessary (it usually isn't).