Re: [eigen] Allow Dynamic as template parameter in fixed-size Eigen methods

[ Thread Index | Date Index | More Archives ]


This is similar to bug 579.
It seems that segment, tail, and head were overseen in the fix.

Do you think, you can provide a patch handling these cases as well? (Basically, what you wrote below plus some additional doxygen docu, similar to


On 13.12.2013 15:53, Márton Danóczy wrote:
Hi all,

currently, many Eigen methods have a dynamic-size and a fixed-size version,

     VectorBlock<Derived> segment(Index start, Index size);
     VectorBlock<Derived, Size> segment<int Size>(Index start);

It would make generic programming a lot easier to add an overload

     VectorBlock<Derived, Size> segment<int Size>(Index start, Index size);
         eigen_assert(Length == Dynamic || Length == length);
         return  VectorBlock<Derived, Size>(derived(), start, size);

The first two methods could then refer to this one:

     VectorBlock<Derived> segment(Index start, Index size)
         return segment<Dynamic>(start, size);

     VectorBlock<Derived, Size> segment<int Size>(Index start)
         EIGEN_STATIC_ASSERT(Size != Dynamic)
         return segment<Size>(start, Size);

This change would enable use cases such as the following (contrived)

     template <int M>
     struct Foo
         Foo(Index m) : a(m*2) {}

         void bar()
             Index m = a.size() / 2;
             a.segment<M>(0, m) += a.segment<M>(m, m);

         enum { Rows = M == Dynamic ? Dynamic : M*2 };

         Eigen::Array<float, Rows, 1> a;


Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252

Mail converted by MHonArc 2.6.19+