Go to the documentation of this file.
10 #ifndef EIGEN_MATRIX_POWER
11 #define EIGEN_MATRIX_POWER
38 template<
typename MatrixType>
58 template<
typename ResultType>
85 template<
typename MatrixType>
133 template<
typename MatrixType>
141 template<
typename MatrixType>
145 switch (m_A.rows()) {
149 res(0,0) =
pow(m_A(0,0), m_p);
152 compute2x2(
res, m_p);
159 template<
typename MatrixType>
166 res = (MatrixType::Identity(IminusT.rows(), IminusT.cols()) +
res).
template triangularView<Upper>()
169 res += MatrixType::Identity(IminusT.rows(), IminusT.cols());
173 template<
typename MatrixType>
178 res.coeffRef(0,0) =
pow(m_A.coeff(0,0),
p);
180 for (
Index i=1;
i < m_A.cols(); ++
i) {
182 if (m_A.coeff(
i-1,
i-1) == m_A.coeff(
i,
i))
184 else if (2*
abs(m_A.coeff(
i-1,
i-1)) <
abs(m_A.coeff(
i,
i)) || 2*
abs(m_A.coeff(
i,
i)) <
abs(m_A.coeff(
i-1,
i-1)))
185 res.coeffRef(
i-1,
i) = (
res.coeff(
i,
i)-
res.coeff(
i-1,
i-1)) / (m_A.coeff(
i,
i)-m_A.coeff(
i-1,
i-1));
187 res.coeffRef(
i-1,
i) = computeSuperDiag(m_A.coeff(
i,
i), m_A.coeff(
i-1,
i-1),
p);
188 res.coeffRef(
i-1,
i) *= m_A.coeff(
i-1,
i);
192 template<
typename MatrixType>
196 const int digits = std::numeric_limits<RealScalar>::digits;
198 digits <= 24? 4.3386528
e-1
L
199 : digits <= 53? 2.789358995219730
e-1
L
200 : digits <= 64? 2.4471944416607995472
e-1
L
201 : digits <= 106? 1.1016843812851143391275867258512
e-1
L
202 : 9.134603732914548552537150753385375
e-2
L);
203 MatrixType IminusT, sqrtT,
T = m_A.template triangularView<Upper>();
205 int degree, degree2, numberOfSquareRoots = 0;
206 bool hasExtraSquareRoot =
false;
208 for (
Index i=0;
i < m_A.cols(); ++
i)
212 IminusT = MatrixType::Identity(m_A.rows(), m_A.cols()) -
T;
213 normIminusT = IminusT.cwiseAbs().colwise().sum().maxCoeff();
214 if (normIminusT < maxNormForPade) {
215 degree = getPadeDegree(normIminusT);
216 degree2 = getPadeDegree(normIminusT/2);
217 if (
degree - degree2 <= 1 || hasExtraSquareRoot)
219 hasExtraSquareRoot =
true;
222 T = sqrtT.template triangularView<Upper>();
223 ++numberOfSquareRoots;
227 for (; numberOfSquareRoots; --numberOfSquareRoots) {
228 compute2x2(
res, ldexp(m_p, -numberOfSquareRoots));
229 res =
res.template triangularView<Upper>() *
res;
231 compute2x2(
res, m_p);
234 template<
typename MatrixType>
237 const float maxNormForPade[] = { 2.8064004e-1
f , 4.3386528e-1
f };
240 if (normIminusT <= maxNormForPade[
degree - 3])
245 template<
typename MatrixType>
248 const double maxNormForPade[] = { 1.884160592658218e-2 , 6.038881904059573e-2, 1.239917516308172e-1,
249 1.999045567181744e-1, 2.789358995219730e-1 };
252 if (normIminusT <= maxNormForPade[
degree - 3])
257 template<
typename MatrixType>
260 #if LDBL_MANT_DIG == 53
261 const int maxPadeDegree = 7;
262 const double maxNormForPade[] = { 1.884160592658218e-2
L , 6.038881904059573e-2
L, 1.239917516308172e-1
L,
263 1.999045567181744e-1
L, 2.789358995219730e-1
L };
264 #elif LDBL_MANT_DIG <= 64
265 const int maxPadeDegree = 8;
266 const long double maxNormForPade[] = { 6.3854693117491799460e-3
L , 2.6394893435456973676e-2
L,
267 6.4216043030404063729e-2
L, 1.1701165502926694307e-1
L, 1.7904284231268670284e-1
L, 2.4471944416607995472e-1
L };
268 #elif LDBL_MANT_DIG <= 106
269 const int maxPadeDegree = 10;
270 const double maxNormForPade[] = { 1.0007161601787493236741409687186e-4
L ,
271 1.0007161601787493236741409687186e-3
L, 4.7069769360887572939882574746264e-3
L, 1.3220386624169159689406653101695e-2
L,
272 2.8063482381631737920612944054906e-2
L, 4.9625993951953473052385361085058e-2
L, 7.7367040706027886224557538328171e-2
L,
273 1.1016843812851143391275867258512e-1
L };
275 const int maxPadeDegree = 10;
276 const double maxNormForPade[] = { 5.524506147036624377378713555116378e-5
L ,
277 6.640600568157479679823602193345995e-4
L, 3.227716520106894279249709728084626e-3
L,
278 9.619593944683432960546978734646284e-3
L, 2.134595382433742403911124458161147e-2
L,
279 3.908166513900489428442993794761185e-2
L, 6.266780814639442865832535460550138e-2
L,
280 9.134603732914548552537150753385375e-2
L };
284 if (normIminusT <= maxNormForPade[
degree - 3])
289 template<
typename MatrixType>
305 template<
typename MatrixType>
314 return 2 *
exp(
p * (
log(curr) +
log(prev)) / 2) *
sinh(
p *
w) / (curr - prev);
336 template<
typename MatrixType>
376 template<
typename ResultType>
385 MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime>
ComplexMatrix;
388 typename MatrixType::Nested
m_A;
427 template<
typename ResultType>
430 template<
typename ResultType>
433 template<
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
439 template<
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
446 template<
typename MatrixType>
447 template<
typename ResultType>
455 res(0,0) =
pow(m_A.coeff(0,0),
p);
462 computeIntPower(
res, intpart);
463 if (
p) computeFracPower(
res,
p);
467 template<
typename MatrixType>
478 if (!m_conditionNumber &&
p)
488 template<
typename MatrixType>
495 m_fT.resizeLike(m_A);
498 m_conditionNumber = m_T.diagonal().array().abs().maxCoeff() / m_T.diagonal().array().abs().minCoeff();
506 eigenvalue = m_T.coeff(
j,
j);
507 rot.makeGivens(m_T.coeff(
j-1,
j), eigenvalue);
508 m_T.applyOnTheRight(
j-1,
j,
rot);
509 m_T.applyOnTheLeft(
j-1,
j,
rot.adjoint());
510 m_T.coeffRef(
j-1,
j-1) = eigenvalue;
512 m_U.applyOnTheRight(
j-1,
j,
rot);
518 m_nulls =
rows() - m_rank;
520 eigen_assert(m_T.bottomRightCorner(m_nulls, m_nulls).isZero()
521 &&
"Base of matrix power should be invertible or with a semisimple zero eigenvalue.");
526 template<
typename MatrixType>
527 template<
typename ResultType>
535 m_tmp = m_A.inverse();
540 if (
fmod(pp, 2) >= 1)
549 template<
typename MatrixType>
550 template<
typename ResultType>
559 m_fT.topRightCorner(m_rank, m_nulls) = m_T.topLeftCorner(m_rank, m_rank).template triangularView<Upper>()
560 .solve(blockTp * m_T.topRightCorner(m_rank, m_nulls));
562 revertSchur(m_tmp, m_fT, m_U);
566 template<
typename MatrixType>
567 template<
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
572 {
res.noalias() =
U * (
T.template triangularView<Upper>() *
U.adjoint()); }
574 template<
typename MatrixType>
575 template<
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
580 {
res.noalias() = (
U * (
T.template triangularView<Upper>() *
U.adjoint())).real(); }
595 template<
typename Derived>
617 template<
typename ResultType>
642 template<
typename Derived>
667 template<
typename ResultType>
681 template<
typename MatrixPowerType>
683 {
typedef typename MatrixPowerType::PlainObject
ReturnType; };
685 template<
typename Derived>
689 template<
typename Derived>
695 template<
typename Derived>
699 template<
typename Derived>
701 {
return MatrixComplexPowerReturnValue<Derived>(derived(),
p); }
705 #endif // EIGEN_MATRIX_POWER
Namespace containing all symbols from the Eigen library.
MatrixPowerParenthesesReturnValue(MatrixPower< MatrixType > &pow, RealScalar p)
Constructor.
Derived::PlainObject PlainObject
Expression of a fixed-size or dynamic-size block.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Block< MatrixType, Dynamic, Dynamic > ResultType
Proxy for the matrix power of some matrix (expression).
MatrixComplexPowerReturnValue(const Derived &A, const ComplexScalar &p)
Constructor.
void computeFracPower(ResultType &res, RealScalar p)
ComplexMatrix m_T
Store the result of Schur decomposition.
void initialize()
Perform Schur decomposition for fractional power.
void compute(ResultType &res, RealScalar p)
Compute the matrix power.
Eigen::Triplet< double > T
std::complex< RealScalar > ComplexScalar
const EIGEN_DEVICE_FUNC LogReturnType log() const
cout<< "Here is a random 4x4 matrix, A:"<< endl<< A<< endl<< endl;ComplexSchur< MatrixXcf > schurOfA(A, false)
Derived::PlainObject ReturnType
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
std::complex< RealScalar > ComplexScalar
Rotation given by a cosine-sine pair.
void computeIntPower(ResultType &res, RealScalar p)
const MatrixPowerParenthesesReturnValue< MatrixType > operator()(RealScalar p)
Returns the matrix power.
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
MatrixType::RealScalar RealScalar
Derived::PlainObject PlainObject
MatrixPowerAtomic(const MatrixType &T, RealScalar p)
Constructor.
void evalTo(ResultType &result) const
Compute the matrix power.
Class for computing matrix powers.
MatrixType::Scalar Scalar
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
void evalTo(ResultType &result) const
Compute the matrix power.
static int getPadeDegree(float normIminusT)
MatrixPowerType::PlainObject ReturnType
Derived::PlainObject ReturnType
Matrix< ComplexScalar, Dynamic, Dynamic, 0, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime > ComplexMatrix
static ComplexScalar computeSuperDiag(const ComplexScalar &, const ComplexScalar &, RealScalar p)
static void revertSchur(Matrix< ComplexScalar, Rows, Cols, Options, MaxRows, MaxCols > &res, const ComplexMatrix &T, const ComplexMatrix &U)
MatrixType::Scalar Scalar
Class for computing matrix powers.
const EIGEN_DEVICE_FUNC ImagReturnType imag() const
Proxy for the matrix power of some matrix (expression).
void matrix_sqrt_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of triangular matrix.
Jet< T, N > pow(const Jet< T, N > &f, double g)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
NumTraits< Scalar >::Real RealScalar
MatrixPowerReturnValue(const Derived &A, RealScalar p)
Constructor.
MatrixPower< MatrixType > & m_pow
void evalTo(ResultType &result) const
Compute the matrix power.
MatrixType::Nested m_A
Reference to the base of matrix power.
void split(const G &g, const PredecessorMap< KEY > &tree, G &Ab1, G &Ab2)
const EIGEN_DEVICE_FUNC CeilReturnType ceil() const
ComplexMatrix m_fT
Store fractional power of m_T.
void split(RealScalar &p, RealScalar &intpart)
Split p into integral part and fractional part.
Derived::RealScalar RealScalar
The matrix class, also used for vectors and row-vectors.
MatrixPower(const MatrixType &A)
Constructor.
void compute(ResultType &res) const
Compute the matrix power.
MatrixType::RealScalar RealScalar
MatrixType::RealScalar RealScalar
std::complex< typename Derived::RealScalar > ComplexScalar
void compute2x2(ResultType &res, RealScalar p) const
const EIGEN_DEVICE_FUNC SinhReturnType sinh() const
void computePade(int degree, const MatrixType &IminusT, ResultType &res) const
Index m_nulls
Rank deficiency of m_A.
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Values initialize(const NonlinearFactorGraph &graph, bool useOdometricPath)
MatrixType m_tmp
Temporary storage.
RealScalar m_conditionNumber
Condition number of m_A.
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
void computeBig(ResultType &res) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Proxy for the matrix power of some matrix.
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:09