improve aliasing detection for inverse and add unit test

This commit is contained in:
Gael Guennebaud
2010-06-02 10:12:13 +02:00
parent 4ebb80490a
commit 143e6ab9d0
2 changed files with 17 additions and 2 deletions

View File

@@ -295,8 +295,10 @@ struct ei_inverse_impl : public ReturnByValue<ei_inverse_impl<MatrixType> >
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();
ei_assert(&dst != (Dest*)(&m_matrix) && "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
const int Size = EIGEN_ENUM_MIN(MatrixType::ColsAtCompileTime,Dest::ColsAtCompileTime);
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);
}
};