I have the following sparse matrix containing O(N) elements
boost::numeric::ublas::compressed_matrix<int> adjacency (N, N);
I could write a double iteration loop to iterate over all the records in O(N^2) time, as shown below, but it will be too slow.
for(int i=0; i<N; ++i) for(int j=0; j<N; ++j) std::cout << adjacency(i,j) std::endl;
How can I iterate over only non-zero entries in O(N) time? For each nonzero element, I would like to access its value and the indices i,j .
c ++ boost sparse-matrix ublas
jailil
source share