Boost logo

Ublas :

From: Russ (c.r.coggrave_at_[hidden])
Date: 2006-04-20 06:28:13


Please see my comments below...

>
> 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.
>

I agree.

> > 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:
>

I will look at the possibility of preparing a patch against the CVS head.
However, I am not sure what you mean by "not included in the official interface"
- do you simply mean that it is not intended for public use and therefore not
documented, whereas the intention would be to document the free function.
 
> template <class CONTAINER>
> typename CONTAINER::size_type
> nnz(const CONTAINER& m)
> {
> return m.nnz();
> }
>

I assume that your proposed free function nnz() should support only the sparse
storage containers since it returns the number of structural non-zero elements.

> 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.
>

I hadn't appreciated that the nnz() member might return a value that differs
from the number of real elements != 0. Since I am looking for the latter, it
would seem that I have no option but to iterate over all elements in the
container and compare the values with 0, regardless of the storage scheme. It
would seem that a free function that returns the number of elements != 0 would
also be helpful.

I would like to propose that we change the name of the nnz() members and the
corresponding free function (described by Gunter above) to nnz_structural() to
clarify its purpose, and create a new free function called nnz() that iterates
over the contains and returns the number of elements != 0.

Free function nnz_structural() is only relevant to sparse storage containers.
Free function nnz() can be implemented for all containers.

I welcome the communities thoughts on this proposal.

Russ