[eigen] AutoDiffScalar

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi all,
I've been following the work on the cminpack branch with interest and
right now I'm looking at AutoDiffScalar.
I've written some tests and seen that it has the potential to be very
efficient, mainly thanks to the lazy evaluation I guess, but I have
some questions.
The fixed size implementation already seems to be mostly done, but
there are some problems with the dynamic version.
Look for example at the implementation of addition:

template<typename OtherDerType>
inline const AutoDiffScalar<CwiseBinaryOp<ei_scalar_sum_op<Scalar>,DerType,OtherDerType>
>
operator+(const AutoDiffScalar<OtherDerType>& other) const
{
    return AutoDiffScalar<CwiseBinaryOp<ei_scalar_sum_op<Scalar>,DerType,OtherDerType>
>(
    m_value + other.value(),
    m_derivatives + other.derivatives());
}

This implementation crashes when "other" was initialized through c'tor
AutoDiffScalar(const Scalar& value) and other.derivatives() is of size
zero.
The fix is not obvious to me since we need to return a binary
expression and just m_derivatives won't do.
I could check the size of other.m_derivatives and fill it up with
zeros, when appropriate, but I would have to do that check at compile
time since "OtherDerType" could also be a binary expression or
something similar. I haven't found a way at compilation to check if an
type is a "normal matrix" or some kind of an expression.

I hope somebody has an idea of how to resolve this, because a fast
forward differentiation implementation with expression templates
supporting dynamic size vectors would be a really cool feature. I've
compared this implementation to Sacado, the only other good template
implementation I could find out there, and this one compares very
favorably(fast).

Any feedback will be appreciated
Björn



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/