Skip to content

Commit

Permalink
Fix convert for ScalMat
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Nov 29, 2024
1 parent 592634b commit b145abb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/scalmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/pdmtypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit b145abb

Please sign in to comment.