Skip to content

Explicit type casting

What does this implement/fix?

The function signature of pmadd assumes identical types of all three arguments, i.e. Eigen/src/Core/GenericPacketMath.h lines 958ff

/** \internal \returns a * b + c (coeff-wise) */
template<typename Packet> EIGEN_DEVICE_FUNC inline Packet
pmadd(const Packet&  a,
         const Packet&  b,
         const Packet&  c)
{ return padd(pmul(a, b),c); }

In Eigen/src/LU/Determinant.h the function pmadd is used with mathematical expressions, i.e.

return internal::pmadd((Scalar)(-m(0,3)),d3_0, (Scalar)(m(1,3)*d3_1)) +
       internal::pmadd((Scalar)(-m(2,3)),d3_2, (Scalar)(m(3,3)*d3_3));

and

return internal::pmadd(m(i0,2), d0, internal::pmadd((Scalar)(-m(i1,2)), d1, (Scalar)(m(i2,2)*d2)));

which must be explicitly casted to Scalar. Otherwise, custom scalar types whose overload of operator* and operator- return expression templates rather than the original types will lead to compiler errors.

Additional information

This bug has ben observed while differentiating Eigen using the AD library CoDiPack.

Merge request reports

Loading