-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid allocation when accessing cholesky
factors (.L, .U)
#42920
base: master
Are you sure you want to change the base?
Conversation
I opened this PR as suggested by @dlfivefifty in the linked discourse thread (which I found following discussion with @KristofferC) and tagging the people who also reviewed #38389: @Keno, @dkarrasch. |
I believe this makes the return type a |
If you think this change should not get merged, because having a concrete return type is the most important consideration, then I can change it to add a comment that explains the reasons for explicit copy, plus making this more explicit in the docstrings (which currently give no indication at all that accessing a field would involve allocations, which I would argue is very counter-intuitive behaviour - property getters shouldn't add any overhead!). A (higher effort, probably breaking, perhaps cleaner overall) change to get both performance (minimal allocations) and a concrete return type would be to turn |
I think this can mostly be fixed with documentation. You can specify if you want the |
That's assuming that you're both in control of the code constructing the factorization, and in the code using it. Which is not necessarily the case in practice. E.g. I have code that gets passed an |
In master, accessing fields
L
orU
ofCholesky
orCholeskyPivoted
calls copy() on the transpose. Here I add tests thayt check that the accessors don't allocate more memory than is needed for e.g. the Adjoint() construction, and remove the unnecessary copy(). Generally julia seems to be trying hard to avoid unnecessary allocations, so I would consider this to be a bugfix, not a breaking change.There is a related discourse thread: https://discourse.julialang.org/t/implementation-for-accessing-cholesky-factors/56219
Side note 1: there is also a copy() in the definition of
_chol!(A::AbstractMatrix, ::Type{UpperTriangular})
- it's a bit less clear to me in what cases this will get run and whether it's okay to remove the copy(), so let me know if you think it'd be worth spending the time to go deeper into that also.Side note 2: some of the code tests uplo using
Cuplo === char_uplo(d)
, some of it usingsym_uplo(Cuplo) == d
, is there any particular reason for this, or would it be worth unifying it?