Re: [eigen] Custom scalar types and matrix products

[ Thread Index | Date Index | More Archives ]


I don't know why there is an ambiguous call here since I cannot reproduce with other custom scalar types, but you can workaround with an explicit evaluation:

A2 * (B2 * A2).eval();

No overhead since matrix products are evaluated into temporaries anyway.


On Tue, Dec 24, 2013 at 2:36 PM, Brad Bell <bradbell@xxxxxxxxxx> wrote:
I am having trouble using the templated scalar type CppAD::AD<Base> with eigen's matrix multiply.

To be specific, the code eigen_mul.cpp (included below)
is generating the error message eigen_mul.stderr (included below).
I have reformatted the error message output so that it is easier to read.

A script that:
generates the file build/eigen_mul.cpp,
runs the g++ compiler,
and generates the error message,
can be found at

You can run this script using the following steps:
    1. svn checkout cppad_trunk
    2. cd cppad_trunk
    3. mkdir build
    4. cd build
    5. cmake ..
    6. cd ../bug
Then modify the script line
to be the location of the eigen include directory on your machine.
Then execute the command

#include <Eigen/Core>
#include <cppad/cppad.hpp>

int main() {
     using Eigen::Matrix;
     using Eigen::Dynamic;
     typedef CppAD::AD<double> AScalar;

     Matrix<AScalar, Dynamic, Dynamic> A2(1,1);
     Matrix<AScalar, Dynamic, Dynamic> B2(1,1);

     A2(0,0) = 1.0;
     B2(0,0) = 2.0;

     A2 * B2 * A2;

     return 0;


warning: ISO C++ says that these are ambiguous,
even though the worst conversion for the first is better than the
worst conversion for the second: [enabled by default]
  A2 * B2 * A2;
note: candidate 1: const typename

Eigen::ProductReturnType<Derived, OtherDerived>::Type
     const Eigen::MatrixBase<OtherDerived>&) const

OtherDerived = Eigen::Matrix<CppAD::AD<double>, -1, -1>;
Derived      = Eigen::GeneralProduct<
     Eigen::Matrix<CppAD::AD<double>, -1, -1>,
     Eigen::Matrix<CppAD::AD<double>, -1, -1>, 5>;

typename Eigen::ProductReturnType<Derived, OtherDerived>::Type =
          Eigen::Matrix<CppAD::AD<double>, -1, -1>,
          Eigen::Matrix<CppAD::AD<double>, -1, -1>, 5>,
     Eigen::Matrix<CppAD::AD<double>, -1, -1>, 5>

MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const

note: candidate 2: const

     const Eigen::ProductBase<Derived, _Lhs, _Rhs>&,
     const typename Derived::Scalar&)

Derived = Eigen::GeneralProduct<
     Eigen::Matrix<CppAD::AD<double>, -1, -1>,
     Eigen::Matrix<CppAD::AD<double>, -1, -1>, 5>;
Lhs = Eigen::Matrix<CppAD::AD<double>, -1, -1>;
Rhs = Eigen::Matrix<CppAD::AD<double>, -1, -1>;

typename Derived::Scalar = CppAD::AD<double>

     const ProductBase<Derived,Lhs,Rhs>& prod,
     const typename Derived::Scalar& x

Mail converted by MHonArc 2.6.19+