Re: [eigen] Assertion in DenseStorageBase.h:487: Nonnegativity of rows and cols sufficient?

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


Am Dienstag 20 Juli 2010, 20:39:13 schrieb Benoit Jacob:
> Yes, it's OK. Can you send us the patch?

Sure, here it is.

Cheers,
Martin





> http://eigen.tuxfamily.org/index.php?title=Developer%27s_Corner#Generating_
> a_patch
> 
> 2010/7/20 Martin Senst <martin.senst@xxxxxx>:
> > Hi everyone,
> > 
> > sorry to bother you again with the topic of zero-sized matrices, but as
> > I've written in the thread about sum() of empty vectors, I need them to
> > avoid ugly special-case-treatments.
> > 
> > 
> > I'm wondering wheter it's okay to change the assertion in
> > DenseStorageBase.h, lines 486 and 487, from
> > 
> > ei_assert(rows > 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime
> > == rows)
> > && cols > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime ==
> > cols));
> > 
> > to
> > 
> > ei_assert(rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime
> > == rows)
> > && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime ==
> > cols));
> > 
> > 
> > 
> > The issue is that currently, code like
> > 
> > MatrixXd A(0, 0);
> > MatrixXd B(0, N);
> > MatrixXd C(N, 0);
> > 
> > fails due to this assertion. If compiled with NDEBUG, this code works as
> > expected, so I guess that the current assertion is overly strict.
> > 
> > As a workaround, something like
> > MatrixXd C = MatrixXd(N, 1).leftCols(0);
> > works, but of course that's pretty ugly.
> > 
> > Cheers
> > Martin

# HG changeset patch
# User Martin Senst <martin.senst@xxxxxx>
# Date 1279653943 -7200
# Node ID defc739310a66c7d9a791ead554eb59196f857fa
# Parent  a8f803f4138581ef952b9d1e942821ebafe8bae6
Relax assertion to allow for matrices with cols() == 0 and/or rows() == 0.

diff -r a8f803f41385 -r defc739310a6 Eigen/src/Core/DenseStorageBase.h
--- a/Eigen/src/Core/DenseStorageBase.h	Mon Jul 19 12:26:52 2010 +0100
+++ b/Eigen/src/Core/DenseStorageBase.h	Tue Jul 20 21:25:43 2010 +0200
@@ -483,8 +483,8 @@
     template<typename T0, typename T1>
     EIGEN_STRONG_INLINE void _init2(Index rows, Index cols, typename ei_enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0)
     {
-      ei_assert(rows > 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
-             && cols > 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
+      ei_assert(rows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows)
+             && cols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols));
       m_storage.resize(rows*cols,rows,cols);
       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
     }


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