Re: [eigen] Minimal ei_traits?

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


There is, and you can find that in Macros.h, in
EIGEN_DENSE_PUBLIC_INTERFACE, which is basically where ei_traits are
used:

#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
  typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; /*!<
\brief Numeric type, e.g. float, double, int or std::complex<float>.
*/ \
  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; /*!<
\brief The underlying numeric type for composed scalar types. \details
In cases where Scalar is e.g. std::complex<T>, T were corresponding to
RealScalar. */ \
  typedef typename Base::PacketScalar PacketScalar; \
  typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief
The return type for coefficient access. \details Depending on whether
the object allows direct coefficient access (e.g. for a MatrixXd),
this type is either 'const Scalar&' or simply 'Scalar' for objects
that do not allow direct coefficient access. */ \
  typedef typename Eigen::ei_nested<Derived>::type Nested; \
  typedef typename Eigen::ei_traits<Derived>::StorageKind StorageKind; \
  typedef typename Eigen::ei_traits<Derived>::Index Index; \
  enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
        ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
        MaxRowsAtCompileTime =
Eigen::ei_traits<Derived>::MaxRowsAtCompileTime, \
        MaxColsAtCompileTime =
Eigen::ei_traits<Derived>::MaxColsAtCompileTime, \
        Flags = Eigen::ei_traits<Derived>::Flags, \
        CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \
        SizeAtCompileTime = Base::SizeAtCompileTime, \
        MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \
        IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
  using Base::derived; \
  using Base::const_cast_derived;


Notice that NOT all of the above lines refer to stuff in ei_traits.
Those that do, tell you what ei_traits must provide.

But let me take this occasion to insist that the ONLY place where you
have to use ei_traits, is if you are hacking Eigen and adding or
modifying some base class underneath some expression class. If you are
just trying to get compile-time information on a given Eigen
expression type (or even if you are just coding some new expression
class for Eigen), you can access these typedefs and enum values right
off this type:

do:

     enum { myvalue = Derived::RowsAtCompileTime };
     typedef typename Derived::Scalar mytype;

and NOT (unless you are hacking Eigen's own base classes):

     enum { myvalue = ei_traits<Derived>::RowsAtCompileTime };
     typedef typename ei_traits<Derived>::Scalar mytype;

The only case where you have to do the latter, is when Derived is not
fully defined. You might ask how could this possibly happen? This
happens when you are inside of a template Base<Derived> class and
Derived inherits Base<Derived>. See the link I just mentioned about
the CRTP.

Now I know that there are many places in Eigen where we use ei_traits,
and that's unnecessary, so that's bad. A patch fixing that is always
welcome. Only use ei_traits if it's needed in order to compile.

Benoit



2010/6/30 Manoj Rajagopalan <rmanoj@xxxxxxxxx>:
> hi eigen developers,
>
>   It is a little difficult to trace the various ei_traits because of their
> distribution and levels of inheritance? Is there a minimum set of typedefs,
> enums etc. that any ei_traits must declare/define/statically-compute?
>
> thanks,
> Manoj
>
>
>



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