mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
Implement evaluator for Replicate.
This commit is contained in:
parent
12a30a982f
commit
11164830f5
@ -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
|
} // namespace internal
|
||||||
|
|
||||||
#endif // EIGEN_COREEVALUATORS_H
|
#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);
|
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:
|
protected:
|
||||||
const typename MatrixType::Nested m_matrix;
|
const typename MatrixType::Nested m_matrix;
|
||||||
|
@ -167,4 +167,13 @@ void test_evaluators()
|
|||||||
|
|
||||||
// test Select
|
// test Select
|
||||||
VERIFY_IS_APPROX_EVALUATOR(aX, (aXsrc > 0).select(aXsrc, -aXsrc));
|
VERIFY_IS_APPROX_EVALUATOR(aX, (aXsrc > 0).select(aXsrc, -aXsrc));
|
||||||
|
|
||||||
|
// test Replicate
|
||||||
|
mXsrc = MatrixXf::Random(6, 6);
|
||||||
|
VectorXf vX = VectorXf::Random(6);
|
||||||
|
mX.resize(6, 6);
|
||||||
|
VERIFY_IS_APPROX_EVALUATOR(mX, mXsrc.colwise() + vX);
|
||||||
|
matXcd.resize(12, 12);
|
||||||
|
VERIFY_IS_APPROX_EVALUATOR(matXcd, matXcd_ref.replicate(2,2));
|
||||||
|
VERIFY_IS_APPROX_EVALUATOR(matXcd, (matXcd_ref.replicate<2,2>()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user