From 6408cb77690f32195479f2053f9705d91dc6492a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 26 Jul 2024 15:05:52 +0530 Subject: [PATCH] Separate parent matrix type from Cholesky parameter --- src/pdmat.jl | 8 ++++---- test/pdmtypes.jl | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pdmat.jl b/src/pdmat.jl index 7f4fcf0..f961545 100644 --- a/src/pdmat.jl +++ b/src/pdmat.jl @@ -1,11 +1,11 @@ """ 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} @@ -13,7 +13,7 @@ function PDMat(mat::AbstractMatrix,chol::Cholesky{T,S}) where {T,S} 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)) diff --git a/test/pdmtypes.jl b/test/pdmtypes.jl index a8f7530..f5b640d 100644 --- a/test/pdmtypes.jl +++ b/test/pdmtypes.jl @@ -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))