In CSC sparse matrix format, each column will need a slot in colptr
irrespective of whether it contains non-zeros or not.

julia> spzeros(Float32, 1,4).colptr
5-element Array{Int64,1}:
 1
 1
 1
 1
 1

julia> spzeros(Float32, 4,1).colptr
2-element Array{Int64,1}:
 1
 1

I think this is what makes the difference in your example.  I think
there is some plans to make also compressed row storage.  Using this
would reverse above situation.

On Sun, 2014-11-30 at 01:29, Zouhair Mahboubi <[email protected]> 
wrote:
> I have the following code:
>
> NS = 23^3
> TSA = Array(Dict, NS)
>
> for from_i in 1:NS
>            TSA[from_i] = Dict()
>            for a in 1:6
>                TSA[from_i][a] = spzeros(Float32, 1, NS)
>            end
> end
>
> This gobbles up about 4G of memory. If instead, I use TSA[from_i][a] =
> spzeros(Float32, NS, 1) it barely makes a dent in my memory usage.
>
> FYI, I’m using dictionaries here because in my application a’s are actually
> tuples of symbols, not integers, and it makes things easier.
>
> The only reason I wrote it as a rowvector is because I need to dot it with
> a non-sparse vector b, but unfortunately dot does not support
> SparseMatrixCSC so I’m using a' * b instead. I can get away with using the
> column vector for now by doing b' * a.
>
> I was surprised at the difference in memory footprint, and I’m curious if
> someone would care to explain why that is?
>
> Thanks,
> -z
> ​

Reply via email to