Drop evaluators for SwapWrapper and SelfCwiseBinaryOp

This commit is contained in:
Gael Guennebaud 2013-11-07 14:07:27 +01:00
parent 5887e82729
commit 57327cc2d5

View File

@ -178,9 +178,9 @@ protected:
const Scalar *m_data;
// We do not need to know the outer stride for vectors
variable_if_dynamic<Index, IsVectorAtCompileTime ? 0
: int(IsRowMajor) ? ColsAtCompileTime
: RowsAtCompileTime> m_outerStride;
variable_if_dynamic<Index, IsVectorAtCompileTime ? 0
: int(IsRowMajor) ? ColsAtCompileTime
: RowsAtCompileTime> m_outerStride;
};
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
@ -1114,143 +1114,6 @@ private:
EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value() > 0 ? m_index.value() : 0; }
};
// ---------- SwapWrapper ----------
template<typename ArgType>
struct evaluator_impl<SwapWrapper<ArgType> >
: evaluator_impl_base<SwapWrapper<ArgType> >
{
typedef SwapWrapper<ArgType> XprType;
evaluator_impl(const XprType& swapWrapper)
: m_argImpl(swapWrapper.expression())
{ }
typedef typename XprType::Index Index;
typedef typename XprType::Scalar Scalar;
typedef typename XprType::Packet Packet;
// This function and the next one are needed by assign to correctly align loads/stores
// TODO make Assign use .data()
Scalar& coeffRef(Index row, Index col)
{
return m_argImpl.coeffRef(row, col);
}
inline Scalar& coeffRef(Index index)
{
return m_argImpl.coeffRef(index);
}
template<typename OtherEvaluatorType>
void copyCoeff(Index row, Index col, const OtherEvaluatorType& other)
{
OtherEvaluatorType& nonconst_other = const_cast<OtherEvaluatorType&>(other);
Scalar tmp = m_argImpl.coeff(row, col);
m_argImpl.coeffRef(row, col) = nonconst_other.coeff(row, col);
nonconst_other.coeffRef(row, col) = tmp;
}
template<typename OtherEvaluatorType>
void copyCoeff(Index index, const OtherEvaluatorType& other)
{
OtherEvaluatorType& nonconst_other = const_cast<OtherEvaluatorType&>(other);
Scalar tmp = m_argImpl.coeff(index);
m_argImpl.coeffRef(index) = nonconst_other.coeff(index);
nonconst_other.coeffRef(index) = tmp;
}
template<int StoreMode, int LoadMode, typename OtherEvaluatorType>
void copyPacket(Index row, Index col, const OtherEvaluatorType& other)
{
OtherEvaluatorType& nonconst_other = const_cast<OtherEvaluatorType&>(other);
Packet tmp = m_argImpl.template packet<StoreMode>(row, col);
m_argImpl.template writePacket<StoreMode>
(row, col, nonconst_other.template packet<LoadMode>(row, col));
nonconst_other.template writePacket<LoadMode>(row, col, tmp);
}
template<int StoreMode, int LoadMode, typename OtherEvaluatorType>
void copyPacket(Index index, const OtherEvaluatorType& other)
{
OtherEvaluatorType& nonconst_other = const_cast<OtherEvaluatorType&>(other);
Packet tmp = m_argImpl.template packet<StoreMode>(index);
m_argImpl.template writePacket<StoreMode>
(index, nonconst_other.template packet<LoadMode>(index));
nonconst_other.template writePacket<LoadMode>(index, tmp);
}
protected:
typename evaluator<ArgType>::nestedType m_argImpl;
};
// ---------- SelfCwiseBinaryOp ----------
template<typename BinaryOp, typename LhsXpr, typename RhsXpr>
struct evaluator_impl<SelfCwiseBinaryOp<BinaryOp, LhsXpr, RhsXpr> >
: evaluator_impl_base<SelfCwiseBinaryOp<BinaryOp, LhsXpr, RhsXpr> >
{
typedef SelfCwiseBinaryOp<BinaryOp, LhsXpr, RhsXpr> XprType;
evaluator_impl(const XprType& selfCwiseBinaryOp)
: m_argImpl(selfCwiseBinaryOp.expression()),
m_functor(selfCwiseBinaryOp.functor())
{ }
typedef typename XprType::Index Index;
typedef typename XprType::Scalar Scalar;
typedef typename XprType::Packet Packet;
// This function and the next one are needed by assign to correctly align loads/stores
// TODO make Assign use .data()
Scalar& coeffRef(Index row, Index col)
{
return m_argImpl.coeffRef(row, col);
}
inline Scalar& coeffRef(Index index)
{
return m_argImpl.coeffRef(index);
}
template<typename OtherEvaluatorType>
void copyCoeff(Index row, Index col, const OtherEvaluatorType& other)
{
Scalar& tmp = m_argImpl.coeffRef(row, col);
tmp = m_functor(tmp, other.coeff(row, col));
}
template<typename OtherEvaluatorType>
void copyCoeff(Index index, const OtherEvaluatorType& other)
{
Scalar& tmp = m_argImpl.coeffRef(index);
tmp = m_functor(tmp, other.coeff(index));
}
template<int StoreMode, int LoadMode, typename OtherEvaluatorType>
void copyPacket(Index row, Index col, const OtherEvaluatorType& other)
{
const Packet res = m_functor.packetOp(m_argImpl.template packet<StoreMode>(row, col),
other.template packet<LoadMode>(row, col));
m_argImpl.template writePacket<StoreMode>(row, col, res);
}
template<int StoreMode, int LoadMode, typename OtherEvaluatorType>
void copyPacket(Index index, const OtherEvaluatorType& other)
{
const Packet res = m_functor.packetOp(m_argImpl.template packet<StoreMode>(index),
other.template packet<LoadMode>(index));
m_argImpl.template writePacket<StoreMode>(index, res);
}
protected:
typename evaluator<LhsXpr>::nestedType m_argImpl;
const BinaryOp m_functor;
};
} // namespace internal
} // end namespace Eigen