Re: [eigen] Using custom scalar types

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


On Sat, 16 Jun 2012, Brad Bell wrote:

Looking at the example in

http://eigen.tuxfamily.org/dox/TopicCustomizingEigen.html#CustomScalarType
one sees
    ... snip ...
    IsInteger = 0,
    IsSigned,
    ReadCost = 1,
I suspect that IsSigned should be 1 for this example ?

Based on unstable/Eigen/AdolcForward, I'd say that you are right.

Furthermore, one also sees
    ... snip ...
    inline adouble internal::sin(const adouble& x) { return sin(x); }
inline adouble internal::cos(const adouble& x) { return cos(x); }
inline adouble internal::pow(const adouble& x, adouble y) { return
pow(x, y); }
    ... snip ...
Is this a typo, or should the argument y be passed by value instead of
by const reference ?

I suppose this is a typo.

It looks like https://bitbucket.org/eigen/eigen/src/tip/unsupported/Eigen/AdolcForward is severely out-of-date. I don't think it even compiles. I replaced it with the version at the end of this message, which is hopefully more correct.

Thanks for your report,
Jitse


---------------------------------------

#ifndef ADOLCSUPPORT_H
#define ADOLCSUPPORT_H

#define ADOLC_TAPELESS
#include <adolc/adouble.h>
#include <Eigen/Core>

namespace Eigen {

template<> struct NumTraits<adtl::adouble>
{
  typedef adtl::adouble Real;
  typedef adtl::adouble NonInteger;
  typedef adtl::adouble Nested;

  enum {
    IsComplex = 0,
    IsInteger = 0,
    IsSigned = 1,
    RequireInitialization = 1,
    ReadCost = 1,
    AddCost = 1,
    MulCost = 1
  };
};

}

namespace Eigen {
  namespace internal {

    inline const adtl::adouble& conj(const adtl::adouble& x)  { return x; }
    inline const adtl::adouble& real(const adtl::adouble& x)  { return x; }
    inline adtl::adouble imag(const adtl::adouble&)    { return 0.; }
    inline adtl::adouble abs(const adtl::adouble&  x)  { return adtl::fabs(x); }
    inline adtl::adouble abs2(const adtl::adouble& x)  { return x*x; }

    using adtl::sqrt;
    using adtl::exp;
    using adtl::log;
    using adtl::sin;
    using adtl::cos;
    using adtl::pow;

  }
}

#endif // ADOLCSUPPORT_H




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