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

Broadcasted scaled sum of complex sparse arrays produces eltype Any

Open sethaxen opened this issue 4 years ago • 1 comments

On Julia 1.6 and master, broadcasting the scaled sum of 5-6 complex sparse arrays sporadically produces eltypes of type Any. Examples:

julia> using SparseArrays

julia> A, B, C, D, E, F = ntuple(_ -> sprand(ComplexF64, 100, 100, 0.1), 6);

julia> (A .+ B .+ C .+ D .+ E .+ F) |> eltype
ComplexF64 (alias for Complex{Float64})

julia> (1 .* A .+ B .+ C .+ D .+ E .+ F) |> eltype
ComplexF64 (alias for Complex{Float64})

julia> (1 .* A .+ 2 .* B .+ C .+ D .+ E .+ F) |> eltype
Any

julia> (1 .* A .+ 2 .* B .+ C .+ D .+ E) |> eltype
Any

julia> (1 .* A .+ 2 .* B .+ C .+ D) |> eltype
ComplexF64 (alias for Complex{Float64})

This does not happen if the matrices have an eltype of Float64. This same issue happened with Julia 1.0-1.2. For Julia 1.3-1.5, the cases with eltype Any had eltype Complex (not ComplexF64).

sethaxen avatar Apr 11 '21 20:04 sethaxen

Duplicate of JuliaLang/SparseArrays.jl#59.

martinholters avatar Jul 23 '21 09:07 martinholters