0

I'v implemented the modulus of a matrix as follows, but it fails to compile :

const double dPI = std::acos( double(-1.) );
using baseSpaceVd = Matrix<double, 4, 1>;
baseSpaceVd  M(0,1,2,3);

M = M.unaryExpr( []( const baseSpaceVd::Scalar x ) { return x%(2*dPI); } );

Compilation error message is :

../src/COpdCtrl.cpp: In lambda function:
../src/COpdCtrl.cpp:187:85: error: invalid operands of types ‘const Scalar {aka const double}’ and ‘double’ to binary ‘operator%’
   curGDerr = curGDerr.unaryExpr( []( const baseSpaceVd::Scalar x ) { return x%(2*dPI); } );

This fix works but I'am afraid it degrades the performance :

M = M.unaryExpr( []( const baseSpaceVd::Scalar x ) { return fmod( x, (2*dPI); } );
dtell
  • 2,488
  • 1
  • 14
  • 29
sylwa06
  • 77
  • 10
  • 1
    This has nothing to do with Eigen. `x % y` just does not work for `double` in C++. If you really want this fast, you need to provide a functor which also works for SIMD-packets (or make a feature request to have that integrated into Eigen). – chtz Nov 21 '19 at 17:24
  • Dear chtz, many thanks for your answer. Where to send my feature request ? Cheers ! – sylwa06 Nov 22 '19 at 08:21
  • 1
    Just found this was already requested: https://eigen.tuxfamily.org/bz/show_bug.cgi?id=467 – chtz Nov 22 '19 at 14:14
  • Thanks for those very useful links – sylwa06 Nov 22 '19 at 20:42

0 Answers0