Simplify cholesky
for ScalMat
and PDiagMat
#182
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We don't have to go through
cholesky(::Diagonal)
in LinearAlgebra (e.g. https://github.com/JuliaLang/julia/blob/28d9f730c1927297fc0cfc415c842968aa1a3a71/stdlib/LinearAlgebra/src/diagonal.jl#L868) when computingcholesky(::ScalMat)
orcholesky(::PDiagMat)
but we can construct theCholesky
object directly without any intermediate steps.This improves performance significantly:
master
Note also that
cholesky(::PDiagMat)
is faster thancholesky(::ScalMat)
due to the reduced number of allocations - the only difference between both code paths is that for theScalMat
the diagonalfill(a.value, a.dim)
is only constructed inside of thecholesky
call whereas it already exists for thePDiagMat
.This PR
Note that with this change, as expected,
cholesky(::ScalMat)
will be faster than the correspondingcholesky(::PDiagMat)
since it only requires a singlesqrt
computation.