but what if I need to access the coordinates of the nonzero entries of a sparse matrix for some reason? Is there a faster way to do it than using my colvals function?
On Friday, April 1, 2016 at 2:03:31 AM UTC-7, Mauro wrote: > > The reason rowvals exists is to access the vector of row-indices of a > CSC-matrix, i.e. one of the internals of CSC, to allow efficient > iteration over the non-zeros. However, there is no equivalent colvals > internal, so there is little reason to do this and even less reason to > encourage it. Consider: > > julia> s = sprand(10^7, 10^7, 1e-7); > > julia> @time rowvals(s); > 0.000004 seconds (4 allocations: 160 bytes) > > julia> @time colvals(s); > 0.508060 seconds (20 allocations: 533.748 MB, 14.61% gc time) > > > On Fri, 2016-04-01 at 10:48, Anonymous <[email protected] <javascript:>> > wrote: > > There is a rowals function, and then there is a find function, and the > find > > function actually allows you to write a one line colvals function: > > > > colvals(S::SparseMatrixCSC) = round(Int, floor(find(S)/(size(S, > 1)+0.1))+1) > > > > shouldn't someone add this to base? >
