Skip to content

pretty-printing sparse-Hermitian matrices #657

Description

@stevengj

We have specialized display of sparse matrices, but it isn't used when the matrix is wrapped in Hermitian:

For example, this looks nice:

julia> S = sprand(1000,1000,0.0001); S = S + S' + I
1000×1000 SparseMatrixCSC{Float64, Int64} with 1182 stored entries:
⎡⠱⢆⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠀⠀⠠⠀⠀⠀⠀⠠⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⎤
⎢⠈⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠰⠀⠀⠀⠀⠠⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠈⠀⠄⠀⠠⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠈⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠂⠀⠀⠁⢂⠀⡔⠈⠀⠀⠀⠀⠀⠠⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠤⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠕⢅⢀⠀⠀⢐⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⢀⠀⎥
⎢⠀⠀⠄⠀⠂⠀⠠⠀⠀⠐⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⢀⠀⠀⡀⠀⎥
⎢⠀⠀⠀⠀⠀⠁⠀⠀⢀⢀⠀⠀⠑⢄⠄⠀⠀⠀⢀⠀⠠⠂⠀⠀⠀⠀⠀⠁⠀⠂⠠⠀⠀⠀⠀⢀⠄⠈⠀⠀⎥
⎢⣀⠀⠀⠀⡀⠂⠡⢀⠀⡀⠀⠀⠀⠁⠑⢄⠐⠀⠀⠀⠀⠀⠀⠀⢀⠀⠂⠀⠀⠈⠀⠀⠀⠀⠀⠄⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⢀⠤⠀⠀⠀⠀⠀⠀⠐⠀⠑⢄⢄⠀⠀⠀⡂⠀⠀⢀⠀⢀⠀⠀⠀⠀⠀⠀⡀⠀⠠⠀⠀⠀⎥
⎢⠀⠂⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀⠐⠀⠀⠀⠑⠑⢄⠀⠀⠀⠀⠀⠀⠠⠀⠀⠀⡀⠄⠀⠠⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠠⠂⠀⠀⠀⠀⠀⠀⠑⢄⠈⠀⠠⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⎥
⎢⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠈⠀⠀⠂⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠐⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠐⠀⠀⠀⠐⠀⢀⠀⠀⠀⠂⠀⠀⡑⢌⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠈⠀⠀⢀⠀⠂⠠⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⠁⠈⠠⠀⠈⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠠⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⠂⠀⠀⠀⠀⠀⠀⡀⠀⎥
⎢⠀⠀⢂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠌⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠛⢄⠀⠄⠀⠀⠀⠀⠀⡄⎥
⎢⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠁⠀⠀⠄⠀⠀⠀⠀⠄⠑⢄⠄⠠⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⠀⠄⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠂⡀⠀⠀⠀⠀⠀⡁⠑⢄⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠂⡀⠀⠀⠀⠠⠀⠀⠀⡀⠁⠀⠀⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢄⠂⠀⎥
⎣⠀⢀⠀⠀⠀⠀⠀⡄⠀⠐⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠤⠀⠀⠀⠀⠈⠀⠑⢄⎦

but Hermitian(S) falls back to the generic AbstractMatrix display, which is much less useful:

julia> show(IOContext(stdout, :limit=>true, :displaysize=>(20,80)), "text/plain", Hermitian(S))
1000×1000 Hermitian{Float64, SparseMatrixCSC{Float64, Int64}}:
 1.0                                                          
     1.0                                                       
         1.0                                                   
             1.0                                               
                 1.0                                           
                     1.0                                      
                         1.0                                   
                             1.0                               
                                                                      
                                    1.0                        
                                        1.0                    
                                           1.0                
                                                1.0            
                                                    1.0        
                                                        1.0    
                                                            1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions