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