bug #1272: Disable assertion when total number of columns is zero.

Also moved assertion to finished() method and adapted unit-test
This commit is contained in:
Christoph Hertzberg 2016-08-12 15:15:34 +02:00
parent e3a8dfb02f
commit c83b754ee0
2 changed files with 12 additions and 8 deletions

View File

@ -103,9 +103,7 @@ struct CommaInitializer
EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception) EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception)
#endif #endif
{ {
eigen_assert((m_row+m_currentBlockRows) == m_xpr.rows() finished();
&& m_col == m_xpr.cols()
&& "Too few coefficients passed to comma initializer (operator<<)");
} }
/** \returns the built matrix once all its coefficients have been set. /** \returns the built matrix once all its coefficients have been set.
@ -116,7 +114,12 @@ struct CommaInitializer
* \endcode * \endcode
*/ */
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
inline XprType& finished() { return m_xpr; } inline XprType& finished() {
eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0)
&& m_col == m_xpr.cols()
&& "Too few coefficients passed to comma initializer (operator<<)");
return m_xpr;
}
XprType& m_xpr; // target expression XprType& m_xpr; // target expression
Index m_row; // current row id Index m_row; // current row id

View File

@ -23,11 +23,12 @@ void test_blocks()
MatrixXi matx11 = mat11, matx12 = mat12, matx21 = mat21, matx22 = mat22; MatrixXi matx11 = mat11, matx12 = mat12, matx21 = mat21, matx22 = mat22;
// The only remaining border case is M1==M2>0 && N1==N2==0.
// In that case it is not possible to decide (without backtracking) if a block starts a new row or does not
if(M1 != M2 || M1 == 0 || N1>0 || N2>0)
{ {
VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat21, matx22).finished(), (m_dynamic << mat11, matx12, mat21, matx22).finished()); VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat21, matx22).finished(), (m_dynamic << mat11, matx12, mat21, matx22).finished());
VERIFY_IS_EQUAL((m_fixed.template topLeftCorner<M1,N1>()), mat11);
VERIFY_IS_EQUAL((m_fixed.template topRightCorner<M1,N2>()), mat12);
VERIFY_IS_EQUAL((m_fixed.template bottomLeftCorner<M2,N1>()), mat21);
VERIFY_IS_EQUAL((m_fixed.template bottomRightCorner<M2,N2>()), mat22);
VERIFY_IS_EQUAL((m_fixed << mat12, mat11, matx21, mat22).finished(), (m_dynamic << mat12, matx11, matx21, mat22).finished()); VERIFY_IS_EQUAL((m_fixed << mat12, mat11, matx21, mat22).finished(), (m_dynamic << mat12, matx11, matx21, mat22).finished());
} }
@ -36,7 +37,7 @@ void test_blocks()
VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22)); VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat11, mat21, mat22));
VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22)); VERIFY_RAISES_ASSERT((m_fixed << mat11, mat12, mat21, mat21, mat22));
} }
else if(N2 > 0 || M1 != M2) // border case if both sublocks have zero columns and same number of rows else
{ {
// allow insertion of zero-column blocks: // allow insertion of zero-column blocks:
VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat11, mat11, mat21, mat21, mat22).finished(), (m_dynamic << mat12, mat22).finished()); VERIFY_IS_EQUAL((m_fixed << mat11, mat12, mat11, mat11, mat21, mat21, mat22).finished(), (m_dynamic << mat12, mat22).finished());