SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

Incomplete promotion rules for sparse matrices

Open jebej opened this issue 8 years ago • 5 comments

promote_type(typeof(sprand(10,10,0.1)),typeof(sprand(ComplexF64,10,10,0.1)))
SparseMatrixCSC{Tv,Int64} where Tv

vs in the dense case:

promote_type(typeof(rand(10,10)),typeof(rand(ComplexF64,10,10)))
Array{Complex{Float64},2}

jebej avatar Jul 28 '17 14:07 jebej

Is this ok:

promote_rule(::Type{SparseMatrixCSC{T1,S1}},::Type{SparseMatrixCSC{T2,S2}}) where {T1,T2,S1,S2} = SparseMatrixCSC{promote_type(T1,T2),promote_type(S1,S2)}

jebej avatar Jul 28 '17 14:07 jebej

JuliaLang/julia#22757

fredrikekre avatar Jul 28 '17 14:07 fredrikekre

Does JuliaLang/julia#22757 fix this problem?

jebej avatar Sep 08 '17 20:09 jebej

I have been using the following locally:

promote_rule{T1,T2,S1,S2}(::Type{SparseMatrixCSC{T1,S1}},::Type{SparseMatrixCSC{T2,S2}}) = SparseMatrixCSC{promote_type(T1,T2),promote_type(S1,S2)}
promote_rule{T1,S1,T2,S2<:AbstractMatrix{T2}}(::Type{SparseMatrixCSC{T1,S1}},::Type{S2}) = Matrix{promote_type(T1,T2)}
promote_rule{T1,S1,T2,S2<:AbstractMatrix{T2}}(::Type{S2},::Type{SparseMatrixCSC{T1,S1}}) = Matrix{promote_type(T1,T2)}

should I make a PR?

jebej avatar Mar 19 '18 14:03 jebej

Revisiting old sparse issues. This does need the PR.

ViralBShah avatar Jan 17 '22 12:01 ViralBShah