Just checked the sparse matrix section of the Julia manual. My question is whether what you explained only applies to actually declared sparse matrix? In my case, the A is not declared as a sparse matrix even though it has a lot of zeros in it - issparse(A) returns false.

On 2014年10月17日 15:03, Mauro wrote:
The operation A[i] for a sparse matrix is quite a bit more expensive
than for a dense array (where it is trivial).  It first needs to convert [i]
it to a [k,m] index and then look it up in the sparse matrix.  See:

https://github.com/JuliaLang/julia/blob/master/base/sparse/sparsematrix.jl#L841

However, if you just need to iterate over the non-zero values, it can
be done much more efficiently:

for nz in A.nzval
      if abs(nz)>1.
         val += (nz - s) * (x + y)
      end
end

We should probably add an iterator to sparsematrix.jl which does that.



Reply via email to