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

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


Hi!

This is similar to bug 579.
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=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 https://bitbucket.org/eigen/eigen/commits/e1dfda4)

Cheers,
Christoph



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,
e.g.

     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_STATIC_ASSERT_VECTOR_ONLY(Derived)
         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)
example:

     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;
     };

Marton



--
----------------------------------------------
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+ http://listengine.tuxfamily.org/