diff options
author | Chen-Pang He <jdh8@ms63.hinet.net> | 2011-09-17 21:00:55 +0800 |
---|---|---|
committer | Chen-Pang He <jdh8@ms63.hinet.net> | 2011-09-17 21:00:55 +0800 |
commit | 16b13596a60c8c384a80ccd71b1c63275dc0d92f (patch) | |
tree | d625d24a8772fac2c2e65ec827c5db77908f1ab1 | |
parent | edf4c4b217268c3379bca017afc480d2b8299de9 (diff) |
mainly enhance MatrixLogarithm's performance for RealScalar != double
-rw-r--r-- | unsupported/Eigen/MatrixFunctions | 3 | ||||
-rw-r--r-- | unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h | 12 | ||||
-rw-r--r-- | unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h | 236 |
3 files changed, 209 insertions, 42 deletions
diff --git a/unsupported/Eigen/MatrixFunctions b/unsupported/Eigen/MatrixFunctions index 136b45183..ac58eec29 100644 --- a/unsupported/Eigen/MatrixFunctions +++ b/unsupported/Eigen/MatrixFunctions @@ -226,6 +226,9 @@ documentation of \ref matrixbase_exp "exp()". \include MatrixLogarithm.cpp Output: \verbinclude MatrixLogarithm.out +\note \p M has to be a matrix of \c float, \c double, \c long double +\c complex<float>, \c complex<double>, or \c complex<long double> . + \sa MatrixBase::exp(), MatrixBase::matrixFunction(), class MatrixLogarithmAtomic, MatrixBase::sqrt(). diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h b/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h index c6e77dd37..c9aeb3321 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixExponential.h @@ -212,7 +212,7 @@ void MatrixExponential<MatrixType>::compute(ResultType &result) template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade3(const MatrixType &A) { - const Scalar b[] = {120., 60., 12., 1.}; + const RealScalar b[] = {120., 60., 12., 1.}; m_tmp1.noalias() = A * A; m_tmp2 = b[3]*m_tmp1 + b[1]*m_Id; m_U.noalias() = A * m_tmp2; @@ -222,7 +222,7 @@ EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade3(const MatrixType & template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade5(const MatrixType &A) { - const Scalar b[] = {30240., 15120., 3360., 420., 30., 1.}; + const RealScalar b[] = {30240., 15120., 3360., 420., 30., 1.}; MatrixType A2 = A * A; m_tmp1.noalias() = A2 * A2; m_tmp2 = b[5]*m_tmp1 + b[3]*A2 + b[1]*m_Id; @@ -233,7 +233,7 @@ EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade5(const MatrixType & template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade7(const MatrixType &A) { - const Scalar b[] = {17297280., 8648640., 1995840., 277200., 25200., 1512., 56., 1.}; + const RealScalar b[] = {17297280., 8648640., 1995840., 277200., 25200., 1512., 56., 1.}; MatrixType A2 = A * A; MatrixType A4 = A2 * A2; m_tmp1.noalias() = A4 * A2; @@ -245,7 +245,7 @@ EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade7(const MatrixType & template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade9(const MatrixType &A) { - const Scalar b[] = {17643225600., 8821612800., 2075673600., 302702400., 30270240., + const RealScalar b[] = {17643225600., 8821612800., 2075673600., 302702400., 30270240., 2162160., 110880., 3960., 90., 1.}; MatrixType A2 = A * A; MatrixType A4 = A2 * A2; @@ -259,7 +259,7 @@ EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade9(const MatrixType & template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade13(const MatrixType &A) { - const Scalar b[] = {64764752532480000., 32382376266240000., 7771770303897600., + const RealScalar b[] = {64764752532480000., 32382376266240000., 7771770303897600., 1187353796428800., 129060195264000., 10559470521600., 670442572800., 33522128640., 1323241920., 40840800., 960960., 16380., 182., 1.}; MatrixType A2 = A * A; @@ -278,7 +278,7 @@ EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade13(const MatrixType template <typename MatrixType> EIGEN_STRONG_INLINE void MatrixExponential<MatrixType>::pade17(const MatrixType &A) { - const Scalar b[] = {830034394580628357120000.L, 415017197290314178560000.L, + const RealScalar b[] = {830034394580628357120000.L, 415017197290314178560000.L, 100610229646136770560000.L, 15720348382208870400000.L, 1774878043152614400000.L, 153822763739893248000.L, 10608466464820224000.L, 595373117923584000.L, 27563570274240000.L, 1060137318240000.L, diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h b/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h index 90afb59ff..e575be0ac 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixLogarithm.h @@ -2,6 +2,7 @@ // for linear algebra. // // Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk> +// Copyright (C) 2011 Chen-Pang He <jdh8@ms63.hinet.net> // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -26,7 +27,7 @@ #define EIGEN_MATRIX_LOGARITHM #ifndef M_PI -#define M_PI 3.14159265358979323846264338327950L +#define M_PI 3.141592653589793238462643383279503L #endif /** \ingroup MatrixFunctions_Module @@ -64,26 +65,31 @@ private: void compute2x2(const MatrixType& A, MatrixType& result); void computeBig(const MatrixType& A, MatrixType& result); static Scalar atanh(Scalar x); - int getPadeDegree(typename MatrixType::RealScalar normTminusI); + int getPadeDegree(float normTminusI); + int getPadeDegree(double normTminusI); + int getPadeDegree(long double normTminusI); void computePade(MatrixType& result, const MatrixType& T, int degree); void computePade3(MatrixType& result, const MatrixType& T); void computePade4(MatrixType& result, const MatrixType& T); void computePade5(MatrixType& result, const MatrixType& T); void computePade6(MatrixType& result, const MatrixType& T); void computePade7(MatrixType& result, const MatrixType& T); + void computePade8(MatrixType& result, const MatrixType& T); + void computePade9(MatrixType& result, const MatrixType& T); + void computePade10(MatrixType& result, const MatrixType& T); + void computePade11(MatrixType& result, const MatrixType& T); - static const double maxNormForPade[]; static const int minPadeDegree = 3; - static const int maxPadeDegree = 7; + static const int maxPadeDegree = std::numeric_limits<RealScalar>::digits<= 24? 5: // single precision + std::numeric_limits<RealScalar>::digits<= 53? 7: // double precision + std::numeric_limits<RealScalar>::digits<= 64? 8: // extended precision + std::numeric_limits<RealScalar>::digits<=106? 10: 11; // double-double or quadruple precision // Prevent copying MatrixLogarithmAtomic(const MatrixLogarithmAtomic&); MatrixLogarithmAtomic& operator=(const MatrixLogarithmAtomic&); }; -template <typename MatrixType> -const double MatrixLogarithmAtomic<MatrixType>::maxNormForPade[] = { 0.0162 /* degree = 3 */, 0.0539, 0.114, 0.187, 0.264 }; - /** \brief Compute logarithm of triangular matrix with clustered eigenvalues. */ template <typename MatrixType> MatrixType MatrixLogarithmAtomic<MatrixType>::compute(const MatrixType& A) @@ -148,10 +154,15 @@ void MatrixLogarithmAtomic<MatrixType>::computeBig(const MatrixType& A, MatrixTy int numberOfExtraSquareRoots = 0; int degree; MatrixType T = A; + const RealScalar maxNormForPade = maxPadeDegree<= 5? 5.3149729967117310e-1: // single precision + maxPadeDegree<= 7? 2.6429608311114350e-1: // double precision + maxPadeDegree<= 8? 2.32777776523703892094e-1L: // extended precision + maxPadeDegree<=10? 1.05026503471351080481093652651105e-1L: // double-double + 1.1880960220216759245467951592883642e-1L; // quadruple precision while (true) { RealScalar normTminusI = (T - MatrixType::Identity(T.rows(), T.rows())).cwiseAbs().colwise().sum().maxCoeff(); - if (normTminusI < maxNormForPade[maxPadeDegree - minPadeDegree]) { + if (normTminusI < maxNormForPade) { degree = getPadeDegree(normTminusI); int degree2 = getPadeDegree(normTminusI / RealScalar(2)); if ((degree - degree2 <= 1) || (numberOfExtraSquareRoots == 1)) @@ -168,26 +179,74 @@ void MatrixLogarithmAtomic<MatrixType>::computeBig(const MatrixType& A, MatrixTy result *= pow(RealScalar(2), numberOfSquareRoots); } -/* \brief Get suitable degree for Pade approximation. */ +/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = float) */ template <typename MatrixType> -int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(typename MatrixType::RealScalar normTminusI) +int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(float normTminusI) { + const float maxNormForPade[] = { 2.5111573934555054e-1 /* degree = 3 */ , 4.0535837411880493e-1, + 5.3149729967117310e-1 }; for (int degree = 3; degree <= maxPadeDegree; ++degree) if (normTminusI <= maxNormForPade[degree - minPadeDegree]) return degree; assert(false); // this line should never be reached } +/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = double) */ +template <typename MatrixType> +int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(double normTminusI) +{ + const double maxNormForPade[] = { 1.6206284795015624e-2 /* degree = 3 */ , 5.3873532631381171e-2, + 1.1352802267628681e-1, 1.8662860613541288e-1, 2.642960831111435e-1 }; + for (int degree = 3; degree <= maxPadeDegree; ++degree) + if (normTminusI <= maxNormForPade[degree - minPadeDegree]) + return degree; + assert(false); // this line should never be reached +} + +/* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = long double) */ +template <typename MatrixType> +int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(long double normTminusI) +{ +#if LDBL_MANT_DIG == 53 // double precision + const double maxNormForPade[] = { 1.6206284795015624e-2 /* degree = 3 */ , 5.3873532631381171e-2, + 1.1352802267628681e-1, 1.8662860613541288e-1, 2.642960831111435e-1 }; +#elif LDBL_MANT_DIG <= 64 // extended precision + const double maxNormForPade[] = { 5.48256690357782863103e-3 /* degree = 3 */, 2.34559162387971167321e-2, + 5.84603923897347449857e-2, 1.08486423756725170223e-1, 1.68385767881294446649e-1, + 2.32777776523703892094e-1 }; +#elif LDBL_MANT_DIG <= 106 // double-double + const double maxNormForPade[] = { 8.58970550342939562202529664318890e-5 /* degree = 3 */, + 9.34074328446359654039446552677759e-4, 4.26117194647672175773064114582860e-3, + 1.21546224740281848743149666560464e-2, 2.61100544998339436713088248557444e-2, + 4.66170074627052749243018566390567e-2, 7.32585144444135027565872014932387e-2, + 1.05026503471351080481093652651105e-1 }; +#else // quadruple precision + const double maxNormForPade[] = { 4.7419931187193005048501568167858103e-5 /* degree = 3 */, + 5.8853168473544560470387769480192666e-4, 2.9216120366601315391789493628113520e-3, + 8.8415758124319434347116734705174308e-3, 1.9850836029449446668518049562565291e-2, + 3.6688019729653446926585242192447447e-2, 5.9290962294020186998954055264528393e-2, + 8.6998436081634343903250580992127677e-2, 1.1880960220216759245467951592883642e-1 }; +#endif + for (int degree = 3; degree <= maxPadeDegree; ++degree) + if (normTminusI <= maxNormForPade[degree - minPadeDegree]) + return degree; + assert(false); // this line should never be reached +} + /* \brief Compute Pade approximation to matrix logarithm */ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade(MatrixType& result, const MatrixType& T, int degree) { switch (degree) { - case 3: computePade3(result, T); break; - case 4: computePade4(result, T); break; - case 5: computePade5(result, T); break; - case 6: computePade6(result, T); break; - case 7: computePade7(result, T); break; + case 3: computePade3(result, T); break; + case 4: computePade4(result, T); break; + case 5: computePade5(result, T); break; + case 6: computePade6(result, T); break; + case 7: computePade7(result, T); break; + case 8: computePade8(result, T); break; + case 9: computePade9(result, T); break; + case 10: computePade10(result, T); break; + case 11: computePade11(result, T); break; default: assert(false); // should never happen } } @@ -196,11 +255,14 @@ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade3(MatrixType& result, const MatrixType& T) { const int degree = 3; - double nodes[] = { 0.112701665379258, 0.500000000000000, 0.887298334620742 }; - double weights[] = { 0.277777777777778, 0.444444444444444, 0.277777777777778 }; + const RealScalar nodes[] = { 0.1127016653792583114820734600217600L, 0.5000000000000000000000000000000000L, + 0.8872983346207416885179265399782400L }; + const RealScalar weights[] = { 0.2777777777777777777777777777777778L, 0.4444444444444444444444444444444444L, + 0.2777777777777777777777777777777778L }; + assert(degree <= maxPadeDegree); MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) + for (int k = 0; k < degree; ++k) result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) .template triangularView<Upper>().solve(TminusI); } @@ -209,11 +271,14 @@ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade4(MatrixType& result, const MatrixType& T) { const int degree = 4; - double nodes[] = { 0.069431844202974, 0.330009478207572, 0.669990521792428, 0.930568155797026 }; - double weights[] = { 0.173927422568727, 0.326072577431273, 0.326072577431273, 0.173927422568727 }; + const RealScalar nodes[] = { 0.0694318442029737123880267555535953L, 0.3300094782075718675986671204483777L, + 0.6699905217924281324013328795516223L, 0.9305681557970262876119732444464048L }; + const RealScalar weights[] = { 0.1739274225687269286865319746109997L, 0.3260725774312730713134680253890003L, + 0.3260725774312730713134680253890003L, 0.1739274225687269286865319746109997L }; + assert(degree <= maxPadeDegree); MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) + for (int k = 0; k < degree; ++k) result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) .template triangularView<Upper>().solve(TminusI); } @@ -222,13 +287,16 @@ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade5(MatrixType& result, const MatrixType& T) { const int degree = 5; - double nodes[] = { 0.046910077030668, 0.230765344947158, 0.500000000000000, - 0.769234655052841, 0.953089922969332 }; - double weights[] = { 0.118463442528095, 0.239314335249683, 0.284444444444444, - 0.239314335249683, 0.118463442528094 }; + const RealScalar nodes[] = { 0.0469100770306680036011865608503035L, 0.2307653449471584544818427896498956L, + 0.5000000000000000000000000000000000L, 0.7692346550528415455181572103501044L, + 0.9530899229693319963988134391496965L }; + const RealScalar weights[] = { 0.1184634425280945437571320203599587L, 0.2393143352496832340206457574178191L, + 0.2844444444444444444444444444444444L, 0.2393143352496832340206457574178191L, + 0.1184634425280945437571320203599587L }; + assert(degree <= maxPadeDegree); MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) + for (int k = 0; k < degree; ++k) result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) .template triangularView<Upper>().solve(TminusI); } @@ -237,13 +305,16 @@ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade6(MatrixType& result, const MatrixType& T) { const int degree = 6; - double nodes[] = { 0.033765242898424, 0.169395306766868, 0.380690406958402, - 0.619309593041598, 0.830604693233132, 0.966234757101576 }; - double weights[] = { 0.085662246189585, 0.180380786524069, 0.233956967286345, - 0.233956967286346, 0.180380786524069, 0.085662246189585 }; + const RealScalar nodes[] = { 0.0337652428984239860938492227530027L, 0.1693953067668677431693002024900473L, + 0.3806904069584015456847491391596440L, 0.6193095930415984543152508608403560L, + 0.8306046932331322568306997975099527L, 0.9662347571015760139061507772469973L }; + const RealScalar weights[] = { 0.0856622461895851725201480710863665L, 0.1803807865240693037849167569188581L, + 0.2339569672863455236949351719947755L, 0.2339569672863455236949351719947755L, + 0.1803807865240693037849167569188581L, 0.0856622461895851725201480710863665L }; + assert(degree <= maxPadeDegree); MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) + for (int k = 0; k < degree; ++k) result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) .template triangularView<Upper>().solve(TminusI); } @@ -252,13 +323,106 @@ template <typename MatrixType> void MatrixLogarithmAtomic<MatrixType>::computePade7(MatrixType& result, const MatrixType& T) { const int degree = 7; - double nodes[] = { 0.025446043828621, 0.129234407200303, 0.297077424311301, 0.500000000000000, - 0.702922575688699, 0.870765592799697, 0.974553956171379 }; - double weights[] = { 0.064742483084435, 0.139852695744638, 0.190915025252559, 0.208979591836734, - 0.190915025252560, 0.139852695744638, 0.064742483084435 }; + const RealScalar nodes[] = { 0.0254460438286207377369051579760744L, 0.1292344072003027800680676133596058L, + 0.2970774243113014165466967939615193L, 0.5000000000000000000000000000000000L, + 0.7029225756886985834533032060384807L, 0.8707655927996972199319323866403942L, + 0.9745539561713792622630948420239256L }; + const RealScalar weights[] = { 0.0647424830844348466353057163395410L, 0.1398526957446383339507338857118898L, + 0.1909150252525594724751848877444876L, 0.2089795918367346938775510204081633L, + 0.1909150252525594724751848877444876L, 0.1398526957446383339507338857118898L, + 0.0647424830844348466353057163395410L }; + assert(degree <= maxPadeDegree); + MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); + result.setZero(T.rows(), T.rows()); + for (int k = 0; k < degree; ++k) + result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) + .template triangularView<Upper>().solve(TminusI); +} + +template <typename MatrixType> +void MatrixLogarithmAtomic<MatrixType>::computePade8(MatrixType& result, const MatrixType& T) +{ + const int degree = 8; + const RealScalar nodes[] = { 0.0198550717512318841582195657152635L, 0.1016667612931866302042230317620848L, + 0.2372337950418355070911304754053768L, 0.4082826787521750975302619288199080L, + 0.5917173212478249024697380711800920L, 0.7627662049581644929088695245946232L, + 0.8983332387068133697957769682379152L, 0.9801449282487681158417804342847365L }; + const RealScalar weights[] = { 0.0506142681451881295762656771549811L, 0.1111905172266872352721779972131204L, + 0.1568533229389436436689811009933007L, 0.1813418916891809914825752246385978L, + 0.1813418916891809914825752246385978L, 0.1568533229389436436689811009933007L, + 0.1111905172266872352721779972131204L, 0.0506142681451881295762656771549811L }; + assert(degree <= maxPadeDegree); + MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); + result.setZero(T.rows(), T.rows()); + for (int k = 0; k < degree; ++k) + result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) + .template triangularView<Upper>().solve(TminusI); +} + +template <typename MatrixType> +void MatrixLogarithmAtomic<MatrixType>::computePade9(MatrixType& result, const MatrixType& T) +{ + const int degree = 9; + const RealScalar nodes[] = { 0.0159198802461869550822118985481636L, 0.0819844463366821028502851059651326L, + 0.1933142836497048013456489803292629L, 0.3378732882980955354807309926783317L, + 0.5000000000000000000000000000000000L, 0.6621267117019044645192690073216683L, + 0.8066857163502951986543510196707371L, 0.9180155536633178971497148940348674L, + 0.9840801197538130449177881014518364L }; + const RealScalar weights[] = { 0.0406371941807872059859460790552618L, 0.0903240803474287020292360156214564L, + 0.1303053482014677311593714347093164L, 0.1561735385200014200343152032922218L, + 0.1651196775006298815822625346434870L, 0.1561735385200014200343152032922218L, + 0.1303053482014677311593714347093164L, 0.0903240803474287020292360156214564L, + 0.0406371941807872059859460790552618L }; + assert(degree <= maxPadeDegree); + MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); + result.setZero(T.rows(), T.rows()); + for (int k = 0; k < degree; ++k) + result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) + .template triangularView<Upper>().solve(TminusI); +} + +template <typename MatrixType> +void MatrixLogarithmAtomic<MatrixType>::computePade10(MatrixType& result, const MatrixType& T) +{ + const int degree = 10; + const RealScalar nodes[] = { 0.0130467357414141399610179939577740L, 0.0674683166555077446339516557882535L, + 0.1602952158504877968828363174425632L, 0.2833023029353764046003670284171079L, + 0.4255628305091843945575869994351400L, 0.5744371694908156054424130005648600L, + 0.7166976970646235953996329715828921L, 0.8397047841495122031171636825574368L, + 0.9325316833444922553660483442117465L, 0.9869532642585858600389820060422260L }; + const RealScalar weights[] = { 0.0333356721543440687967844049466659L, 0.0747256745752902965728881698288487L, + 0.1095431812579910219977674671140816L, 0.1346333596549981775456134607847347L, + 0.1477621123573764350869464973256692L, 0.1477621123573764350869464973256692L, + 0.1346333596549981775456134607847347L, 0.1095431812579910219977674671140816L, + 0.0747256745752902965728881698288487L, 0.0333356721543440687967844049466659L }; + assert(degree <= maxPadeDegree); + MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); + result.setZero(T.rows(), T.rows()); + for (int k = 0; k < degree; ++k) + result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) + .template triangularView<Upper>().solve(TminusI); +} + +template <typename MatrixType> +void MatrixLogarithmAtomic<MatrixType>::computePade11(MatrixType& result, const MatrixType& T) +{ + const int degree = 11; + const RealScalar nodes[] = { 0.0108856709269715035980309994385713L, 0.0564687001159523504624211153480364L, + 0.1349239972129753379532918739844233L, 0.2404519353965940920371371652706952L, + 0.3652284220238275138342340072995692L, 0.5000000000000000000000000000000000L, + 0.6347715779761724861657659927004308L, 0.7595480646034059079628628347293048L, + 0.8650760027870246620467081260155767L, 0.9435312998840476495375788846519636L, + 0.9891143290730284964019690005614287L }; + const RealScalar weights[] = { 0.0278342835580868332413768602212743L, 0.0627901847324523123173471496119701L, + 0.0931451054638671257130488207158280L, 0.1165968822959952399592618524215876L, + 0.1314022722551233310903444349452546L, 0.1364625433889503153572417641681711L, + 0.1314022722551233310903444349452546L, 0.1165968822959952399592618524215876L, + 0.0931451054638671257130488207158280L, 0.0627901847324523123173471496119701L, + 0.0278342835580868332413768602212743L }; + assert(degree <= maxPadeDegree); MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows()); result.setZero(T.rows(), T.rows()); - for (int k = 0; k < degree; ++k) + for (int k = 0; k < degree; ++k) result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI) .template triangularView<Upper>().solve(TminusI); } |