aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported
diff options
context:
space:
mode:
authorGravatar Chen-Pang He <jdh8@ms63.hinet.net>2012-09-23 23:49:50 +0800
committerGravatar Chen-Pang He <jdh8@ms63.hinet.net>2012-09-23 23:49:50 +0800
commit334532b7f56728e425dca64007ff7a3b6857d79f (patch)
treee3b6b7d5de6dda9cd61b393fee35251b0fca5765 /unsupported
parent1d402dac039e665f5704dd43a8c0025c383e4bf1 (diff)
Remove class MatrixPowerEvaluator with enhanced existing MatrixPowerReturnValue to simplicity, but docs are not completed yet.
Diffstat (limited to 'unsupported')
-rw-r--r--unsupported/Eigen/src/MatrixFunctions/MatrixPower.h61
1 files changed, 15 insertions, 46 deletions
diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h b/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h
index 0d00cf76e..15ede1c2a 100644
--- a/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h
+++ b/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h
@@ -12,9 +12,6 @@
namespace Eigen {
-template<typename MatrixType>
-class MatrixPowerEvaluator;
-
/**
* \ingroup MatrixFunctions_Module
*
@@ -91,8 +88,8 @@ template<typename MatrixType> class MatrixPower
*
* \param[in] p exponent, a real scalar.
*/
- const MatrixPowerEvaluator<MatrixType> operator()(RealScalar p)
- { return MatrixPowerEvaluator<MatrixType>(*this, p); }
+ const MatrixPowerReturnValue<MatrixType> operator()(RealScalar p)
+ { return MatrixPowerReturnValue<MatrixType>(*this, p); }
/**
* \brief Compute the matrix power.
@@ -333,7 +330,13 @@ class MatrixPowerReturnValue : public ReturnByValue<MatrixPowerReturnValue<Deriv
* \param[in] p scalar, the exponent of the matrix power.
*/
MatrixPowerReturnValue(const Derived& A, RealScalar p)
- : m_A(A), m_p(p) { }
+ : m_pow(new MatrixPower<PlainObject>(A)), m_p(p), m_del(true) { }
+
+ MatrixPowerReturnValue(MatrixPower<PlainObject>& pow, RealScalar p)
+ : m_pow(&pow), m_p(p), m_del(false) { }
+
+ ~MatrixPowerReturnValue()
+ { if (m_del) delete m_pow; }
/**
* \brief Compute the matrix power.
@@ -343,52 +346,22 @@ class MatrixPowerReturnValue : public ReturnByValue<MatrixPowerReturnValue<Deriv
*/
template<typename ResultType>
inline void evalTo(ResultType& res) const
- { MatrixPower<PlainObject>(m_A).compute(res, m_p); }
+ { m_pow->compute(res, m_p); }
template<typename OtherDerived>
const MatrixPowerMatrixProduct<PlainObject,OtherDerived> operator*(const MatrixBase<OtherDerived>& b) const
- {
- MatrixPower<PlainObject> Apow(m_A);
- return MatrixPowerMatrixProduct<PlainObject,OtherDerived>(Apow, b.derived(), m_p);
- }
+ { return MatrixPowerMatrixProduct<PlainObject,OtherDerived>(*m_pow, b.derived(), m_p); }
- Index rows() const { return m_A.rows(); }
- Index cols() const { return m_A.cols(); }
+ Index rows() const { return m_pow->rows(); }
+ Index cols() const { return m_pow->cols(); }
private:
- const Derived& m_A;
+ MatrixPower<PlainObject>* m_pow;
const RealScalar m_p;
+ const bool m_del; // whether to delete the pointer at destruction
MatrixPowerReturnValue& operator=(const MatrixPowerReturnValue&);
};
-template<typename MatrixType>
-class MatrixPowerEvaluator
-: public ReturnByValue<MatrixPowerEvaluator<MatrixType> >
-{
- public:
- typedef typename MatrixType::RealScalar RealScalar;
- typedef typename MatrixType::Index Index;
-
- MatrixPowerEvaluator(MatrixPower<MatrixType>& ref, RealScalar p)
- : m_pow(ref), m_p(p) { }
-
- template<typename ResultType>
- inline void evalTo(ResultType& res) const
- { m_pow.compute(res, m_p); }
-
- template<typename Derived>
- const MatrixPowerMatrixProduct<MatrixType, Derived> operator*(const MatrixBase<Derived>& b) const
- { return MatrixPowerMatrixProduct<MatrixType, Derived>(m_pow, b.derived(), m_p); }
-
- Index rows() const { return m_pow.rows(); }
- Index cols() const { return m_pow.cols(); }
-
- private:
- MatrixPower<MatrixType>& m_pow;
- const RealScalar m_p;
- MatrixPowerEvaluator& operator=(const MatrixPowerEvaluator&);
-};
-
namespace internal {
template<typename MatrixType, typename Derived>
struct nested<MatrixPowerMatrixProduct<MatrixType,Derived> >
@@ -398,10 +371,6 @@ template<typename Derived>
struct traits<MatrixPowerReturnValue<Derived> >
{ typedef typename Derived::PlainObject ReturnType; };
-template<typename MatrixType>
-struct traits<MatrixPowerEvaluator<MatrixType> >
-{ typedef MatrixType ReturnType; };
-
template<typename Lhs, typename Rhs>
struct traits<MatrixPowerMatrixProduct<Lhs,Rhs> >
: traits<MatrixPowerProductBase<MatrixPowerMatrixProduct<Lhs,Rhs>,Lhs,Rhs> >