QuantEcon / ContinuousDPs.jl

Continuous state dynamic programming
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

ENH: performance boost by vectorizing call to funeval #18

Closed sglyon closed 6 years ago

sglyon commented 6 years ago

the BasisMatrices routines are unfortunately not very efficient when evaluated at a single point.

This pull request tries to get around this by vectorizing the call to funeval in the innermost part of the s_wise_max set of routines.

The speedup was considerable. When solving a cdp with VFI at a tol of 1e-3, the monetary policy example went from 25 to 4 seconds and the optimal growth example went from 70 seconds to 8 seconds.

Another (related) change is using type parameters for all the function fields of ContinuousDP. Function is an abstract type in Julia 0.6, and all functions are concrete subtypes of Function. Thus, we if let ContinuousDP parameterize on these concrete types, all uses of cdp.(f|g|x_lb|x_ub) will be type-inferrable by the compiler.


EDIT

I still believe there are many performance optimizations on the table, but this is a first step.

I really should have focused on getting the API stable, but I couldn't resist.


oyamad commented 6 years ago

(Added some commits and rebased.)

Many thanks, this is great!

sglyon commented 6 years ago

Looks good to me. Happy to see that performance boost!