rodluger / Limbdark.jl

Analytical transit light curves for limb darkened stars
MIT License
14 stars 4 forks source link

Speeding up multiple cel_bulirsch calculations with same k_c. #26

Closed ericagol closed 5 years ago

ericagol commented 6 years ago

One of the more expensive parts of cel_bulirsch(k_c,p,a,b) is the square-root operation, \nu_{i+1} = 2\sqrt{\nu_i \mu_i}, that is performed for each iteration. It turns out that the terms involved in the square-root only depend on k_c, but not on p, a, or b. So, when computing s_2, when we evaluate the necessary three elliptic integrals, we can save computing time by computing all three of these at once, and then we will only need to do the square roots 1/3 as much of the time!

It turns out that division is almost as expensive as square-root; these are both about 10x the expense of addition or multiplication. https://github.com/eschnett/AutoBenchmark.jl

There are two */p terms in cel which could be combined to be optimized. All to say, these elliptic integrals may be faster to evaluate together rather than alone. I will write a method that works with vector a, b, and p values.

rodluger commented 6 years ago

Interesting! I'd love to use this to speed up starry as well.

ericagol commented 5 years ago

This has been implemented, and it did in fact speed up the elliptic integral computation.