@@ -357,7 +357,7 @@ function Base.show(io::IO, ::MIME"text/plain", S::AbstractSparseMatrixCSCInclAdj
357357 show_circular (io, S) && return
358358 io = IOContext (io, :compact => true , :typeinfo => eltype (S), :SHOWN_SET => S)
359359
360- if (screen[1 ] < size (S, 1 ) + 4 ) | (screen[2 ] < 3 size (S, 2 ))
360+ if (screen[1 ] < size (S, 1 ) + 5 ) | (screen[2 ] < 3 size (S, 2 ))
361361 _show_with_braille_patterns (io, S)
362362 else
363363 _show_with_dotted_zeros (io, S)
407407
408408const brailleBlocks = UInt16[' ⠁' , ' ⠂' , ' ⠄' , ' ⡀' , ' ⠈' , ' ⠐' , ' ⠠' , ' ⢀' ]
409409function _show_with_braille_patterns (io:: IO , S:: AbstractSparseMatrixCSCInclAdjointAndTranspose )
410- try
411- zero (eltype (S))
412- catch
413- printstyled (io, " WARNING: could not find generic zero for given elements. expect errors and wrong results\n " , color= :red )
414- end
415-
416410 m, n = size (S)
417411 (m == 0 || n == 0 ) && return show (io, MIME (" text/plain" ), S)
418412
@@ -421,6 +415,14 @@ function _show_with_braille_patterns(io::IO, S::AbstractSparseMatrixCSCInclAdjoi
421415 maxHeight = displaysize (io)[1 ] - 4 # -4 from [Prompt, header, newline after elements, new prompt]
422416 maxWidth = displaysize (io)[2 ] - 2 # -2 from brackets
423417
418+ warn = false
419+ try
420+ zero (eltype (S))
421+ catch
422+ warn = true
423+ maxHeight -= 1
424+ end
425+
424426 # In the process of generating the braille pattern to display the nonzero
425427 # structure of `S`, we need to be able to scale the matrix `S` to a
426428 # smaller matrix with the same aspect ratio as `S`, but fits on the
@@ -464,6 +466,13 @@ function _show_with_braille_patterns(io::IO, S::AbstractSparseMatrixCSCInclAdjoi
464466 rvals = rowvals (parent (S))
465467 rowscale = max (1 , scaleHeight - 1 ) / max (1 , m - 1 )
466468 colscale = max (1 , scaleWidth - 1 ) / max (1 , n - 1 )
469+
470+ if rowscale != 1 || colscale != 1
471+ print (io, " (downscaled to fit on screen)" )
472+ end
473+ println (io, " :" )
474+ warn && printstyled (stderr , " WARNING: could not find generic zero for given elements. expect errors and wrong results\n " , color= :red )
475+
467476 if isa (S, AbstractSparseMatrixCSC)
468477 @inbounds for j in axes (S,2 )
469478 # Scale the column index `j` to the best matching column index
@@ -508,14 +517,14 @@ function _show_with_dotted_zeros(io::IO, S::AbstractSparseMatrixCSCInclAdjointAn
508517 rows, cols, vals = rowvals (parent (S)), ColumnIndices (parent (S)), nonzeros (parent (S))
509518 (S isa Adjoint) | (S isa Transpose) && ((rows, cols) = (cols, rows))
510519
511- align = [alignment (io, val) for val in vals]
520+ align = [isassigned (vals, val) ? alignment (io, vals[ val]) : ( 3 , 3 ) for val in eachindex ( vals) ]
512521 colwidths = [max .((0 , 0 ), align[findall (== (col), cols)]. .. ) for col in axes (S,2 )]
513522 displaysize (io)[2 ] < sum (sum .(colwidths) .+ 2 ) && return _show_with_braille_patterns (io, S)
514523
515524 try
516525 zero (eltype (S))
517526 catch
518- printstyled (io , " WARNING: could not find generic zero for given elements. expect errors and wrong results\n " , color= :red )
527+ printstyled (stderr , " WARNING: could not find generic zero for given elements. expect errors and wrong results\n " , color= :red )
519528 end
520529
521530 for row in axes (S,1 )
@@ -528,7 +537,9 @@ function _show_with_dotted_zeros(io::IO, S::AbstractSparseMatrixCSCInclAdjointAn
528537 print (io, " " ^ l * " ⋅" * (col== axes (S,2 )[end ] ? " " : " " ^ r))
529538 else
530539 l, r = (l+ 1 , r+ 1 ) .- align[index][]
531- print (io, " " ^ l, vals[index][], (col== axes (S,2 )[end ] ? " " : " " ^ r))
540+ print (io, " " ^ l)
541+ isassigned (vals, index[]) ? show (io, vals[index][]) : print (io, " #undef" )
542+ col == axes (S,2 )[end ] || print (io, " " ^ r)
532543 end
533544 end
534545 row == axes (S,1 )[end ] || println (io)
@@ -1951,9 +1962,9 @@ julia> A = sparse([1, 2, 3], [1, 2, 3], [1.0, 0.0, 1.0])
19511962
19521963julia> dropzeros(A)
195319643×3 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
1954- 1.0 ⋅ ⋅
1955- ⋅ ⋅ ⋅
1956- ⋅ ⋅ 1.0
1965+ 1.0 ⋅ ⋅
1966+ ⋅ ⋅ ⋅
1967+ ⋅ ⋅ 1.0
19571968```
19581969"""
19591970dropzeros (A:: AbstractSparseMatrixCSC ) = dropzeros! (copy (A))
@@ -2123,7 +2134,7 @@ argument specifies a random number generator, see [Random Numbers](@ref).
21232134```jldoctest; setup = :(using Random; Random.seed!(0))
21242135julia> sprandn(2, 2, 0.75)
212521362×2 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
2126- -1.20577 ⋅
2137+ -1.20577 ⋅
21272138 0.311817 -0.234641
21282139```
21292140"""
@@ -2150,9 +2161,9 @@ specified.
21502161```jldoctest
21512162julia> spzeros(3, 3)
215221633×3 SparseMatrixCSC{Float64, Int64} with 0 stored entries:
2153- ⋅ ⋅ ⋅
2154- ⋅ ⋅ ⋅
2155- ⋅ ⋅ ⋅
2164+ ⋅ ⋅ ⋅
2165+ ⋅ ⋅ ⋅
2166+ ⋅ ⋅ ⋅
21562167
21572168julia> spzeros(Float32, 4)
215821694-element SparseVector{Float32, Int64} with 0 stored entries
0 commit comments