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

eltype not inferred in broadcasting involving sparse arrays #273

Open
jishnub opened this issue May 24, 2023 · 0 comments
Open

eltype not inferred in broadcasting involving sparse arrays #273

jishnub opened this issue May 24, 2023 · 0 comments

Comments

@jishnub
Copy link
Member

jishnub commented May 24, 2023

julia> using LinearAlgebra, SparseArrays, StructArrays

julia> D = sparse(Diagonal(Float64[1:4;]));

julia> S = StructArray{ComplexF64}((D, D));

julia> ComplexF64.(S)
4×4 SparseMatrixCSC{Any, Int64} with 4 stored entries:
Error showing value of type SparseMatrixCSC{Any, Int64}:
ERROR: MethodError: no method matching zero(::Type{Any})

Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T
   @ Base missing.jl:105
  zero(::Union{Type{P}, P}) where P<:Dates.Period
   @ Dates ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/Dates/src/periods.jl:51
  zero(::AbstractIrrational)
   @ Base irrationals.jl:151
  ...

Stacktrace:
  [1] zero(#unused#::Type{Any})
    @ Base ./missing.jl:106
  [2] getindex
    @ ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/SparseArrays/src/sparsematrix.jl:2504 [inlined]
  [3] isassigned(::SparseMatrixCSC{Any, Int64}, ::Int64, ::Int64)
    @ Base ./abstractarray.jl:606
  [4] alignment(io::IOContext{Base.TTY}, X::AbstractVecOrMat, rows::Vector{Int64}, cols::Vector{Int64}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64, ncols::Int64)
    @ Base ./arrayshow.jl:68
  [5] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
    @ Base ./arrayshow.jl:207
  [6] print_matrix(io::IOContext{Base.TTY}, X::SparseMatrixCSC{Any, Int64}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64)
    @ Base ./arrayshow.jl:171
  [7] print_matrix
    @ ./arrayshow.jl:171 [inlined]
  [8] print_array(io::IOContext{Base.TTY}, S::SparseMatrixCSC{Any, Int64})
    @ SparseArrays ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/SparseArrays/src/sparsematrix.jl:339
  [9] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::SparseMatrixCSC{Any, Int64})
    @ Base ./arrayshow.jl:399
 [10] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:276
 [11] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:557
 [12] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:262
 [13] display
    @ ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:281 [inlined]
 [14] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [15] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
 [16] invokelatest
    @ ./essentials.jl:813 [inlined]
 [17] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:305
 [18] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:287
 [19] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:557
 [20] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:285
 [21] (::REPL.var"#do_respond#80"{Bool, Bool, REPL.var"#93#103"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:899
 [22] #invokelatest#2
    @ ./essentials.jl:816 [inlined]
 [23] invokelatest
    @ ./essentials.jl:813 [inlined]
 [24] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/LineEdit.jl:2647
 [25] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/REPL/src/REPL.jl:1300
 [26] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:514

However, this works:

julia> D = Diagonal(Float64[1:4;]);

julia> S = StructArray{ComplexF64}((D, D));

julia> ComplexF64.(S)
4×4 Diagonal{ComplexF64, Vector{ComplexF64}}:
 1.0+1.0im                              
           2.0+2.0im                    
                     3.0+3.0im          
                               4.0+4.0im
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant