[eigen] Custom scalar types and matrix products |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
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
https://projects.coin-or.org/CppAD/browser/trunk/bug/eigen_mul.sh
You can run this script using the following steps:
1. svn checkout https://projects.coin-or.org/svn/CppAD/trunk
cppad_trunk
2. cd cppad_trunk
3. mkdir build
4. cd build
5. cmake ..
6. cd ../bug
Then modify the script eigen_mul.sh line
-I$HOME/prefix/eigen/include
to be the location of the eigen include directory on your machine.
Then execute the command
./eigen_mul.sh
eigen_mul.cpp:
=============
#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;
}
eigen_mul.stderr
================
eigen_mul.cpp:15:12:
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;
^
--------------------------------------------------------------------------
/home/bradbell/prefix/eigen/include/Eigen/src/Core/GeneralProduct.h:571:1:
note: candidate 1: const typename
Eigen::ProductReturnType<Derived, OtherDerived>::Type
Eigen::MatrixBase<Derived>::operator*(
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::GeneralProduct<
Eigen::GeneralProduct<
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
--------------------------------------------------------------------------
/home/bradbell/prefix/eigen/include/Eigen/src/Core/ProductBase.h:198:1:
note: candidate 2: const
Eigen::ScaledProduct<Derived>
Eigen::operator*(
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>
operator*(
const ProductBase<Derived,Lhs,Rhs>& prod,
const typename Derived::Scalar& x
)