Boost logo

Ublas :

Subject: Re: [ublas] Question regarding sparse vector's nnz() method
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2010-03-14 08:20:52


Rui Maciel schrieb:
> I was looking for a way to check how many entries are mapped in any given
> sparse vector and, as the documentation doesn't mention anything related to
> this, I've combed through the vector_sparse.hpp source file.
>
> While browsing the code I've stumbled on the nnz() method, which is defined in
> all sparse vector classes. After testing it it appears that it does exactly
> what I was searching for. Nonetheless, as it's an undocumented method, I was
> left wondering if it's results are meaningful or even if it works at all.
>
> So, can anyone help? Does the nnz() method return the number of mapped
> elements? If not, is there any way to access that information?
>
>
The nnz() method returns the number of strutural non-zeros. This means
the number of actually stored matrix elements (no matter whether they
are zero or not.) The rational is that returning the number of stored
matrix elements is a O(1) operation for most matrix types. If you really
want the number of elements which are not zero, then you have to iterate
over the whole matrix.

If for some matrix the implementation is different to that explanation
then we should consider this as a bug.

mfg
Gunter

__________ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 4942 (20100313) __________

E-Mail wurde geprüft mit ESET NOD32 Antivirus.

http://www.eset.com