11 #ifndef EIGEN_MATRIX_EXPONENTIAL
12 #define EIGEN_MATRIX_EXPONENTIAL
25 template <
typename RealScalar>
26 struct MatrixExponentialScalingOp
32 MatrixExponentialScalingOp(
int squarings) : m_squarings(squarings) { }
39 inline const RealScalar operator() (
const RealScalar&
x)
const
42 return ldexp(
x, -m_squarings);
45 typedef std::complex<RealScalar> ComplexScalar;
51 inline const ComplexScalar operator() (
const ComplexScalar&
x)
const
54 return ComplexScalar(ldexp(
x.real(), -m_squarings), ldexp(
x.imag(), -m_squarings));
66 template <
typename MatA,
typename MatU,
typename MatV>
71 const RealScalar
b[] = {120.L, 60.L, 12.L, 1.L};
74 U.noalias() =
A * tmp;
75 V =
b[2] * A2 +
b[0] * MatrixType::Identity(
A.
rows(),
A.
cols());
83 template <
typename MatA,
typename MatU,
typename MatV>
88 const RealScalar
b[] = {30240.L, 15120.L, 3360.L, 420.L, 30.L, 1.L};
92 U.noalias() =
A * tmp;
93 V =
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(
A.
rows(),
A.
cols());
101 template <
typename MatA,
typename MatU,
typename MatV>
104 typedef typename MatA::PlainObject
MatrixType;
106 const RealScalar
b[] = {17297280.L, 8648640.L, 1995840.L, 277200.L, 25200.L, 1512.L, 56.L, 1.L};
112 U.noalias() =
A * tmp;
113 V =
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(
A.
rows(),
A.
cols());
122 template <
typename MatA,
typename MatU,
typename MatV>
125 typedef typename MatA::PlainObject
MatrixType;
127 const RealScalar
b[] = {17643225600.L, 8821612800.L, 2075673600.L, 302702400.L, 30270240.L,
128 2162160.L, 110880.L, 3960.L, 90.L, 1.L};
133 const MatrixType tmp =
b[9] * A8 +
b[7] * A6 +
b[5] * A4 +
b[3] * A2
135 U.noalias() =
A * tmp;
136 V =
b[8] * A8 +
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(
A.
rows(),
A.
cols());
144 template <
typename MatA,
typename MatU,
typename MatV>
147 typedef typename MatA::PlainObject
MatrixType;
149 const RealScalar
b[] = {64764752532480000.L, 32382376266240000.L, 7771770303897600.L,
150 1187353796428800.L, 129060195264000.L, 10559470521600.L, 670442572800.L,
151 33522128640.L, 1323241920.L, 40840800.L, 960960.L, 16380.L, 182.L, 1.L};
155 V =
b[13] * A6 +
b[11] * A4 +
b[9] * A2;
157 tmp +=
b[7] * A6 +
b[5] * A4 +
b[3] * A2 +
b[1] * MatrixType::Identity(
A.
rows(),
A.
cols());
158 U.noalias() =
A * tmp;
159 tmp =
b[12] * A6 +
b[10] * A4 +
b[8] * A2;
160 V.noalias() = A6 * tmp;
161 V +=
b[6] * A6 +
b[4] * A4 +
b[2] * A2 +
b[0] * MatrixType::Identity(
A.
rows(),
A.
cols());
171 #if LDBL_MANT_DIG > 64
172 template <
typename MatA,
typename MatU,
typename MatV>
173 void matrix_exp_pade17(
const MatA& A, MatU& U, MatV& V)
175 typedef typename MatA::PlainObject
MatrixType;
177 const RealScalar
b[] = {830034394580628357120000.L, 415017197290314178560000.L,
178 100610229646136770560000.L, 15720348382208870400000.L,
179 1774878043152614400000.L, 153822763739893248000.L, 10608466464820224000.L,
180 595373117923584000.L, 27563570274240000.L, 1060137318240000.L,
181 33924394183680.L, 899510451840.L, 19554575040.L, 341863200.L, 4651200.L,
182 46512.L, 306.L, 1.L};
187 V =
b[17] * A8 +
b[15] * A6 +
b[13] * A4 +
b[11] * A2;
189 tmp +=
b[9] * A8 +
b[7] * A6 +
b[5] * A4 +
b[3] * A2
191 U.noalias() =
A * tmp;
192 tmp =
b[16] * A8 +
b[14] * A6 +
b[12] * A4 +
b[10] * A2;
193 V.noalias() = tmp * A8;
194 V +=
b[8] * A8 +
b[6] * A6 +
b[4] * A4 +
b[2] * A2
199 template <typename MatrixType, typename RealScalar = typename NumTraits<typename traits<MatrixType>::Scalar>::Real>
200 struct matrix_exp_computeUV
212 template <
typename MatrixType>
213 struct matrix_exp_computeUV<
MatrixType, float>
215 template <
typename ArgType>
220 const float l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
222 if (l1norm < 4.258730016922831e-001f) {
224 }
else if (l1norm < 1.880152677804762e+000f) {
227 const float maxnorm = 3.925724783138660f;
228 frexp(l1norm / maxnorm, &squarings);
229 if (squarings < 0) squarings = 0;
230 MatrixType A =
arg.unaryExpr(MatrixExponentialScalingOp<float>(squarings));
236 template <
typename MatrixType>
237 struct matrix_exp_computeUV<
MatrixType, double>
239 typedef typename NumTraits<typename traits<MatrixType>::Scalar>::Real RealScalar;
240 template <
typename ArgType>
245 const RealScalar l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
247 if (l1norm < 1.495585217958292e-002) {
249 }
else if (l1norm < 2.539398330063230e-001) {
251 }
else if (l1norm < 9.504178996162932e-001) {
253 }
else if (l1norm < 2.097847961257068e+000) {
256 const RealScalar maxnorm = 5.371920351148152;
257 frexp(l1norm / maxnorm, &squarings);
258 if (squarings < 0) squarings = 0;
259 MatrixType A =
arg.unaryExpr(MatrixExponentialScalingOp<RealScalar>(squarings));
265 template <
typename MatrixType>
266 struct matrix_exp_computeUV<
MatrixType, long double>
268 template <
typename ArgType>
271 #if LDBL_MANT_DIG == 53
272 matrix_exp_computeUV<MatrixType, double>::run(
arg, U, V, squarings);
278 const long double l1norm =
arg.cwiseAbs().colwise().sum().maxCoeff();
281 #if LDBL_MANT_DIG <= 64
283 if (l1norm < 4.1968497232266989671e-003L) {
285 }
else if (l1norm < 1.1848116734693823091e-001L) {
287 }
else if (l1norm < 5.5170388480686700274e-001L) {
289 }
else if (l1norm < 1.3759868875587845383e+000L) {
292 const long double maxnorm = 4.0246098906697353063L;
293 frexp(l1norm / maxnorm, &squarings);
294 if (squarings < 0) squarings = 0;
295 MatrixType A =
arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings));
299 #elif LDBL_MANT_DIG <= 106
301 if (l1norm < 3.2787892205607026992947488108213e-005L) {
303 }
else if (l1norm < 6.4467025060072760084130906076332e-003L) {
305 }
else if (l1norm < 6.8988028496595374751374122881143e-002L) {
307 }
else if (l1norm < 2.7339737518502231741495857201670e-001L) {
309 }
else if (l1norm < 1.3203382096514474905666448850278e+000L) {
312 const long double maxnorm = 3.2579440895405400856599663723517L;
313 frexp(l1norm / maxnorm, &squarings);
314 if (squarings < 0) squarings = 0;
315 MatrixType A =
arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings));
316 matrix_exp_pade17(A, U, V);
319 #elif LDBL_MANT_DIG <= 113
321 if (l1norm < 1.639394610288918690547467954466970e-005L) {
323 }
else if (l1norm < 4.253237712165275566025884344433009e-003L) {
325 }
else if (l1norm < 5.125804063165764409885122032933142e-002L) {
327 }
else if (l1norm < 2.170000765161155195453205651889853e-001L) {
329 }
else if (l1norm < 1.125358383453143065081397882891878e+000L) {
332 const long double maxnorm = 2.884233277829519311757165057717815L;
333 frexp(l1norm / maxnorm, &squarings);
334 if (squarings < 0) squarings = 0;
335 MatrixType A =
arg.unaryExpr(MatrixExponentialScalingOp<long double>(squarings));
336 matrix_exp_pade17(A, U, V);
349 template<
typename T>
struct is_exp_known_type :
false_type {};
350 template<>
struct is_exp_known_type<float> :
true_type {};
351 template<>
struct is_exp_known_type<double> :
true_type {};
352 #if LDBL_MANT_DIG <= 113
353 template<>
struct is_exp_known_type<long double> :
true_type {};
356 template <
typename ArgType,
typename ResultType>
359 typedef typename ArgType::PlainObject
MatrixType;
362 matrix_exp_computeUV<MatrixType>::run(
arg, U,
V, squarings);
365 result = denom.partialPivLu().solve(numer);
366 for (
int i=0;
i<squarings;
i++)
376 template <
typename ArgType,
typename ResultType>
379 typedef typename ArgType::PlainObject
MatrixType;
382 typedef typename std::complex<RealScalar> ComplexScalar;
383 result =
arg.matrixFunction(internal::stem_function_exp<ComplexScalar>);
398 template<
typename Derived>
struct MatrixExponentialReturnValue
399 :
public ReturnByValue<MatrixExponentialReturnValue<Derived> >
406 MatrixExponentialReturnValue(
const Derived& src) : m_src(src) { }
412 template <
typename ResultType>
413 inline void evalTo(ResultType& result)
const
415 const typename internal::nested_eval<Derived, 10>::type tmp(m_src);
419 Index rows()
const {
return m_src.rows(); }
420 Index cols()
const {
return m_src.cols(); }
423 const typename internal::ref_selector<Derived>::type m_src;
427 template<
typename Derived>
428 struct traits<MatrixExponentialReturnValue<Derived> >
430 typedef typename Derived::PlainObject ReturnType;
434 template <
typename Derived>
438 return MatrixExponentialReturnValue<Derived>(derived());
SparseMatrix< double > A(n, n)
Matrix< float, 1, Dynamic > MatrixType
const MatrixExponentialReturnValue< Derived > exp() const
void matrix_exp_pade7(const MatA &A, MatU &U, MatV &V)
Compute the (7,7)-Padé approximant to the exponential.
void matrix_exp_pade9(const MatA &A, MatU &U, MatV &V)
Compute the (9,9)-Padé approximant to the exponential.
void matrix_exp_compute(const ArgType &arg, ResultType &result, true_type)
void matrix_exp_pade3(const MatA &A, MatU &U, MatV &V)
Compute the (3,3)-Padé approximant to the exponential.
void matrix_exp_pade13(const MatA &A, MatU &U, MatV &V)
Compute the (13,13)-Padé approximant to the exponential.
void matrix_exp_pade5(const MatA &A, MatU &U, MatV &V)
Compute the (5,5)-Padé approximant to the exponential.
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< DerType >, typename internal::traits< internal::remove_all_t< DerType >>::Scalar, product) > pow(const Eigen::AutoDiffScalar< DerType > &x, const typename internal::traits< internal::remove_all_t< DerType >>::Scalar &y)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_arg_op< typename Derived::Scalar >, const Derived > arg(const Eigen::ArrayBase< Derived > &x)