Re: [eigen] TriangularViewType& operator/=(const typename internal::traits<MatrixType>::Scalar& other)

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


Hi,

the types TpFloat and NumTraits<TpFloat>::Real should be fully compatible, just like std::complex<T> and T. Currently, we cannot even do:

TpFloat c;
NumTraits<TpFloat>::Real r;
c = r;

So the first step is to make them compatible and/or define NumTraits<TpFloat>::Real to be TpFloatBase ???

This should be enough to compile with the devel branch.


gael.

On Mon, Sep 5, 2016 at 4:00 PM, Peter <list@xxxxxxxxxxxxxxxxx> wrote:
Dear All,

I'm trying to extend my simple test code using eigen for a user defined type
including the diagonalization. Sadly, I got lost in the template machinery.

In short


template<typename T>
class MyType
{
  public:

    typedef T value_type;
       
    // ...
  protected:
    T za, zb;
};

typedef   double TpFloatBase;
typedef   std::complex<TpFloatBase> TpComplex;

typedef   MyType < TpFloatBase > TpRFloat;
typedef   MyType < TpComplex   > TpFloat;

Eigen::SelfAdjointEigenSolver<TpMatrix> eigensolverH;
eigensolverH.compute(H);


triggers

/home/peter/Eigen/eigen/Eigen/src/Core/TriangularMatrix.h:386:26: note: Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::TriangularViewType& Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::operator/=(const typename Eigen::internal::traits<T>::Scalar&) [with _MatrixType = Eigen::Matrix<MyType<std::complex<double> >, -1, -1, 0, -1, -1>; unsigned int _Mode = 1u; Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::TriangularViewType = Eigen::TriangularView<Eigen::Matrix<MyType<std::complex<double> >, -1, -1, 0, -1, -1>, 1u>; typename Eigen::internal::traits<T>::Scalar = MyType<std::complex<double> >]
     TriangularViewType&  operator/=(const typename internal::traits<MatrixType>::Scalar& other) { return *this = derived().nestedExpression() / other; }
                          ^
/home/peter/Eigen/eigen/Eigen/src/Core/TriangularMatrix.h:386:26: note:   no known conversion for argument 1 from ‘Eigen::SelfAdjointEigenSolver<Eigen::Matrix<MyType<std::complex<double> >, -1, -1, 1> >::RealScalar {aka MyType<double>}’ to ‘const Scalar& {aka const MyType<std::complex<double> >&}’


I thought it would be sufficient to define

template<class T>
MyType< std::complex<T> > operator/( const MyType< std::complex<T> >&  z , const MyType<T>& b)
{
        return z / MyType< std::complex<T > >( b.z1() , b.z2()  ); ///< Could be optimized
}

And indeed

        TpRFloat r(1);
        TpFloat  z(2);
        TpFloat  q = z / r; // o.k.

compiles fine.

Could you please give be hint, which operator I'm missing?

I've attached the complete source file that triggers the error, including the error messages I get using
"g++  -std=c++11 -g Test.C   -I $HOME/Eigen/eigen  -o Test " .

Note, that  some the operator definition doesn't make sense mathematically, I just put something to get it compiled.


Thanks in advance,
best regards,
Peter



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