Fix detection of vector-at-time: use Rows/Cols instead of MaxRow/MaxCols.

This fix VectorXd(n).middleCol(0,0).outerSize() which was equal to 1.
This commit is contained in:
Gael Guennebaud 2019-01-15 15:09:49 +01:00
parent 32d7232aec
commit f8bc5cb39e
2 changed files with 19 additions and 6 deletions

View File

@ -150,8 +150,8 @@ template<typename Derived> class DenseBase
* \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
*/
IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
|| internal::traits<Derived>::MaxColsAtCompileTime == 1,
IsVectorAtCompileTime = internal::traits<Derived>::RowsAtCompileTime == 1
|| internal::traits<Derived>::ColsAtCompileTime == 1,
/**< This is set to true if either the number of rows or the number of
* columns is known at compile-time to be equal to 1. Indeed, in that case,
* we are dealing with a column-vector (if there is only one column) or with

View File

@ -227,6 +227,16 @@ template<typename MatrixType> void block(const MatrixType& m)
VERIFY_IS_APPROX( (m1+m1).template subVector<Vertical>(c1), (m1+m1).col(c1) );
VERIFY_IS_EQUAL( m1.template subVectors<Horizontal>(), m1.rows() );
VERIFY_IS_EQUAL( m1.template subVectors<Vertical>(), m1.cols() );
if (rows>=2 || cols>=2) {
VERIFY_IS_EQUAL( int(m1.middleCols(0,0).IsRowMajor), int(m1.IsRowMajor) );
VERIFY_IS_EQUAL( m1.middleCols(0,0).outerSize(), m1.IsRowMajor ? rows : 0);
VERIFY_IS_EQUAL( m1.middleCols(0,0).innerSize(), m1.IsRowMajor ? 0 : rows);
VERIFY_IS_EQUAL( int(m1.middleRows(0,0).IsRowMajor), int(m1.IsRowMajor) );
VERIFY_IS_EQUAL( m1.middleRows(0,0).outerSize(), m1.IsRowMajor ? 0 : cols);
VERIFY_IS_EQUAL( m1.middleRows(0,0).innerSize(), m1.IsRowMajor ? cols : 0);
}
}
@ -287,11 +297,14 @@ EIGEN_DECLARE_TEST(block)
{
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST_1( block(Matrix<float, 1, 1>()) );
CALL_SUBTEST_1( block(Matrix<float, 1, Dynamic>(internal::random(2,50))) );
CALL_SUBTEST_1( block(Matrix<float, Dynamic, 1>(internal::random(2,50))) );
CALL_SUBTEST_2( block(Matrix4d()) );
CALL_SUBTEST_3( block(MatrixXcf(3, 3)) );
CALL_SUBTEST_4( block(MatrixXi(8, 12)) );
CALL_SUBTEST_5( block(MatrixXcd(20, 20)) );
CALL_SUBTEST_6( block(MatrixXf(20, 20)) );
CALL_SUBTEST_3( block(MatrixXcf(internal::random(2,50), internal::random(2,50))) );
CALL_SUBTEST_4( block(MatrixXi(internal::random(2,50), internal::random(2,50))) );
CALL_SUBTEST_5( block(MatrixXcd(internal::random(2,50), internal::random(2,50))) );
CALL_SUBTEST_6( block(MatrixXf(internal::random(2,50), internal::random(2,50))) );
CALL_SUBTEST_7( block(Matrix<int,Dynamic,Dynamic,RowMajor>(internal::random(2,50), internal::random(2,50))) );
CALL_SUBTEST_8( block(Matrix<float,Dynamic,4>(3, 4)) );