mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Implement evaluator for Replicate.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user