Re: [eigen] [Sparse] element acces in a cwise unary op on an Eigen::Sparse

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]



Hi Gael,
Thanks for your answer.

On Thu, 25 Nov 2010 13:13:59 +0100, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:
Random access to a sparse matrix is inherently very inefficient, and
so I decided not to support it. Instead use iterators and/or, some

I am fully aware that is dumb to iterate over the whole virtual matrix
however, the decision was not mine to make.
Give that I had to enable some operations that result in a dense matrix
(e.g. "or equal" logical ops between sparse matrices where 0. <= 0.
so my result is full) because i am reimplementing an already existing API knew that the result would have to be large (i.e. dense) and slow to compute.

I just wished I had not to consume even more temp memory by making a dense copy of the arg
to iterate over it.


fast access function like .innerVector(i).lastCoeff() ...

thank for the suggestion, but I' did not have much better luck with lastCoeff():

#include <iostream>
#include <Eigen/Core>
#include <Eigen/Sparse>
#include <complex>

template<typename Derived>
void useLastCoeff( Eigen::EigenBase<Derived> const a){
    std::cout<<a.derived().innerVector(0).lastCoeff()<<std::endl;
}

int main(int argc, char* argv[])
{
    Eigen::SparseMatrix<double> a(2,5);
    a.insert(1,0)=555.;
    a.insert(2,0)=777.;
    a.insert(0,1)=666.;

    a.finalize();

    useLastCoeff(a.cast<std::complex<double> >());
    return 0;
}
fails with :
tst-coeff.cxx: In function ‘void useLastCoeff(Eigen::EigenBase<Derived>) [with Derived = Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<double, std::complex<double> >, Eigen::SparseMatrix<double> >]’:
tst-coeff.cxx:20:49:   instantiated from here
tst-coeff.cxx:8:5: error: ‘const class Eigen::SparseInnerVectorSet<Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<double, std::complex<double> >, Eigen::SparseMatrix<double> >, 1>’ has no member named ‘lastCoeff’


SparseMatrix and DynamicSparseMatrix objects provide a coeff()
function for debug purpose only. It is not supposed to be used in
production code.

I try to use unaryExpr()and binaryExpr() whenever possible, but when I have to consider
every virtual element of the matrix (even the "0."), I'm stuck :(

Btw, à propos Eigen::Sparse<bool> :

- it would be nice to be able to set the default value to «true».
- template<> struct scalar_fuzzy_impl<bool> seemed to be missing an isMuchSmallerThan() for some sparse operation but I fail to be able to reproduce the error (I rewrote the code that was triggering it :( )

Thanks

Best Regards,

Bernard



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/