* Make ReturnByValue have the EvalBeforeAssigningBit and explicitly

enforce this mechanism (otherwise ReturnByValue bypasses it).
 (use .noalias() to get the old behavior.)
* Remove a hack in Inverse, futile optimization for 2x2 expressions.
This commit is contained in:
Benoit Jacob
2010-05-30 13:43:08 -04:00
parent 48b8ace517
commit 641d968a9a
4 changed files with 21 additions and 23 deletions

View File

@@ -45,12 +45,18 @@ class NoAlias
public:
NoAlias(ExpressionType& expression) : m_expression(expression) {}
/** Behaves like MatrixBase::lazyAssign(other)
* \sa MatrixBase::lazyAssign() */
/* \sa MatrixBase::lazyAssign() */
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase<OtherDerived>& other)
{ return m_expression.lazyAssign(other.derived()); }
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator=(const ReturnByValue<OtherDerived>& other)
{
other.evalTo(m_expression);
return m_expression;
}
/** \sa MatrixBase::operator+= */
template<typename OtherDerived>
EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase<OtherDerived>& other)

View File

@@ -36,9 +36,9 @@ struct ei_traits<ReturnByValue<Derived> >
enum {
// We're disabling the DirectAccess because e.g. the constructor of
// the Block-with-DirectAccess expression requires to have a coeffRef method.
// Also, we don't want to have to implement the stride stuff.
// FIXME this should be fixed so we can have DirectAccessBit here.
Flags = (ei_traits<typename ei_traits<Derived>::ReturnType>::Flags
| EvalBeforeNestingBit) & ~DirectAccessBit
| EvalBeforeNestingBit | EvalBeforeAssigningBit) & ~DirectAccessBit
};
};
@@ -83,8 +83,11 @@ template<typename Derived>
template<typename OtherDerived>
Derived& DenseBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
{
other.evalTo(derived());
return derived();
// since we're by-passing the mechanisms in Assign.h, we implement here the EvalBeforeAssigningBit.
// override by using .noalias(), see corresponding operator= in NoAlias.
typename Derived::PlainObject result(rows(), cols());
other.evalTo(result);
return (derived() = result);
}
#endif // EIGEN_RETURNBYVALUE_H