Re: [eigen] Using Matrix<AutoDiff> in conjunction with Matrix<double>?

[ Thread Index | Date Index | More Archives ]

Yes, adding such flexibility is desirable, and this issue has been identified a long time ago:

feel free to extend AutoDiffScalar and to propose a patch.


On Thu, Mar 31, 2016 at 5:21 PM, <Daniel.Vollmer@xxxxxx> wrote:

I'm working with the (unsupported) AutoDiff module and I was wondering whether it might be worthwhile to support mixing expressions containing Matrix<AutoDiff<T> > with Matrix<T>, e.g.

  typedef Eigen::Matrix<double, 3, 1> Vec;
  typedef Eigen::AutoDiffScalar<Eigen::Vector3d> AD;
  typedef Eigen::Matrix<AD, 3, 1> VecAD;

  VecAD foo(VecAD::Zero());
  Vec bar(Vec::Ones());
  foo += bar; // fail: need to use cast, `bar.cast<AD>()` works
  foo = bar * AD(0.5); // fail: error: invalid operands to binary _expression_ ('Vec' (aka 'Matrix<double, 3, 1>') and'AD' (aka 'AutoDiffScalar<Matrix<double, 3, 1> >'))
  AD v =; // fail: error: implicit instantiation of undefined template Eigen::internal::conj_helper<Eigen::AutoDiffScalar<Eigen::Matrix<double, 3, 1, 0, 3, 1> >, double, false, false>'

I can work around this by using `cast<AD>()`, but that is sub-optimal because the derivatives are then known to be zero (and could thus be implemented more efficiently).

Can I just extend the supported expressions to do this without too much trouble? How would I go about this?

As an additional note, in order to stream Matrices containing AD, I had to do the following:

namespace Eigen {
namespace internal {

// so we can print matrices of AutoDiffScalar
template<typename DerType>
struct significant_decimals_impl<AutoDiffScalar<DerType> > : significant_decimals_impl<typename DerType::Scalar> { };

} // end namespace internal
} // end namespace Eigen

Best regards

Daniel Vollmer

Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR)
German Aerospace Center
Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany

Daniel Vollmer | AS C²A²S²E

Mail converted by MHonArc 2.6.19+