diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2013-07-31 14:57:20 +0100 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2013-07-31 14:57:20 +0100 |
commit | 68168e9eae53b56a9b063d0fa5bd6f7f02cca1bf (patch) | |
tree | 9714006363a8844d26bb0d8b82ba4ceaa9adb372 /unsupported | |
parent | 43df1e707c523808864eb7b9f0781846ff57916b (diff) |
MatrixFunctions: replace eval() by nested.
This eliminates an unnecessary copy in some situations, e.g. Map.
Diffstat (limited to 'unsupported')
4 files changed, 29 insertions, 24 deletions
diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h b/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h index d67ded7ba..05df5a102 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h @@ -392,17 +392,14 @@ template<typename Derived> struct MatrixExponentialReturnValue template <typename ResultType> inline void evalTo(ResultType& result) const { - const typename Derived::PlainObject srcEvaluated = m_src.eval(); - internal::matrix_exp_compute(srcEvaluated, result); + internal::matrix_exp_compute(m_src, result); } Index rows() const { return m_src.rows(); } Index cols() const { return m_src.cols(); } protected: - const Derived& m_src; - private: - MatrixExponentialReturnValue& operator=(const MatrixExponentialReturnValue&); + const typename internal::nested<Derived, 10>::type m_src; }; namespace internal { diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h b/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h index a5675228e..f619d8ae5 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixFunction.h @@ -481,11 +481,15 @@ template<typename Derived> class MatrixFunctionReturnValue : public ReturnByValue<MatrixFunctionReturnValue<Derived> > { public: - typedef typename Derived::Scalar Scalar; typedef typename Derived::Index Index; typedef typename internal::stem_function<Scalar>::type StemFunction; + protected: + typedef typename internal::nested<Derived, 10>::type DerivedNested; + + public: + /** \brief Constructor. * * \param[in] A %Matrix (expression) forming the argument of the matrix function. @@ -500,26 +504,25 @@ template<typename Derived> class MatrixFunctionReturnValue template <typename ResultType> inline void evalTo(ResultType& result) const { - typedef typename Derived::PlainObject PlainObject; - typedef internal::traits<PlainObject> Traits; + typedef typename internal::remove_all<DerivedNested>::type DerivedNestedClean; + typedef internal::traits<DerivedNestedClean> Traits; static const int RowsAtCompileTime = Traits::RowsAtCompileTime; static const int ColsAtCompileTime = Traits::ColsAtCompileTime; - static const int Options = PlainObject::Options; + static const int Options = DerivedNestedClean::Options; typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; typedef Matrix<ComplexScalar, Dynamic, Dynamic, Options, RowsAtCompileTime, ColsAtCompileTime> DynMatrixType; typedef internal::MatrixFunctionAtomic<DynMatrixType> AtomicType; AtomicType atomic(m_f); - const PlainObject Aevaluated = m_A.eval(); - internal::matrix_function_compute<PlainObject>::run(Aevaluated, atomic, result); + internal::matrix_function_compute<DerivedNestedClean>::run(m_A, atomic, result); } Index rows() const { return m_A.rows(); } Index cols() const { return m_A.cols(); } private: - typename internal::nested<Derived>::type m_A; + const DerivedNested m_A; StemFunction *m_f; }; diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h b/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h index 6f84a31bd..6248eeec7 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk> +// Copyright (C) 2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> // Copyright (C) 2011 Chen-Pang He <jdh8@ms63.hinet.net> // // This Source Code Form is subject to the terms of the Mozilla @@ -306,10 +306,14 @@ template<typename Derived> class MatrixLogarithmReturnValue : public ReturnByValue<MatrixLogarithmReturnValue<Derived> > { public: - typedef typename Derived::Scalar Scalar; typedef typename Derived::Index Index; +protected: + typedef typename internal::nested<Derived, 10>::type DerivedNested; + +public: + /** \brief Constructor. * * \param[in] A %Matrix (expression) forming the argument of the matrix logarithm. @@ -323,25 +327,24 @@ public: template <typename ResultType> inline void evalTo(ResultType& result) const { - typedef typename Derived::PlainObject PlainObject; - typedef internal::traits<PlainObject> Traits; + typedef typename internal::remove_all<DerivedNested>::type DerivedNestedClean; + typedef internal::traits<DerivedNestedClean> Traits; static const int RowsAtCompileTime = Traits::RowsAtCompileTime; static const int ColsAtCompileTime = Traits::ColsAtCompileTime; - static const int Options = PlainObject::Options; + static const int Options = DerivedNestedClean::Options; typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar; typedef Matrix<ComplexScalar, Dynamic, Dynamic, Options, RowsAtCompileTime, ColsAtCompileTime> DynMatrixType; typedef internal::MatrixLogarithmAtomic<DynMatrixType> AtomicType; AtomicType atomic; - const PlainObject Aevaluated = m_A.eval(); - internal::matrix_function_compute<PlainObject>::run(Aevaluated, atomic, result); + internal::matrix_function_compute<DerivedNestedClean>::run(m_A, atomic, result); } Index rows() const { return m_A.rows(); } Index cols() const { return m_A.cols(); } private: - typename internal::nested<Derived>::type m_A; + const DerivedNested m_A; }; namespace internal { diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h b/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h index 314b3f38e..8ca4f4864 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixSquareRoot.h @@ -318,7 +318,10 @@ struct matrix_sqrt_compute<MatrixType, 1> template<typename Derived> class MatrixSquareRootReturnValue : public ReturnByValue<MatrixSquareRootReturnValue<Derived> > { + protected: typedef typename Derived::Index Index; + typedef typename internal::nested<Derived, 10>::type DerivedNested; + public: /** \brief Constructor. * @@ -335,16 +338,15 @@ template<typename Derived> class MatrixSquareRootReturnValue template <typename ResultType> inline void evalTo(ResultType& result) const { - typedef typename Derived::PlainObject PlainObject; - const PlainObject srcEvaluated = m_src.eval(); - internal::matrix_sqrt_compute<PlainObject>::run(srcEvaluated, result); + typedef typename internal::remove_all<DerivedNested>::type DerivedNestedClean; + internal::matrix_sqrt_compute<DerivedNestedClean>::run(m_src, result); } Index rows() const { return m_src.rows(); } Index cols() const { return m_src.cols(); } protected: - const Derived& m_src; + const DerivedNested m_src; }; namespace internal { |