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

[ Thread Index | Date Index | More Archives ]

Dear Gael,

Am 05.09.2016 um 22:45 schrieb Gael Guennebaud:

On Mon, Sep 5, 2016 at 10:42 PM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx <mailto:gael.guennebaud@xxxxxxxxx>> wrote:

    It seems that you also need to specialize:

    template<typename T> struct ScalarBinaryOpTraits<MyType< std::complex<T> >,MyType<T> > { typedef MyType< std::complex<T> > ReturnType; };
    template<typename T> struct ScalarBinaryOpTraits<MyType<T>,MyType< std::complex<T> > > { typedef MyType< std::complex<T> > ReturnType; };

indeed, I was missing the above declarations and the constructor from the real type to the complex type.

perhaps this could be handled automatically on our side, using NumTraits information. I'll give it a try.

Using NumTraits I rewrote it in

template <> struct ScalarBinaryOpTraits< TpFloat, typename NumTraits<TpFloat>::Real > { typedef TpFloat ReturnType; };
template <> struct ScalarBinaryOpTraits< typename NumTraits<TpFloat>::Real, TpFloat > { typedef TpFloat ReturnType; };

which can be rewritten in

template <class T> struct ScalarBinaryOpTraits< T, typename NumTraits<T>::Real > { typedef T ReturnType; };
template <class T> struct ScalarBinaryOpTraits< typename NumTraits<T>::Real, T > { typedef T ReturnType; };

all three versions compile fine using g++ or clang.

The real version even gives the correct result.
I still have to investigate the complex case .

Thanks for your help,
best regards,

Mail converted by MHonArc 2.6.19+