Question about Julia sparse matrices design decisions

I understand that Julia made the decision to support only a single sparse matrix format (in the standard library, anyway) - CSC (compressed sparse column).

I tried searching and couldn’t find any discussion of why this was chosen as opposed to supporting both CSC and CSR.

Certain operations are much more efficient using CSR, especially certain multiplications. As an example, if supporting both CSC and CSR, then transpose becomes trivial and the common computation transpose(A) * A (for least square approximation and many other usages) becomes much more efficient.

Is there some thread somewhere that discusses this? Is it at all likely that Julia will “natively” support additional compressed formats? I assume it is always possible to support such formats as an additional package, but I couldn’t find any generic CSR package - all the packages I could find weren’t generic (e.g., CUSPARSE.jl).

I don’t know much about sparse matrix representations but note that transposes are always “trivial” in julia.

julia> A = spdiagm(0=>rand(2))
2×2 SparseMatrixCSC{Float64,Int64} with 2 stored entries:
  [1, 1]  =  0.922997
  [2, 2]  =  0.226075

julia> A'
2×2 Adjoint{Float64,SparseMatrixCSC{Float64,Int64}}:
 0.922997  0.0
 0.0       0.226075

Note that the type of A' is an Adjoint, which is a wrapper over the original array that takes care of indexing, etc… So in that sense, CSR wouldn’t be any different.
That said, I can’t say whether other aspects like memory management would be improved by having both types :man_shrugging:

1 Like

Note that “sparse” includes banded as well. And there is a format for storing banded matrices.


Ah, I wasn’t aware of the Adjoint trick. This does make a CSR format unnecessary, it is just the Adjoint of a CSC matrix as you point out. Many thanks!

1 Like