Re: [eigen] Generic conservativeResize() for both matrices and vectors?

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


Thanks Hauke! Alright, if the only way are the specializations of
conservative_resize_like_impl<>, my solution is not ugly, it's just
necessary :-)

On your proposal to overload foo() instead, I can't use it in my real
function, since the sizes are determined dynamically within the
function, not passed as arguments (that was for the  example). Anyway,
thanks for your quick answer!

Best,
JL

On Fri, Nov 26, 2010 at 7:45 PM, Hauke Heibel
<hauke.heibel@xxxxxxxxxxxxxx> wrote:
> Hi Jose,
>
> This behavior exists on purpose. The conservative_resize_like_impl
> helper struct provides run(...) with two indices only for matrices and
> not for vectors. The functionality you desire requires additional
> error checks to be completely safe to guard against parameters
> deviating from 1 when working with row vectors.
>
> Your approach is the only workaround. I would change the templates a
> bit and declare MatOrVecResizer as
>
>  template<typename Derived, int R = Derived::RowsAtCompileTime, int C
> = Derived::ColsAtCompileTime> struct MatOrVecResizer;
>
> thus you have to write less when actually calling the helper as below
>
>  detail::MatOrVecResizer<Derived>::doit(m,nRows,nCols);
>
> I don't consider your solution as ugly but what I would be worried
> about is the fact that
>
>  Matrix<double,1,Dynamic>  M;
>  foo(M,1000,4); // this
>  foo(M,1,4); // and this
>
> do the same things without letting you know.
>
> One alternative - which would be working for Matrices only is to
> overload foo() for dynamic matrices as well as row and column vectors.
> You would loose the compatibility with expressions templates but on
> the other hand side resizing does not make much sense on general
> expressions - pretty much no sense at all. You could define them as
>
> template <class Scalar> void foo(
> Eigen::Matrix<Scalar,Dynamic,Dynamic> &m, int nRows, int nCols );
> template <class Scalar> void foo( Eigen::Matrix<Scalar,Dynamic,1> &m,
> int nRows, int nCols );
> template <class Scalar> void foo( Eigen::Matrix<Scalar,1,Dynamic> &m,
> int nRows, int nCols );
>
> Kind regards,
> Hauke
>
>
>



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