Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-04-20 03:24:02


On Wednesday 19 April 2006 21:39, Russ wrote:
> Is there another trait that can be used to check for support of nnz(), or
> alternatively, would it be possible to add nnz() to all vector and matrix
> classes that use the sparse_tag container_type trait?

IMHO all classes using the sparse_tag should have the nnz() member function.

> An example would be ublas::unit_vector<> class, which has the sparse_tag
> container_type trait, but does not support nnz(). However, implementing
> nnz() would of course be very simple.

I think Micheal will gladly accept a patch that provides all these missing
nnz(). But because nnz() is not included in the official interface you should
use a free function nnz() with has the correct overloads for all types.
Something like this should work:

template <class CONTAINER>
typename CONTAINER::size_type
nnz(const CONTAINER& m)
{
        return m.nnz();
}

There was a discussion about nnz() a few month ago and we finally decided to
prefer the free function, because there is a difference between real nonzeros
(value that are not 0) and structural nonzeros (values that are stored, but
may be 0 or not). nnz() usually returns the number of structural nonzeros.

mfg
Gunter