// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2011 Benoit Jacob // Copyright (C) 2011 Gael Guennebaud // Copyright (C) 2011 Jitse Niesen // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifndef EIGEN_COREEVALUATORS_H #define EIGEN_COREEVALUATORS_H namespace internal { template struct evaluator_impl {}; template struct evaluator { typedef evaluator_impl type; }; template struct evaluator { typedef evaluator_impl type; }; template struct evaluator_impl > { typedef Transpose TransposeType; evaluator_impl(const TransposeType& t) : m_argImpl(t.nestedExpression()) {} typedef typename TransposeType::Index Index; typename TransposeType::CoeffReturnType coeff(Index i, Index j) const { return m_argImpl.coeff(j, i); } typename TransposeType::Scalar& coeffRef(Index i, Index j) { return m_argImpl.coeffRef(j, i); } protected: typename evaluator::type m_argImpl; }; template struct evaluator_impl > { typedef Matrix MatrixType; evaluator_impl(const MatrixType& m) : m_matrix(m) {} typedef typename MatrixType::Index Index; typename MatrixType::CoeffReturnType coeff(Index i, Index j) const { return m_matrix.coeff(i, j); } typename MatrixType::Scalar& coeffRef(Index i, Index j) { return m_matrix.const_cast_derived().coeffRef(i, j); } protected: const MatrixType &m_matrix; }; template struct evaluator_impl > { typedef Array ArrayType; evaluator_impl(const ArrayType& a) : m_array(a) {} typedef typename ArrayType::Index Index; Index colIndexByOuterInner(Index outer, Index inner) const { return m_array.colIndexByOuterInner(outer, inner); } typename ArrayType::CoeffReturnType coeff(Index i, Index j) const { return m_array.coeff(i, j); } typename ArrayType::Scalar& coeffRef(Index i, Index j) { return m_array.const_cast_derived().coeffRef(i, j); } protected: const ArrayType &m_array; }; template struct evaluator_impl > { typedef CwiseNullaryOp NullaryOpType; evaluator_impl(const NullaryOpType& n) : m_nullaryOp(n) {} typedef typename NullaryOpType::Index Index; typename NullaryOpType::CoeffReturnType coeff(Index i, Index j) const { return m_nullaryOp.coeff(i, j); } protected: const NullaryOpType& m_nullaryOp; }; template struct evaluator_impl > { typedef CwiseUnaryOp UnaryOpType; evaluator_impl(const UnaryOpType& op) : m_unaryOp(op), m_argImpl(op.nestedExpression()) {} typedef typename UnaryOpType::Index Index; typename UnaryOpType::CoeffReturnType coeff(Index i, Index j) const { return m_unaryOp.functor()(m_argImpl.coeff(i, j)); } protected: const UnaryOpType& m_unaryOp; typename evaluator::type m_argImpl; }; template struct evaluator_impl > { typedef CwiseBinaryOp BinaryOpType; evaluator_impl(const BinaryOpType& xpr) : m_binaryOp(xpr), m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) {} typedef typename BinaryOpType::Index Index; typename BinaryOpType::CoeffReturnType coeff(Index i, Index j) const { return m_binaryOp.functor()(m_lhsImpl.coeff(i, j),m_rhsImpl.coeff(i, j)); } protected: const BinaryOpType& m_binaryOp; typename evaluator::type m_lhsImpl; typename evaluator::type m_rhsImpl; }; // products template struct evaluator_impl > : public evaluator::PlainObject>::type { typedef GeneralProduct XprType; typedef typename XprType::PlainObject PlainObject; typedef typename evaluator::type evaluator_base; // enum { // EvaluateLhs = ; // EvaluateRhs = ; // }; evaluator_impl(const XprType& product) : evaluator_base(m_result), m_lhsImpl(product.lhs()), m_rhsImpl(product.rhs()) { m_result.resize(product.rows(), product.cols()); product.evalTo(m_result); } protected: PlainObject m_result; typename evaluator::type m_lhsImpl; typename evaluator::type m_rhsImpl; }; } // namespace internal #endif // EIGEN_COREEVALUATORS_H