From b145abb9e98166b3e5561ecf5283cfcf13ede8dc Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 29 Nov 2024 22:41:36 +0100 Subject: [PATCH] Fix `convert` for `ScalMat` --- src/scalmat.jl | 2 +- test/pdmtypes.jl | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scalmat.jl b/src/scalmat.jl index feabe8a..8144615 100644 --- a/src/scalmat.jl +++ b/src/scalmat.jl @@ -8,7 +8,7 @@ end ### Conversion Base.convert(::Type{ScalMat{T}}, a::ScalMat{T}) where {T<:Real} = a -Base.convert(::Type{ScalMat{T}}, a::ScalMat) where {T<:Real} = ScalMat(a.dim, T(a.value)) +Base.convert(::Type{ScalMat{T}}, a::ScalMat) where {T<:Real} = ScalMat{T}(a.dim, T(a.value)) Base.convert(::Type{AbstractPDMat{T}}, a::ScalMat) where {T<:Real} = convert(ScalMat{T}, a) ### Basics diff --git a/test/pdmtypes.jl b/test/pdmtypes.jl index a8f7530..f31ccb6 100644 --- a/test/pdmtypes.jl +++ b/test/pdmtypes.jl @@ -57,7 +57,7 @@ using Test end @testset "float type conversions" begin - for T in (Float32, Float64), S in (Float32, Float64) + for T in (Float32, Float64), S in (Float32, Float64, Real) A = PDMat(Matrix{T}(I, 2, 2)) for R in (AbstractArray{S}, AbstractMatrix{S}, AbstractPDMat{S}, PDMat{S}) B = @inferred(convert(R, A)) @@ -83,7 +83,8 @@ using Test @test B isa ScalMat{S} @test B == A @test (B === A) === (S === T) - @test (B.value === A.value) === (S === T) + # Conversion to `Real` does not change the scalar `value` + @test (B.value === A.value) === (S === T || S === Real) end if HAVE_CHOLMOD