SpecialFunctions.jl icon indicating copy to clipboard operation
SpecialFunctions.jl copied to clipboard

Extensive use of abs for complex tolerances

Open weymouth opened this issue 1 year ago • 2 comments

I just profiled expintx(1,z::Complex) and found the majority of the time is spent checking the convergence using abs(stuff) < ϵ. Would there be a problem with simply squaring all of these and using abs2(stuff) < ϵ^2? This is much much faster, especially when stuff::Complex.

Since ϵ=10eps(T), I suppose that could lead to some issues. But I would much prefer to slightly reduce the tolerance than the current waste of compute.

I'm happy to do the PR if it's likely to get merged in.

weymouth avatar Mar 18 '24 22:03 weymouth

Or we could just use fastabs. That should be harmless, right?

weymouth avatar Mar 18 '24 22:03 weymouth

Yes, fastabs should be fine here. Not sure how that compares to abs2, but with abs2 you also need to be careful of over/underflow.

stevengj avatar Mar 19 '24 14:03 stevengj