This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Overloading for matrixes and expressions of std::complex

Tags: None
(comma "," separated)
karstenahnert
Registered Member
Posts
3
Karma
0
Hi,

I have a user defined function abs( MatrixBase< D > const& m ) which calculates the column-wise absolute value of the matrix:

Code: Select all
template< typename D >
inline const
typename Eigen::CwiseUnaryOp<
    typename Eigen::internal::scalar_abs_op<
        typename Eigen::internal::traits< D >::Scalar > ,
        const D >
abs( const Eigen::MatrixBase< D > &m ) {
    return m.cwiseAbs();
}


Is there a way to overload this function for matrixes and expressions consisting of std::complex<>? In case of a matrix of complex this method should return an expression with complex values not doubles.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Not tested, but that should do the job:
Code: Select all
inline const
typename Eigen::CwiseUnaryOp<
   Eigen::internal::scalar_abs_op<typename D::Scalar> ,
   const D >::CastXpr<typename D::Scalar >::Type
abs( const Eigen::MatrixBase<D> &m ) {
    return m.cwiseAbs().template cast<typename D::Scalar>();
}

If D::Scalar is real, then the cast operation is a no-op.
karstenahnert
Registered Member
Posts
3
Karma
0
ggael wrote:Not tested, but that should do the job:


Hmm, no this is not working. I don't even see CastXpr in eigen. Which Eigen are you referring to. My own is 3.2.2. Maybe this one is to old?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
right, it is only defined in the devel branch. in the meantime the returned type of cast is:

template<typename NewType>
typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, const Derived> >::type


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]