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

Base.show fails with structural matrices with non-number elements #50377

Open
longemen3000 opened this issue Jul 1, 2023 · 6 comments · Fixed by #50391
Open

Base.show fails with structural matrices with non-number elements #50377

longemen3000 opened this issue Jul 1, 2023 · 6 comments · Fixed by #50391
Labels
arrays [a, r, r, a, y, s] linear algebra Linear algebra

Comments

@longemen3000
Copy link
Contributor

Some matrices (SparseMatrixCSC and Diagonal, as far as i know) depend on a type defining iszero(x::T) and zero(Type{T}) to work. a MWE:

show(IOBuffer(),MIME"text/plain"(),Diagonal(fill(nothing,3)))

version info.

julia> versioninfo()
Julia Version 1.9.1
Commit 147bdf428c (2023-06-07 08:27 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, haswell)
  Threads: 4 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 4

related:

korsbo/Latexify.jl#269

@jishnub jishnub added linear algebra Linear algebra arrays [a, r, r, a, y, s] labels Jul 1, 2023
@longemen3000
Copy link
Contributor Author

longemen3000 commented Jul 2, 2023

this could be solved by:

  1. defining Base.isstored(A::Diagonal,i::Int,j::Int) == i == j ? isstored(A.diag,i) : false

  2. Replacing the code in arrayshow.jl:

    julia/base/arrayshow.jl

    Lines 67 to 72 in 36e188f

    for i in rows # plumb down and see what largest element sizes are
    if isassigned(X,i,j)
    aij = alignment(io, X[i,j])::Tuple{Int,Int}
    else
    aij = undef_ref_alignment
    end

to:

if isstored(X,i,j) && isassigned(X,i,j)
    aij = alignment(io, X[i,j])::Tuple{Int,Int}
else
    aij = undef_ref_alignment
end

@vtjnash
Copy link
Member

vtjnash commented Jul 6, 2023

I am not certain about the proposed fix there, since the code expects getindex to work, and then calls Base.replace_in_print_matrix to call Base.replace_with_centered_mark on the resulting element repr.

@longemen3000
Copy link
Contributor Author

The issue is not fixed with #50391, but defines the necessary functions to work on a fix

@vtjnash vtjnash reopened this Jul 6, 2023
@vtjnash
Copy link
Member

vtjnash commented Jul 6, 2023

Right, github got confused by the text there, but my uncertainty remains over the proposed answer here

@longemen3000
Copy link
Contributor Author

Yeah, I will need to see what to do about that, but at least there is now a way to detect if an element of a matrix is stored or not

@vtjnash
Copy link
Member

vtjnash commented Jul 6, 2023

Yeah, that seemed to be the goal of a5e032e (#33821), which originally started to add that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] linear algebra Linear algebra
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants