Skip to content

Commit

Permalink
Fix promotion of element types when converting a Vector or Matrix
Browse files Browse the repository at this point in the history
to a CHOLMOD.Dense
  • Loading branch information
andreasnoack committed Jan 27, 2016
1 parent 5ac7f75 commit 2b6c143
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,15 @@ get_perm(FC::FactorComponent) = get_perm(Factor(FC))
#########################

# Convertion/construction
function convert{T<:VTypes}(::Type{Dense}, A::VecOrMat{T})
function convert(::Type{Dense}, A::VecOrMat)
T = promote_type(eltype(A), Float64)
d = allocate_dense(size(A, 1), size(A, 2), stride(A, 2), T)
s = unsafe_load(d.p)
unsafe_copy!(s.x, pointer(A), length(A))
for i in eachindex(A)
unsafe_store!(s.x, A[i], i)
end
d
end
convert(::Type{Dense}, A::VecOrMat) = Dense(float(A))
convert(::Type{Dense}, A::Sparse) = sparse_to_dense(A)

# This constructior assumes zero based colptr and rowval
Expand Down
4 changes: 4 additions & 0 deletions test/sparsedir/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,7 @@ Fnew = deserialize(b)
@test_throws ArgumentError diag(Fnew)
@test_throws ArgumentError logdet(Fnew)

# Issue with promotion during conversion to CHOLMOD.Dense
@test SparseArrays.CHOLMOD.Dense(ones(Float32, 5)) == ones(5, 1)
@test SparseArrays.CHOLMOD.Dense(ones(Int, 5)) == ones(5, 1)
@test SparseArrays.CHOLMOD.Dense(ones(Complex{Float32}, 5, 2)) == ones(5, 2)

0 comments on commit 2b6c143

Please sign in to comment.