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

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


Random access to a sparse matrix is inherently very inefficient, and
so I decided not to support it. Instead use iterators and/or, some
fast access function like .innerVector(i).lastCoeff() ...

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

gael.

On Thu, Nov 25, 2010 at 10:11 AM,  <bernard.hugueney@xxxxxxxxxx> wrote:
>
> Hi,
> I'd like to have access on elements of a cwise unary op, but the compiler
> cannot find a coeff member function.
> the folowing code :
> #include <iostream>
> #include <Eigen/Core>
> #include <Eigen/Sparse>
> #include <complex>
>
> template<typename Derived>
> void useCoeff( Eigen::EigenBase<Derived> const a){
>    std::cout<<a.coeff(0,0)<<std::endl;
> }
>
> int main(int argc, char* argv[])
> {
>    Eigen::SparseMatrix<double> a(2,2);
>    std::cout<<a.coeff(0,0)<<std::endl;
>    useCoeff(a.cast<std::complex<double> >());
>    return 0;
> }
>
> gives the error :
> tst-coeff.cxx: In function ‘void useCoeff(Eigen::EigenBase<Derived>) [with
> Derived = Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<double,
> std::complex<double> >, Eigen::SparseMatrix<double> >]’:
> tst-coeff.cxx:15:45:   instantiated from here
> tst-coeff.cxx:8:5: error: ‘const class
> Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<double,
> std::complex<double> >, Eigen::SparseMatrix<double> >’ has no member named
> ‘coeff’
>
> How am I to access elements of my cast expression ?
>
> Any help greatly appreciated :)
>
> Best regards,
>
> Bernard
>
>
>



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