From: Gunter Winkler (guwi17_at_[hidden])
Date: 2005-03-11 17:21:12
Am Freitag, 11. März 2005 18:15 schrieb Dima Sorkin:
> I have a following code:
> 1: sparse_matrix<double> m1(N,N);
> 2: // fill m1 ...
> 3: compressed_matrix<double> m2(m1);
An Alternative would be to use a coordinate_matrix to fill the data. The
conversion from coordinate matrix to a compressed_matrix is very fast.
The third way is to precompute the structure of the compressed_matrix
and fill it using push_back(). See
for more details.
> 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)).
I am going to check this...
> 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 ?
It should be possible to implement a non_zeros() function for
sparse_matrix. You have to count the number of entries in the storage