Boost logo

Ublas :

From: Dima Sorkin (dsorkin_at_[hidden])
Date: 2005-03-11 12:15:02

 I have a following code:
1: sparse_matrix<double> m1(N,N);
2: // fill m1 ...
3: compressed_matrix<double> m2(m1);

The time that it takes to line 3 to execute seems to be O(N^2).
In my program it is critical to do it bounded in O(N*log(N)).
As I understand , I should change line 3 into:
compressed_matrix<double> m2(m1,number of non-zeros in m1);
in order to allow to preallocate memory for m2.

1) Will it change the performance into O(N*log(N)) ?
2) I can't find any kind of non_zeros() method in class sparse_matrix.
What is the good way to find the number of non zeros ?

Thank you.