Open Gattocrucco opened 1 year ago
Sorry for the long response time. I don't understand the details but a speedup is definitely welcome!
Ok, I'll open a pull request then
Can this be closed now @Gattocrucco ?
Duh this slipped my from radar.
No I haven't made the PR, and I see the code on main is still the old unoptimized one.
Is your feature request related to a problem? Please describe.
Using
optimize.minimize(..., method='l-bfgs-b').inv_hess.todense()
(code) I noticed its implementation does $O(n^3)$ operations when it could be $O(n^2)$. I made a few tries at optimizing it. The methods I considered are:1) modifying
LbfgsInvHessProduct.todense
to avoid matrix by matrix multiplications 2) implementingLbfgsInvHessProduct._matmat
and doingobj.matmat(eye(*obj.shape))
3) using the stock implementation ofLbfgsInvHessProduct._matmat
Code and benchmark:
Benchmark result with n = 1000:
With n = 10:
With n = 10000:
Conclusions: the direct rewrite of
todense
is slower than using the matvec operation, and the existing matmat is slower than the reimplementation for small sizes because it involves a python loop (code).I can do a PR for this if interested.
Describe the solution you'd like.
No response
Describe alternatives you've considered.
No response
Additional context (e.g. screenshots, GIFs)
No response