JuliaLang / LinearAlgebra.jl

Julia Linear Algebra standard library
Other
17 stars 4 forks source link

Bug Report: `SymTridiagonal` Constructor Fails to `show` or `collect` #1100

Open singularitti opened 1 month ago

singularitti commented 1 month ago

I want to run an example in the docs:

julia> using LinearAlgebra

julia> A = SymTridiagonal(fill([1 2; 3 4], 3), fill([1 2; 3 4], 2))
3×3 SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}:
Error showing value of type SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}:
ERROR: MethodError: no method matching zero(::Type{Matrix{Int64}})
The function `zero` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  zero(::Type{Union{}}, Any...)
   @ Base number.jl:310
  zero(::Type{Missing})
   @ Base missing.jl:104
  zero(::Missing)
   @ Base missing.jl:101
  ...

Stacktrace:
  [1] getindex(A::SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}, i::Int64, j::Int64)
    @ LinearAlgebra ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/LinearAlgebra/src/tridiag.jl:457
  [2] alignment(io::IOContext{…}, X::AbstractVecOrMat, rows::Vector{…}, cols::Vector{…}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64, ncols::Int64)
    @ Base ./arrayshow.jl:69
  [3] _print_matrix(io::IOContext{…}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{…}, colsA::UnitRange{…})
    @ Base ./arrayshow.jl:207
  [4] print_matrix(io::IOContext{…}, X::SymTridiagonal{…}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64)
    @ Base ./arrayshow.jl:171
  [5] print_matrix
    @ ./arrayshow.jl:171 [inlined]
  [6] print_array
    @ ./arrayshow.jl:358 [inlined]
  [7] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, X::SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}})
    @ Base ./arrayshow.jl:399
  [8] (::REPL.var"#68#69"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:348
  [9] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:646
 [10] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:334
 [11] display
    @ ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:353 [inlined]
 [12] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [13] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:0
 [14] (::REPL.var"#70#71"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:359
 [15] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:646
 [16] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:357
 [17] (::REPL.var"#do_respond#96"{…})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:988
 [18] #invokelatest#2
    @ ./essentials.jl:1054 [inlined]
 [19] invokelatest
    @ ./essentials.jl:1051 [inlined]
 [20] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2749
 [21] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1456
 [22] (::REPL.var"#75#81"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/REPL/src/REPL.jl:461
Some type information was truncated. Use `show(err)` to see complete types.

julia> A |> collect
ERROR: MethodError: no method matching zero(::Type{Matrix{Int64}})
The function `zero` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  zero(::Type{Union{}}, Any...)
   @ Base number.jl:310
  zero(::Type{Missing})
   @ Base missing.jl:104
  zero(::Missing)
   @ Base missing.jl:101
  ...

Stacktrace:
  [1] getindex
    @ ~/.asdf/installs/julia/1.11.0/share/julia/stdlib/v1.11/LinearAlgebra/src/tridiag.jl:457 [inlined]
  [2] _getindex
    @ ./abstractarray.jl:1358 [inlined]
  [3] getindex
    @ ./abstractarray.jl:1312 [inlined]
  [4] iterate
    @ ./abstractarray.jl:1209 [inlined]
  [5] copyto_unaliased!(deststyle::IndexLinear, dest::Matrix{Matrix{Int64}}, srcstyle::IndexCartesian, src::SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}})
    @ Base ./abstractarray.jl:1088
  [6] copyto!
    @ ./abstractarray.jl:1061 [inlined]
  [7] _collect_indices(indsA::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, A::SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}})
    @ Base ./array.jl:723
  [8] collect
    @ ./array.jl:707 [inlined]
  [9] |>(x::SymTridiagonal{Matrix{Int64}, Vector{Matrix{Int64}}}, f::typeof(collect))
    @ Base ./operators.jl:926
 [10] top-level scope
    @ REPL[3]:1

As you can see, I can neither show it nor collect it. Is this a bug or desired behavior?

System info:

julia> versioninfo()
Julia Version 1.11.0
Commit 501a4f25c2b (2024-10-07 11:40 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 16 × Apple M3 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m3)
jishnub commented 1 month ago

This should be fixed by https://github.com/JuliaLang/julia/pull/50423. Some of the basics required for that PR have already been merged, and it needs a rebase.

singularitti commented 1 month ago

That's good to hear!