Fastest way to check for Inf or NaN in an array?

Indeed this is exactly my situation. This NaN/Inf checker is part of SymbolicRegression.jl, where billions of generated expressions need to be evaluated over an input array, and switching from checking NaNs with any(isfinite, x) to isfinite(sum(x)) changed the overall search speed of the entirety of SymbolicRegression.jl by 25%! You can see the measurements on [Performance] Single evaluation results · Issue #73 · MilesCranmer/SymbolicRegression.jl · GitHub - equation evaluation is the bottleneck here so any tiny improvement, even to the NaN checker, counts quite a bit.

1 Like