I think the nzrange function (new to 0.4 function) is best to do
that:

Base.nzrange(A, col)

   Return the range of indices to the structural nonzero values of a
   sparse matrix column. In conjunction with "nonzeros(A)" and
   "rowvals(A)", this allows for convenient iterating over a sparse
   matrix

      A = sparse(I,J,V)
      rows = rowvals(A)
      vals = nonzeros(A)
      m, n = size(A)
      for i = 1:n
         for j in nzrange(A, i)
            row = rows[j]
            val = vals[j]
            # perform sparse wizardry...
         end
      end

If you're on 0.3 just add these two definitions from 0.4:

    rowvals(S::SparseMatrixCSC) = S.rowval
    nzrange(S::SparseMatrixCSC, col::Integer) = 
S.colptr[col]:(S.colptr[col+1]-1)

(this is just what Odd suggested)

And yes, transposing is likely the fastest for doing this over rows as
indexing into columns is very expensive.

Reply via email to