Skip to content

Commit 083bd8f

Browse files
added cholesky of cholesky (#55559)
Currently, if you have a cholesky matrix, you cannot call `cholesky` on it again: ``` using LinearAlgebra N = 10 A = randn(N, N) P = Symmetric(A * A' + I) C = cholesky(P) CC = cholesky(C) # this line throws an error ``` This small PR provides the fix. --------- Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
1 parent eaa2edd commit 083bd8f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stdlib/LinearAlgebra/src/cholesky.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ end
551551
# allow packages like SparseArrays.jl to hook into here and redirect to out-of-place `cholesky`
552552
_cholesky(A::AbstractMatrix, args...; kwargs...) = cholesky!(A, args...; kwargs...)
553553

554+
# allow cholesky of cholesky
555+
cholesky(A::Cholesky) = A
556+
554557
## With pivoting
555558
"""
556559
cholesky(A, RowMaximum(); tol = 0.0, check = true) -> CholeskyPivoted

stdlib/LinearAlgebra/test/cholesky.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,14 @@ end
630630
end
631631
end
632632

633+
@testset "cholesky_of_cholesky" begin
634+
for T in (Float64, ComplexF64), uplo in (:U, :L)
635+
A = randn(T, 100, 100)
636+
P = Hermitian(A' * A, uplo)
637+
C = cholesky(P)
638+
CC = cholesky(C)
639+
@test C == CC
640+
end
641+
end
642+
633643
end # module TestCholesky

0 commit comments

Comments
 (0)