From be62b29c39d2d73beb0cf1fb920e7995db521f78 Mon Sep 17 00:00:00 2001 From: vandenman Date: Fri, 15 Sep 2023 14:23:30 +0200 Subject: [PATCH 1/3] mimic constructor from PDMats.jl --- src/psd_mat.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/psd_mat.jl b/src/psd_mat.jl index 0996928..581ed44 100644 --- a/src/psd_mat.jl +++ b/src/psd_mat.jl @@ -23,11 +23,11 @@ struct PSDMat{T<:Real,S<:AbstractMatrix} <: AbstractPDMat{T} PSDMat{T,S}(m::AbstractMatrix{T},c::CholType{T,S}) where {T,S} = new{T, S}(m, c) end -function PSDMat(mat::AbstractMatrix, chol::CholType) - d = LinearAlgebra.checksquare(mat) +function PSDMat(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.")) - PSDMat{eltype(mat),typeof(mat)}(mat, chol) + PSDMat{T, S}(d, convert(S, mat), chol) end PSDMat(mat::Matrix) = PSDMat(mat, cholesky(mat, VERSION >= v"1.8.0-rc1" ? RowMaximum() : Val(true); check=false)) From ba9a55ca686a02ca773dcaa9cac14896a351b8f1 Mon Sep 17 00:00:00 2001 From: vandenman Date: Fri, 15 Sep 2023 14:32:09 +0200 Subject: [PATCH 2/3] add a test for constructing with integer matrices --- test/psd_mat.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/psd_mat.jl b/test/psd_mat.jl index 86faccf..d9a34e6 100644 --- a/test/psd_mat.jl +++ b/test/psd_mat.jl @@ -69,6 +69,20 @@ end @test whiten!( similar(x), pd, x) ≈ whiten!( similar(x), psd, x) @test unwhiten!(similar(x), pd, x) ≈ unwhiten!(similar(x), psd, x) end + + @testset "Constructing from Matrix{<:Integer} works" begin + + m = [ + 1 0 + 0 1 + ] + + for type in (UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt, Int) + @test PSDMat{Float64, Matrix{Float64}} == typeof(PSDMat(type.(m))) + end + + end + end @testset "Degenerate MvNormal" begin From 4fee327a1f1b5b439464e0f03507e4413d6f307e Mon Sep 17 00:00:00 2001 From: vandenman Date: Fri, 20 Oct 2023 11:35:30 +0200 Subject: [PATCH 3/3] fix rebase --- src/psd_mat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psd_mat.jl b/src/psd_mat.jl index 581ed44..7726e45 100644 --- a/src/psd_mat.jl +++ b/src/psd_mat.jl @@ -24,7 +24,7 @@ struct PSDMat{T<:Real,S<:AbstractMatrix} <: AbstractPDMat{T} end function PSDMat(mat::AbstractMatrix, chol::CholType{T,S}) where {T,S} - d = size(mat, 1) + d = LinearAlgebra.checksquare(mat) size(chol, 1) == d || throw(DimensionMismatch("Dimensions of mat and chol are inconsistent.")) PSDMat{T, S}(d, convert(S, mat), chol)