Skip to content

Commit

Permalink
Separate parent matrix type from Cholesky parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jul 26, 2024
1 parent 53bf0d0 commit 6408cb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pdmat.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""
Full positive definite matrix together with a Cholesky factorization object.
"""
struct PDMat{T<:Real,S<:AbstractMatrix} <: AbstractPDMat{T}
mat::S
struct PDMat{T<:Real,S<:AbstractMatrix{T},M<:AbstractMatrix{T}} <: AbstractPDMat{T}
mat::M
chol::Cholesky{T,S}

PDMat{T,S}(m::AbstractMatrix{T},c::Cholesky{T,S}) where {T,S} = new{T,S}(m,c)
PDMat{T,S}(m::M, c::Cholesky{T,S}) where {T,S<:AbstractMatrix{T},M<:AbstractMatrix{T}} = new{T,S,M}(m,c)
end

function PDMat(mat::AbstractMatrix,chol::Cholesky{T,S}) where {T,S}
d = LinearAlgebra.checksquare(mat)
if size(chol, 1) != d
throw(DimensionMismatch("Dimensions of mat and chol are inconsistent."))
end
PDMat{T,S}(convert(S, mat), chol)
PDMat{T,S}(convert(AbstractMatrix{T}, mat), chol)
end

PDMat(mat::AbstractMatrix) = PDMat(mat, cholesky(mat))
Expand Down
5 changes: 5 additions & 0 deletions test/pdmtypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ using Test
end
end

@testset "PDMat fro SymTridiagonal" begin
S = SymTridiagonal(fill(4,4), fill(1,3))
@test PDMat(S) == S
end

@testset "AbstractPDMat constructors (#136)" begin
x = rand(10, 10)
A = Array(Symmetric(x' * x + I))
Expand Down

0 comments on commit 6408cb7

Please sign in to comment.