-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account for pivoting in sparse Cholesky decompositions (#175)
* Account for pivoting in sparse Cholesky decompositions * Update Project.toml
- Loading branch information
Showing
4 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
using LinearAlgebra, PDMats | ||
using PDMats: chol_lower, chol_upper | ||
|
||
@testset "chol_lower" begin | ||
A = rand(100, 100) | ||
C = A'A | ||
size_of_one_copy = sizeof(C) | ||
@assert size_of_one_copy > 100 # ensure the matrix is large enough that few-byte allocations don't matter | ||
|
||
chol_lower(C) | ||
@test (@allocated chol_lower(C)) < 1.05 * size_of_one_copy # allow 5% overhead | ||
|
||
for uplo in (:L, :U) | ||
ch = cholesky(Symmetric(C, uplo)) | ||
chol_lower(ch) | ||
@test (@allocated chol_lower(ch)) < 33 # allow small overhead for wrapper types | ||
chol_upper(ch) | ||
@test (@allocated chol_upper(ch)) < 33 # allow small overhead for wrapper types | ||
@testset "chol_lower and chol_upper" begin | ||
@testset "allocations" begin | ||
A = rand(100, 100) | ||
C = A'A | ||
size_of_one_copy = sizeof(C) | ||
@assert size_of_one_copy > 100 # ensure the matrix is large enough that few-byte allocations don't matter | ||
|
||
@test chol_lower(C) ≈ chol_upper(C)' | ||
@test (@allocated chol_lower(C)) < 1.05 * size_of_one_copy # allow 5% overhead | ||
@test (@allocated chol_upper(C)) < 1.05 * size_of_one_copy | ||
|
||
for uplo in (:L, :U) | ||
ch = cholesky(Symmetric(C, uplo)) | ||
@test chol_lower(ch) ≈ chol_upper(ch)' | ||
@test (@allocated chol_lower(ch)) < 33 # allow small overhead for wrapper types | ||
@test (@allocated chol_upper(ch)) < 33 # allow small overhead for wrapper types | ||
end | ||
end | ||
|
||
# issue #120 | ||
@testset "correctness with pivoting" begin | ||
A = [2 1 1; 1 2 0; 1 0 2] | ||
x = randn(3) | ||
|
||
# Compute `invquad` without explicit factorization | ||
b = x' * (A \ x) | ||
|
||
@test sum(abs2, PDMats.chol_lower(A) \ x) ≈ b | ||
@test sum(abs2, PDMats.chol_upper(A)' \ x) ≈ b | ||
|
||
for uplo in (:L, :U) | ||
# dense version | ||
ch_dense = cholesky(Symmetric(A, uplo)) | ||
@test sum(abs2, PDMats.chol_lower(ch_dense) \ x) ≈ b | ||
@test sum(abs2, PDMats.chol_upper(ch_dense)' \ x) ≈ b | ||
|
||
# sparse version | ||
if PDMats.HAVE_CHOLMOD | ||
ch_sparse = cholesky(Symmetric(sparse(A), uplo)) | ||
@test sum(abs2, PDMats.chol_lower(ch_sparse) \ x) ≈ b | ||
@test sum(abs2, PDMats.chol_upper(ch_sparse)' \ x) ≈ b | ||
end | ||
end | ||
end | ||
end |
5ca3316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
5ca3316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/92636
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: