Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix convert for ScalMat #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PDMats"
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
version = "0.11.31"
version = "0.11.32"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
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
Loading