Skip to content

Conversation

@ElOceanografo
Copy link
Contributor

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)

It produces the correct answers, but is relatively slow and needs work on optimization. The main bottleneck is extracting the factors via umf_extract, so directly indexing into the UmfpackLU struct should speed it up...though I'm not sure how to do that.

@dkarrasch dkarrasch added the sparse Sparse arrays label Nov 18, 2020
@ViralBShah
Copy link
Member

@ElOceanografo Maybe address the comments and get this merged?

@ElOceanografo
Copy link
Contributor Author

ElOceanografo commented Jan 22, 2021

Sorry, lost track of this! Comments were straightforward, but this is still very slow. Benchmarking on my computer produces the following timings:

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

@btime logabsdet($A) # 549.719 ms (91 allocations: 278.57 MiB)
@btime logabsdet($F) # 79.753 ms (25 allocations: 86.26 MiB)
@btime logabsdet($Adense) # 46.192 ms (3 allocations: 30.53 MiB)
@btime logabsdet($Fdense) # 20.099 μs (0 allocations: 0 bytes)

Profiling shows most of the time in the first benchmark is spent here, while most of the time in the second benchmark is spent extracting the fields from the LU factorization in this line. I know next to nothing about the internals of SuiteSparse, maybe someone who does can chime in? Using the sparse factorization should in principle be faster than converting to a dense matrix and falling back on the default method, right?

Edit: added timing for logabsdet(Fdense)

@ViralBShah
Copy link
Member

The problem with testing on random sparse matrices is that the LU factorization gets a lot of fill-in, making it almost dense. In this case, the filled up factors end up having 50% nonzeros. In reality, most sparse problems coming from a real application have more structure and significantly less fill-in.

@ViralBShah
Copy link
Member

ViralBShah commented Jan 22, 2021

UmfpackLU is an opaque object, but this ends up spending a bunch of time converting the opaque object, when all you really want are the diagonals. I still think this should be ok to merge. Try some experiments with the identity matrix?

At scale, the U[i,i] indexing could end up being slow, but it is easy to pick that entry from the sparse data structure directly, much faster. Worth doing some experiments with a million size matrix.

@ViralBShah
Copy link
Member

Probably also rebase to master.

@ElOceanografo
Copy link
Contributor Author

Running the same benchmark with A = spdiagm(0 => ones(n)) is still slower than the dense version (189.999 μs (81 allocations: 1.11 MiB)). If you know where the UmfpackLU object's layout is documented, I can try to figure out how to pick the diagonal values out directly. But if you think this is worth merging as-is I can go ahead and rebase it.

@ViralBShah
Copy link
Member

That will have to be in the UmfpackLU documentation or maybe even the Umfpack source code. I had trouble compiling this PR (following the gh command line) instructions and did end up rebasing it to master. Trying to get it working so I can try a few examples myself.

@ElOceanografo
Copy link
Contributor Author

I did some digging in the Umfpack documentation, and it should be possible to extract just the U matrix and scaling factors Rs by passing null values in for the other arguments (see section 13, top of page 94, in the pdf here: https://fossies.org/linux/SuiteSparse/UMFPACK/Doc/UMFPACK_UserGuide.pdf). That isn't currently possible through the SuiteSparse.UMFPACK wrappers, which is probably worth a separate issue.

rssdev10 and others added 17 commits May 4, 2021 00:05
* deps: upgrade CSL

This adds the `.so` files, particularly for libatomic that we need on FreeBSD

* build: define uninstall targets even for deps that are not always installed

Most commonly csl, llvm-tools, and clang, but there were other ones in
the wrong lists also.
This adds a convenience method to be able to essentially wrap an
arbitrary task in a try/catch/log block conveniently.
Fixes JuliaLang#40303. When printing values to fixed widths through the
`Ryu.writefixed` or `Ryu.writeexp` routines, we have a "cleanup" section
after a value has been printed to see if it needs to be rounded given
the input precision and width. The core issue was the terminating
condition: it previously only checked if we were at the start of a
buffer or had encountered the `'-'` character. Via Printf formatting,
however, it also allows specifying the `'+'` and `' '` characters to
preceed a formatted number. Hence, in the OP, the `'1'` character was
getting "rounded" up to the `','` character. The fix here is correctly
checking if the `plus` or `space` options were passed to the routine and
if so, include those in our rounding termination check. The original
issue only reported the "plus" case for the `f` format specifier, but
the same bug affects the `e` format specifier and the "space" option.
jishnub and others added 24 commits May 4, 2021 00:05
JuliaLang#39999)

* reduced_index for BigInt UnitRanges

* Add tests for Integer subtypes

* use OneTo constructor instead of typeof

Co-authored-by: Simeon Schaub <[email protected]>

Co-authored-by: Simeon Schaub <[email protected]>
* Make opnorm( 1x0 matrix ) zero

Fixes #40370.

* more opnorm tests

* remove convert on svdvals

Co-authored-by: Daniel Karrasch <[email protected]>
Co-authored-by: akaysh <[email protected]>
Co-authored-by: Sacha Verweij <[email protected]>

Co-authored-by: akaysh <[email protected]>
Co-authored-by: Sacha Verweij <[email protected]>
…s`, `Base.preferences_names`, and `Artifacts.artifact_names` always have the same length (JuliaLang#40618)

* Add tests to make sure that `Base.project_names`, `Base.manifest_names`, `Base.preferences_names`, and `Artifacts.artifact_names` always have the same length

* Add a comment explaining why we have these tests
* update all checksums and pcre rules to generate them

Co-authored-by: Jameson Nash <[email protected]>
@ViralBShah
Copy link
Member

Something has gone wrong with this PR.

@ElOceanografo
Copy link
Contributor Author

I tried to rebase it to master last night and may have messed it up. I can try to fix it, or if it's easier I could close it and open a new one with the same changes...

@ViralBShah
Copy link
Member

If its easier to do a new PR, just go for it.

@ElOceanografo
Copy link
Contributor Author

Ok, closing this, will open a new one in a second.

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