LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

Unnecessary scalar indexing in `logdet(C::Cholesky)`

Open sharanry opened this issue 3 years ago • 3 comments

Related: https://github.com/JuliaGaussianProcesses/AbstractGPs.jl/pull/329 https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/cholesky.jl#L672

sharanry avatar Jul 21 '22 12:07 sharanry

Can't we do sum(log, real.(diag(C.factors))) ?

sharanry avatar Jul 21 '22 13:07 sharanry

Have you tried it with allowscalar(false) (or whatever the correct syntax is)? I don't think diag(C.factors) does anything else than scalar indexing and collecting the resulting vector. That would be worse in general, because it adds an allocation.

dkarrasch avatar Jul 22 '22 15:07 dkarrasch

Seems like a minimal change is:

 @inbounds for i in diagind(C.factors)
    dd += log(real(C.factors[i]))
end

Probably that doesn't help with OP's case, however?

stevengj avatar Jul 26 '22 15:07 stevengj