diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-04-05 18:20:43 +0100 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-04-05 18:20:43 +0100 |
commit | 11ea81858ae113ae11ee79dbb3a338172507a1bc (patch) | |
tree | a9887d2d8bcc9e92bf078f482b6a8f4dfba42dd6 | |
parent | cca7b146a2018a74aa5f83edc0797fab89b1040e (diff) |
Implement evaluator for CwiseUnaryView
-rw-r--r-- | Eigen/src/Core/CoreEvaluators.h | 43 | ||||
-rw-r--r-- | test/evaluators.cpp | 12 |
2 files changed, 53 insertions, 2 deletions
diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index 3060ca982..9ed942135 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -259,7 +259,7 @@ struct evaluator_impl<CwiseUnaryOp<UnaryOp, ArgType> > } protected: - const UnaryOpType& m_unaryOp; + const UnaryOpType m_unaryOp; typename evaluator<ArgType>::type m_argImpl; }; @@ -304,6 +304,47 @@ protected: typename evaluator<Rhs>::type m_rhsImpl; }; +// -------------------- CwiseUnaryView -------------------- + +template<typename UnaryOp, typename ArgType> +struct evaluator_impl<CwiseUnaryView<UnaryOp, ArgType> > +{ + typedef CwiseUnaryView<UnaryOp, ArgType> CwiseUnaryViewType; + + evaluator_impl(const CwiseUnaryViewType& op) + : m_unaryOp(op.functor()), + m_argImpl(op.nestedExpression()) + { } + + typedef typename CwiseUnaryViewType::Index Index; + typedef typename CwiseUnaryViewType::Scalar Scalar; + typedef typename CwiseUnaryViewType::CoeffReturnType CoeffReturnType; + + CoeffReturnType coeff(Index row, Index col) const + { + return m_unaryOp(m_argImpl.coeff(row, col)); + } + + CoeffReturnType coeff(Index index) const + { + return m_unaryOp(m_argImpl.coeff(index)); + } + + Scalar& coeffRef(Index row, Index col) + { + return m_unaryOp(m_argImpl.coeffRef(row, col)); + } + + Scalar& coeffRef(Index index) + { + return m_unaryOp(m_argImpl.coeffRef(index)); + } + +protected: + const UnaryOp& m_unaryOp; + typename evaluator<ArgType>::type m_argImpl; +}; + // -------------------- Product -------------------- template<typename Lhs, typename Rhs> diff --git a/test/evaluators.cpp b/test/evaluators.cpp index b2bc42840..bd4e89806 100644 --- a/test/evaluators.cpp +++ b/test/evaluators.cpp @@ -143,7 +143,7 @@ void test_evaluators() mXref.block(4, 4, 9, 12) = mXsrc; VERIFY_IS_APPROX(mX, mXref); - // Testing Map + // test Map const float raw[3] = {1,2,3}; float buffer[3] = {0,0,0}; Vector3f v3; @@ -154,4 +154,14 @@ void test_evaluators() VERIFY(buffer[0] == 2); VERIFY(buffer[1] == 4); VERIFY(buffer[2] == 6); + + // test CwiseUnaryView + mat1.setRandom(); + mat2.setIdentity(); + MatrixXcd matXcd(6,6), matXcd_ref(6,6); + copy_using_evaluator(matXcd.real(), mat1); + copy_using_evaluator(matXcd.imag(), mat2); + matXcd_ref.real() = mat1; + matXcd_ref.imag() = mat2; + VERIFY_IS_APPROX(matXcd, matXcd_ref); } |