Implement evaluator for Replicate.

This commit is contained in:
Jitse Niesen
2011-04-12 22:54:31 +01:00
parent 12a30a982f
commit 11164830f5
3 changed files with 63 additions and 0 deletions

View File

@@ -615,6 +615,56 @@ protected:
};
// -------------------- Replicate --------------------
template<typename XprType, int RowFactor, int ColFactor>
struct evaluator_impl<Replicate<XprType, RowFactor, ColFactor> >
{
typedef Replicate<XprType, RowFactor, ColFactor> ReplicateType;
evaluator_impl(const ReplicateType& replicate)
: m_argImpl(replicate.nestedExpression()),
m_rows(replicate.nestedExpression().rows()),
m_cols(replicate.nestedExpression().cols())
{ }
typedef typename ReplicateType::Index Index;
typedef typename ReplicateType::CoeffReturnType CoeffReturnType;
typedef typename ReplicateType::PacketReturnType PacketReturnType;
CoeffReturnType coeff(Index row, Index col) const
{
// try to avoid using modulo; this is a pure optimization strategy
const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
: RowFactor==1 ? row
: row % m_rows;
const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
: ColFactor==1 ? col
: col % m_cols;
return m_argImpl.coeff(actual_row, actual_col);
}
template<int LoadMode>
PacketReturnType packet(Index row, Index col) const
{
const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
: RowFactor==1 ? row
: row % m_rows;
const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
: ColFactor==1 ? col
: col % m_cols;
return m_argImpl.template packet<LoadMode>(actual_row, actual_col);
}
protected:
typename evaluator<XprType>::type m_argImpl;
Index m_rows;
Index m_cols;
};
} // namespace internal
#endif // EIGEN_COREEVALUATORS_H

View File

@@ -122,6 +122,10 @@ template<typename MatrixType,int RowFactor,int ColFactor> class Replicate
return m_matrix.template packet<LoadMode>(actual_row, actual_col);
}
const typename internal::remove_all<typename MatrixType::Nested>::type& nestedExpression() const
{
return m_matrix;
}
protected:
const typename MatrixType::Nested m_matrix;