[eigen] Assertion in DenseStorageBase.h:487: Nonnegativity of rows and cols sufficient? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
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