# Question about Julia sparse matrices design decisions

**URL:** <https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488>\
**Category:** Internals & Design\
**Tags:** matrices\
**Created:** [August 25, 2020, 6:40am UTC](https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488 "2020-08-25T06:40:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![orenbenkiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orenbenkiki/32/5578_2.png) [@orenbenkiki](https://discourse.julialang.org/u/orenbenkiki)\
**Post date:** [August 25, 2020, 6:40am UTC](https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488/1 "2020-08-25T06:40:35Z")

</div>

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](https://github.com/JuliaAttic/CUSPARSE.jl)**).

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [August 25, 2020, 11:10am UTC](https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488/2 "2020-08-25T11:10:02Z")

</div>

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

```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 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 25, 2020, 2:04pm UTC](https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488/3 "2020-08-25T14:04:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![orenbenkiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orenbenkiki/32/5578_2.png) [@orenbenkiki](https://discourse.julialang.org/u/orenbenkiki)\
**Post date:** [August 25, 2020, 3:02pm UTC](https://discourse.julialang.org/t/question-about-julia-sparse-matrices-design-decisions/45488/4 "2020-08-25T15:02:42Z")

</div>

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!
