`StaticArray` types

SparseMatrixCSC currently has a documented type definition of:

SparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}

but, if you try to actually make one, you will find in practice that it only has exactly one of the types:

SparseMatrixCSC{Tv<:Union{Number, Missing},Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}
SparseMatrixCSC{Tv<:Union{UniformScaling{N} where N, Missing},Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}
SparseMatrixCSC{Tv<:Union{CartesianIndex{N} where N, Missing},Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}

that is, unless you don’t have any empty indices.

now, why is this? it’s because when we’re printing it out, we first find the textual width of zero(::Type{Tv}), and then put a which is the same length as that in the array.
look at how w i d e :

julia> A = sparse([3], [4], [CartesianIndex((1,2,3))])
3×4 SparseMatrixCSC{CartesianIndex{3}, Int64} with 1 stored entry:
            ⋅                        ⋅                        ⋅                        ⋅
            ⋅                        ⋅                        ⋅                        ⋅
            ⋅                        ⋅                        ⋅             CartesianIndex(1, 2, 3)

the reason I found this was because I was trying to dissect the awful way it interacts with Base printing functions for #62362. I even had a commit message ready for them: stop cannibalizing unexported base printing functions \n\n stahp it. doe normaal.. (I’m warning you, LinearAlgebra, you’re next ^^)




now, there are two paths forward, which is why I am asking over here.

  1. keep the type of SparseMatrixCSC the same, and fix the printing
  2. restrict the type of SparseMatrixCSC to SparseMatrixCSC{Tv<:Union{Number, Missing},Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}

the second option here probably has compilation benefits, and right now you can make that change without it being breaking. idk much about all that, so I’m throwing this question out to the community. I’d say it’s extremely unlikely that someone is actually using UniformScaling or CartesianIndex SparseMatrixCSC’s because you have to be extra careful that the types actually make it all the way through:

sparse([2, 4], [2, 1], [6I, I]) # fails, has to be: sparse([2, 4], [2, 1], UniformScaling{Int64}[6I, I])
sparse([3,4], [4,3], [CartesianIndex((1,2,3)), CartesianIndex((1,2,3,5))]) # fails: they have to be the same dimensionality