@@ -344,6 +344,26 @@ function Base.print_array(io::IO, S::AbstractSparseMatrixCSCInclAdjointAndTransp
344344 end
345345end
346346
347+ """
348+ ColumnIndices(S::AbstractSparseMatrixCSC)
349+
350+ Return the column indices of the stored values in `S`.
351+ This is an internal type that is used in displaying sparse matrices,
352+ and is not a part of the public interface.
353+ """
354+ struct ColumnIndices{Ti,S<: AbstractSparseMatrixCSC{<:Any,Ti} } <: AbstractVector{Ti}
355+ arr :: S
356+ end
357+
358+ size (C:: ColumnIndices ) = (nnz (C. arr),)
359+ # returns the column index of the n-th non-zero value from the column pointer
360+ @inline function getindex (C:: ColumnIndices , i:: Int )
361+ @boundscheck checkbounds (C, i)
362+ colptr = getcolptr (C. arr)
363+ ind = searchsortedlast (colptr, i)
364+ eltype (C)(ind)
365+ end
366+
347367# always show matrices as `sparse(I, J, K)`
348368function Base. show (io:: IO , _S:: AbstractSparseMatrixCSCInclAdjointAndTranspose )
349369 _checkbuffers (_S)
@@ -358,21 +378,7 @@ function Base.show(io::IO, _S::AbstractSparseMatrixCSCInclAdjointAndTranspose)
358378 print (io, " transpose(" )
359379 end
360380 print (io, " sparse(" , I, " , " )
361- if length (I) == 0
362- print (io, eltype (getcolptr (S)), " []" )
363- else
364- print (io, " [" )
365- il = nnz (S) - 1
366- for col in 1 : size (S, 2 ),
367- k in getcolptr (S)[col] : (getcolptr (S)[col+ 1 ]- 1 )
368- print (io, col)
369- if il > 0
370- print (io, " , " )
371- il -= 1
372- end
373- end
374- print (io, " ]" )
375- end
381+ show (io, ColumnIndices (S))
376382 print (io, " , " , K, " , " , m, " , " , n, " )" )
377383 if _S isa Adjoint || _S isa Transpose
378384 print (io, " )" )
0 commit comments