Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate parent matrix type from Cholesky parameter #207

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading