@@ -227,22 +227,37 @@ end
227227Base. replace_in_print_matrix (A:: AbstractSparseMatrix , i:: Integer , j:: Integer , s:: AbstractString ) =
228228 Base. isstored (A, i, j) ? s : Base. replace_with_centered_mark (s)
229229
230- function Base. show (io:: IO , :: MIME"text/plain" , S :: AbstractSparseMatrixCSC )
230+ function Base. array_summary (io:: IO , S :: AbstractSparseMatrixCSC , dims :: Tuple{Vararg{Base.OneTo}} )
231231 _checkbuffers (S)
232232 xnnz = nnz (S)
233233 m, n = size (S)
234234 print (io, m, " ×" , n, " " , typeof (S), " with " , xnnz, " stored " ,
235235 xnnz == 1 ? " entry" : " entries" )
236- if ! (m == 0 || n == 0 )
237- print (io, " :" )
238- show (IOContext (io, :typeinfo => eltype (S)), S)
236+ nothing
237+ end
238+
239+ # called by `show(io, MIME("text/plain"), ::AbstractSparseMatrixCSC)`
240+ function Base. print_array (io:: IO , S:: AbstractSparseMatrixCSC )
241+ if max (size (S)... ) < 16
242+ Base. print_matrix (io, S)
243+ else
244+ _show_with_braille_patterns (io, S)
239245 end
240246end
241247
242- Base. show (io:: IO , S:: AbstractSparseMatrixCSC ) = Base. show (convert (IOContext, io), S:: AbstractSparseMatrixCSC )
248+ # always show matrices as `sparse(I, J, K)`
249+ function Base. show (io:: IO , S:: AbstractSparseMatrixCSC )
250+ _checkbuffers (S)
251+ # can't use `findnz`, because that expects all values not to be #undef
252+ I = rowvals (S)
253+ J = [col for col = 1 : size (S, 2 ) for k = getcolptr (S)[col] : (getcolptr (S)[col+ 1 ]- 1 )]
254+ K = nonzeros (S)
255+ m, n = size (S)
256+ print (io, " sparse(" , I, " , " , J, " , " , K, " , " , m, " , " , n, " )" )
257+ end
243258
244259const brailleBlocks = UInt16[' ⠁' , ' ⠂' , ' ⠄' , ' ⡀' , ' ⠈' , ' ⠐' , ' ⠠' , ' ⢀' ]
245- function _show_with_braille_patterns (io:: IOContext , S:: AbstractSparseMatrixCSC )
260+ function _show_with_braille_patterns (io:: IO , S:: AbstractSparseMatrixCSC )
246261 m, n = size (S)
247262 (m == 0 || n == 0 ) && return show (io, MIME (" text/plain" ), S)
248263
@@ -303,18 +318,6 @@ function _show_with_braille_patterns(io::IOContext, S::AbstractSparseMatrixCSC)
303318 foreach (c -> print (io, Char (c)), @view brailleGrid[1 : end - 1 ])
304319end
305320
306- function Base. show (io:: IOContext , S:: AbstractSparseMatrixCSC )
307- _checkbuffers (S)
308- if max (size (S)... ) < 16 && ! (get (io, :compact , false ):: Bool )
309- ioc = IOContext (io, :compact => true )
310- println (ioc)
311- Base. print_matrix (ioc, S)
312- return
313- end
314- println (io)
315- _show_with_braille_patterns (io, S)
316- end
317-
318321# # Reshape
319322
320323function sparse_compute_reshaped_colptr_and_rowval! (colptrS:: Vector{Ti} , rowvalS:: Vector{Ti} ,
0 commit comments