Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2006-04-20 15:54:58

On Thursday, 20. April 2006 12:28, Russ wrote:
> 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.

That would be good. I just looking at the current CVS head and find nnz
implementation in all the classes in matrix_sparse.hpp and vector_sparse.hpp
so I am wondering what we are missing.

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

Looking at documentation there are two problems currently. These contrive to
exclude the 'nnz' member from "the offical interface".

The nnz member functions are not document in any of the sparse class
definitions. More fundementally uBLAS currently only has a Matrix and Vector
concepts. The are no Sparse Matrix and Sparse Vector concepts as jet that
define the additional properaties that are (or should) be implemented in the
actual models. So this part of the documentation is a bit of a construction

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

Such a free function would be great. A fair bit of work to get this all
documented up however.

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

All favour other then the renaming! I think we already once changed the name
of the member function so I would be against doing it again. I recall the new
name 'nnz' (as opposed to 'non_zeros') was chosen as it is used elsewhere for
the number of structural non-zeros.

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


Michael Stevens Systems Engineering
34128 Kassel, Germany
Phone/Fax: +49 561 5218038
Navigation Systems, Estimation  and
                 Bayesian Filtering