mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
improve aliasing detection for inverse and add unit test
This commit is contained in:
parent
4ebb80490a
commit
143e6ab9d0
@ -295,8 +295,10 @@ struct ei_inverse_impl : public ReturnByValue<ei_inverse_impl<MatrixType> >
|
|||||||
|
|
||||||
template<typename Dest> inline void evalTo(Dest& dst) const
|
template<typename Dest> inline void evalTo(Dest& dst) const
|
||||||
{
|
{
|
||||||
// FIXME this is a naive aliasing check that could be improved. It only catches x = x.inverse();
|
const int Size = EIGEN_ENUM_MIN(MatrixType::ColsAtCompileTime,Dest::ColsAtCompileTime);
|
||||||
ei_assert(&dst != (Dest*)(&m_matrix) && "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
|
ei_assert(( (Size<=1) || (Size>4) || (ei_extract_data(m_matrix)!=ei_extract_data(dst)))
|
||||||
|
&& "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
|
||||||
|
|
||||||
ei_compute_inverse<MatrixTypeNestedCleaned, Dest>::run(m_matrix, dst);
|
ei_compute_inverse<MatrixTypeNestedCleaned, Dest>::run(m_matrix, dst);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -82,6 +82,19 @@ template<typename MatrixType> void inverse(const MatrixType& m)
|
|||||||
m3.computeInverseWithCheck(m4, invertible);
|
m3.computeInverseWithCheck(m4, invertible);
|
||||||
VERIFY( rows==1 ? invertible : !invertible );
|
VERIFY( rows==1 ? invertible : !invertible );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// check in-place inversion
|
||||||
|
if(MatrixType::RowsAtCompileTime>=2 && MatrixType::RowsAtCompileTime<=4)
|
||||||
|
{
|
||||||
|
// in-place is forbidden
|
||||||
|
VERIFY_RAISES_ASSERT(m1 = m1.inverse());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m2 = m1.inverse();
|
||||||
|
m1 = m1.inverse();
|
||||||
|
VERIFY_IS_APPROX(m1,m2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_inverse()
|
void test_inverse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user