mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-22 01:29:35 +08:00
Fix infinite recursion in ProductBase::coeff() (bug #447)
Triggered by product of dynamic-size 1 x n and n x 1 matrices. Also, add regression test.
This commit is contained in:
parent
5cab18976b
commit
57b5767fe2
@ -154,7 +154,8 @@ class ProductBase : public MatrixBase<Derived>
|
||||
#else
|
||||
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
|
||||
eigen_assert(this->rows() == 1 && this->cols() == 1);
|
||||
return derived().coeff(row,col);
|
||||
Matrix<Scalar,1,1> result = *this;
|
||||
return result.coeff(row,col);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -162,7 +163,8 @@ class ProductBase : public MatrixBase<Derived>
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_SIZE_1x1(Derived)
|
||||
eigen_assert(this->rows() == 1 && this->cols() == 1);
|
||||
return derived().coeff(i);
|
||||
Matrix<Scalar,1,1> result = *this;
|
||||
return result.coeff(i);
|
||||
}
|
||||
|
||||
const Scalar& coeffRef(Index row, Index col) const
|
||||
|
@ -25,6 +25,25 @@
|
||||
#define EIGEN_NO_STATIC_ASSERT
|
||||
#include "product.h"
|
||||
|
||||
// regression test for bug 447
|
||||
void product1x1()
|
||||
{
|
||||
Matrix<float,1,3> matAstatic;
|
||||
Matrix<float,3,1> matBstatic;
|
||||
matAstatic.setRandom();
|
||||
matBstatic.setRandom();
|
||||
VERIFY_IS_APPROX( (matAstatic * matBstatic).coeff(0,0),
|
||||
matAstatic.cwiseProduct(matBstatic.transpose()).sum() );
|
||||
|
||||
MatrixXf matAdynamic(1,3);
|
||||
MatrixXf matBdynamic(3,1);
|
||||
matAdynamic.setRandom();
|
||||
matBdynamic.setRandom();
|
||||
VERIFY_IS_APPROX( (matAdynamic * matBdynamic).coeff(0,0),
|
||||
matAdynamic.cwiseProduct(matBdynamic.transpose()).sum() );
|
||||
}
|
||||
|
||||
|
||||
void test_product_small()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
@ -33,6 +52,7 @@ void test_product_small()
|
||||
CALL_SUBTEST_3( product(Matrix3d()) );
|
||||
CALL_SUBTEST_4( product(Matrix4d()) );
|
||||
CALL_SUBTEST_5( product(Matrix4f()) );
|
||||
CALL_SUBTEST_6( product1x1() );
|
||||
}
|
||||
|
||||
#ifdef EIGEN_TEST_PART_6
|
||||
|
Loading…
x
Reference in New Issue
Block a user