julia> A = sparse([rand() < 0.01 ? 1 : 0 for _ in 1:50, _ in 1:50])
50×50 SparseMatrixCSC{Int64,Int64} with 23 stored entries:
[...]
julia> sum(A, dims=1)
1×50 Array{Int64,2}:
0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 2 3 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 2 1 0 3
Sometimes you have a very sparse matrix and want to sum a slice of it. The slice may potentially have very many columns or rows that are entirely zero, in which case it makes a lot of sense to preserve sparsity in the output.
In the non-slice case, where every row and column usually contains at least one nonzero value, it makes sense to keep the result dense.
It would be great if preserving sparsity in sum and other similar reductions were allowed via a keyword argument, eg. sparse=true.
cc @simonbyrne, who suggested the keyword idea on Slack a few months ago.
Sometimes you have a very sparse matrix and want to sum a slice of it. The slice may potentially have very many columns or rows that are entirely zero, in which case it makes a lot of sense to preserve sparsity in the output.
In the non-slice case, where every row and column usually contains at least one nonzero value, it makes sense to keep the result dense.
It would be great if preserving sparsity in
sumand other similar reductions were allowed via a keyword argument, eg.sparse=true.cc @simonbyrne, who suggested the keyword idea on Slack a few months ago.