Skip to content

Conversation

@ElOceanografo
Copy link
Contributor

Replacement for #38476 after I borked a rebase. Will fix JuliaLang/LinearAlgebra.jl#788. This new method is a direct translation of the dense logabsdet(::LU) method in LinearAlgebra:

function logabsdet(F::LU{T}) where T # return log(abs(det)) and sign(det)

Performance problems mentioned in the previous PR should have been fixed by #40663.

@dkarrasch dkarrasch added linear algebra Linear algebra sparse Sparse arrays labels May 5, 2021
Co-authored-by: Daniel Karrasch <[email protected]>
@dkarrasch
Copy link
Member

I have another way to compute the sign of the permutation, inspired by code from Permutations.jl. Should I push it here and you profile your benchmark cases with it?

@ElOceanografo
Copy link
Contributor Author

Yes, that would be great!

@ElOceanografo
Copy link
Contributor Author

That's an improvement! I also did some more testing and you were right, the call to diag was taking longer than indexing directly into U as before, so I switched back.

This method is still a bit slower than the default version for a dense LinearAlgebra.LU object...see simple benchmarks below. Profiling shows most of that time is spent getting U, Rs, p, and q out of the UMFPACK object. But when you factor in the time spent performing the factorization, calling logabsdet on a sparse matrix is now a) possible, b) correct, and c) much faster than the dense version. So I think this is probably ok to merge at this point, unless you've got any other ideas for improvement?

using LinearAlgebra, SparseArrays, BenchmarkTools
n = 2000
pnz = 0.0001
A = sprandn(n, n, pnz); A = A'A + I
Adense = Matrix(A)
F = lu(A)
Fdense = lu(Adense)


@btime logabsdet($F) # 58.337 μs (13 allocations: 127.23 KiB)
@btime logabsdet($Fdense) # 30.058 μs (0 allocations: 0 bytes)
@btime logabsdet($A) # 252.128 μs (77 allocations: 1.05 MiB)
@btime logabsdet($Adense) # 43.563 ms (3 allocations: 30.53 MiB)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear algebra Linear algebra sparse Sparse arrays

Projects

None yet

Development

Successfully merging this pull request may close these issues.

logabsdet unimplemented for sparse matrices

3 participants