Boost logo

Ublas :

Subject: [ublas] does matrix_unary1 work for arbitrary functions?
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2012-01-29 19:45:40


Hi list,

Recently I implemented an exp for matrices on the basis of the
matrix_unary1. This works just fine for dense vectors. But for sparse
there are problems:

The indexed access method suggests, that everything should work:

const_reference operator () (size_type i, size_type j) const {
   return functor_type::apply (e_ (i, j));
}

When functor_type being something which computes exp(x) the above operator
results in something like:
Exp<mat>(i,j)=exp(mat(i,j));

which is what i wanted.

However, indexed access works differently:

const_reference operator * () const {
    return functor_type::apply (*it_);
}
At first sight it looks right. only that in the case of
exp<compressed_vector> it_ is sparse and so all zero elements are skipped.

This leads to different results depending on which type of access is used.
e.g. printing out the vectors using op<< works flawlessly, but assigning
the result to a vector fails.

Is this working as intended as in: "functions are required that f(0)=0"?
Or am I missing something like an important flag which can be used in this
case?

Thanks for your help and have a nice start in the week!
Oswin