Skip to content

Commit

Permalink
Improve chol_lower and chol_upper (#149)
Browse files Browse the repository at this point in the history
* Improve  `chol_lower` and `chol_upper`

* Increase allowed overhead for Ubuntu x64 on Julia 1.0

Co-authored-by: Andreas Noack <[email protected]>
  • Loading branch information
devmotion and andreasnoack authored Apr 27, 2022
1 parent 8727724 commit 84df00b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PDMats"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.7"
version = "0.11.8"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
13 changes: 10 additions & 3 deletions src/chol.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Accessing a.L directly might involve an extra copy();
# instead, always use the stored Cholesky factor:
chol_lower(a::Cholesky) = a.uplo === 'L' ? a.L : a.U'
chol_upper(a::Cholesky) = a.uplo === 'U' ? a.U : a.L'
# instead, always use the stored Cholesky factor
# Using `a.factors` instead of `a.L` or `a.U` avoids one
# additional `LowerTriangular` or `UpperTriangular` wrapper and
# leads to better performance
function chol_lower(a::Cholesky)
return a.uplo === 'L' ? LowerTriangular(a.factors) : LowerTriangular(a.factors')
end
function chol_upper(a::Cholesky)
return a.uplo === 'U' ? UpperTriangular(a.factors) : UpperTriangular(a.factors')
end

# For a dense Matrix, the following allows us to avoid the Adjoint wrapper:
chol_lower(a::Matrix) = cholesky(Symmetric(a, :L)).L
Expand Down
4 changes: 2 additions & 2 deletions test/chol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ using PDMats: chol_lower, chol_upper
for uplo in (:L, :U)
ch = cholesky(Symmetric(C, uplo))
chol_lower(ch)
@test (@allocated chol_lower(ch)) < 50 # allow small overhead for wrapper types
@test (@allocated chol_lower(ch)) < 33 # allow small overhead for wrapper types
chol_upper(ch)
@test (@allocated chol_upper(ch)) < 50 # allow small overhead for wrapper types
@test (@allocated chol_upper(ch)) < 33 # allow small overhead for wrapper types
end
end

2 comments on commit 84df00b

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/59234

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:

git tag -a v0.11.8 -m "<description of version>" 84df00b41da9573c3e0b7e79bdcde2dda24bb2d5
git push origin v0.11.8

Please sign in to comment.