add support for determinant on empty matrix

This commit is contained in:
Gael Guennebaud 2010-07-19 10:45:06 +02:00
parent 78d3c54631
commit cac147ba10
2 changed files with 5 additions and 0 deletions

View File

@ -47,6 +47,8 @@ template<typename Derived,
{ {
static inline typename ei_traits<Derived>::Scalar run(const Derived& m) static inline typename ei_traits<Derived>::Scalar run(const Derived& m)
{ {
if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0)
return typename ei_traits<Derived>::Scalar(1);
return m.partialPivLu().determinant(); return m.partialPivLu().determinant();
} }
}; };

View File

@ -61,6 +61,9 @@ template<typename MatrixType> void determinant(const MatrixType& m)
m2 = m1; m2 = m1;
m2.row(i) *= x; m2.row(i) *= x;
VERIFY_IS_APPROX(m2.determinant(), m1.determinant() * x); VERIFY_IS_APPROX(m2.determinant(), m1.determinant() * x);
// check empty matrix
VERIFY_IS_APPROX(m2.block(0,0,0,0).determinant(), Scalar(1));
} }
void test_determinant() void test_determinant()