Skip to content

Commit

Permalink
Merge pull request #117 from mossr/master
Browse files Browse the repository at this point in the history
PDMat: convert Matrix type to the same Cholesky type
  • Loading branch information
andreasnoack committed Sep 17, 2020
2 parents 6d1caa7 + f0c6aea commit 1102683
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pdmat.jl
Expand Up @@ -9,11 +9,11 @@ struct PDMat{T<:Real,S<:AbstractMatrix} <: AbstractPDMat{T}
PDMat{T,S}(d::Int,m::AbstractMatrix{T},c::CholType{T,S}) where {T,S} = new{T,S}(d,m,c)
end

function PDMat(mat::AbstractMatrix,chol::CholType)
function PDMat(mat::AbstractMatrix,chol::CholType{T,S}) where {T,S}
d = size(mat, 1)
size(chol, 1) == d ||
throw(DimensionMismatch("Dimensions of mat and chol are inconsistent."))
PDMat{eltype(mat),typeof(mat)}(d, mat, chol)
PDMat{T,S}(d, convert(S, mat), chol)
end

PDMat(mat::Matrix) = PDMat(mat, cholesky(mat))
Expand Down
2 changes: 2 additions & 0 deletions test/pdmtypes.jl
Expand Up @@ -48,3 +48,5 @@ a = PDMat([1 0.5; 0.5 1])
@inferred whiten(a, ones(2))
@inferred unwhiten(a, ones(2))

# convert Matrix type to the same Cholesky type (#117)
@test PDMat([1 0; 0 1]) == [1.0 0.0; 0.0 1.0]

0 comments on commit 1102683

Please sign in to comment.