mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-13 12:19:12 +08:00
bug #1669: fix PartialPivLU/inverse with zero-sized matrices.
(grafted from 8a06c699d0f8d47f4fc4f259a21574b4719792b2 )
This commit is contained in:
parent
7b160dcc82
commit
c30beb5974
@ -519,7 +519,10 @@ void PartialPivLU<MatrixType>::compute()
|
||||
// the row permutation is stored as int indices, so just to be sure:
|
||||
eigen_assert(m_lu.rows()<NumTraits<int>::highest());
|
||||
|
||||
m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
|
||||
if(m_lu.cols()>0)
|
||||
m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
|
||||
else
|
||||
m_l1_norm = RealScalar(0);
|
||||
|
||||
eigen_assert(m_lu.rows() == m_lu.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
|
||||
const Index size = m_lu.rows();
|
||||
|
@ -92,6 +92,22 @@ template<typename MatrixType> void inverse(const MatrixType& m)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
void inverse_zerosized()
|
||||
{
|
||||
Matrix<Scalar,Dynamic,Dynamic> A(0,0);
|
||||
{
|
||||
Matrix<Scalar,0,1> b, x;
|
||||
x = A.inverse() * b;
|
||||
}
|
||||
{
|
||||
Matrix<Scalar,Dynamic,Dynamic> b(0,1), x;
|
||||
x = A.inverse() * b;
|
||||
VERIFY_IS_EQUAL(x.rows(), 0);
|
||||
VERIFY_IS_EQUAL(x.cols(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
void test_inverse()
|
||||
{
|
||||
int s = 0;
|
||||
@ -105,6 +121,7 @@ void test_inverse()
|
||||
s = internal::random<int>(50,320);
|
||||
CALL_SUBTEST_5( inverse(MatrixXf(s,s)) );
|
||||
TEST_SET_BUT_UNUSED_VARIABLE(s)
|
||||
CALL_SUBTEST_5( inverse_zerosized<float>() );
|
||||
|
||||
s = internal::random<int>(25,100);
|
||||
CALL_SUBTEST_6( inverse(MatrixXcd(s,s)) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user