|
Ublas : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-01-13 09:53:13
Am Samstag, 12. Januar 2008 11:48 schrieb Markus Weimer:
> Hi,
> does clear() set all values to 0 for dense and sparse matrices? And
> if so: Is that efficient for a freshly generated sparse matrix?
Yes and yes. sparse clear() simply drops all stored nonzeros. This is a
O(1) operation. dense clear() fills the matrix with zeros. This is a
O(n*m) operation.
> And a meta question: Where would I have found that information? I
> could noy find it on the uBlas website :-(
The matrix doc states:
void clear () Clears the matrix.
Well, that lets a lot of space for "interpretations" ;-)
However, one should have a look at the matrix concept which is more
expressive:
* Clear
* m.clear ()
* Equivalent to
for (i = 0; i < m.size1 (); ++ i)
for (j = 0; j < m.size2 (); ++ j)
m.erase_element (i, j);
Although, this exactly expresses the idea of clear() there is no
efficiency guarantee here and you have to rely that the programmers
used an efficient implementation. Thus a look in the source is always
the quickest solution.
mfg
Gunter