11 #ifndef EIGEN_MATRIX_LOGARITHM
12 #define EIGEN_MATRIX_LOGARITHM
21 template <
typename Scalar>
26 template <
typename Scalar>
29 static const int value = std::numeric_limits<RealScalar>::digits <= 24 ? 5 :
30 std::numeric_limits<RealScalar>::digits <= 53 ? 7
32 std::numeric_limits<RealScalar>::digits <= 64 ? 8
34 std::numeric_limits<RealScalar>::digits <= 106 ? 10
40 template <
typename MatrixType>
52 result(0, 0) = logA00;
54 result(1, 1) = logA11;
58 result(0, 1) =
A(0, 1) /
A(0, 0);
60 result(0, 1) =
A(0, 1) * (logA11 - logA00) /
y;
70 const float maxNormForPade[] = {2.5111573934555054e-1 , 4.0535837411880493e-1, 5.3149729967117310e-1};
73 int degree = minPadeDegree;
75 if (normTminusI <= maxNormForPade[
degree - minPadeDegree])
break;
81 const double maxNormForPade[] = {1.6206284795015624e-2 , 5.3873532631381171e-2, 1.1352802267628681e-1,
82 1.8662860613541288e-1, 2.642960831111435e-1};
85 int degree = minPadeDegree;
87 if (normTminusI <= maxNormForPade[
degree - minPadeDegree])
break;
93 #if LDBL_MANT_DIG == 53
94 const long double maxNormForPade[] = {1.6206284795015624e-2L , 5.3873532631381171e-2L,
95 1.1352802267628681e-1L, 1.8662860613541288e-1L, 2.642960831111435e-1L};
96 #elif LDBL_MANT_DIG <= 64
97 const long double maxNormForPade[] = {5.48256690357782863103e-3L ,
98 2.34559162387971167321e-2L,
99 5.84603923897347449857e-2L,
100 1.08486423756725170223e-1L,
101 1.68385767881294446649e-1L,
102 2.32777776523703892094e-1L};
103 #elif LDBL_MANT_DIG <= 106
104 const long double maxNormForPade[] = {8.58970550342939562202529664318890e-5L ,
105 9.34074328446359654039446552677759e-4L,
106 4.26117194647672175773064114582860e-3L,
107 1.21546224740281848743149666560464e-2L,
108 2.61100544998339436713088248557444e-2L,
109 4.66170074627052749243018566390567e-2L,
110 7.32585144444135027565872014932387e-2L,
111 1.05026503471351080481093652651105e-1L};
113 const long double maxNormForPade[] = {4.7419931187193005048501568167858103e-5L ,
114 5.8853168473544560470387769480192666e-4L,
115 2.9216120366601315391789493628113520e-3L,
116 8.8415758124319434347116734705174308e-3L,
117 1.9850836029449446668518049562565291e-2L,
118 3.6688019729653446926585242192447447e-2L,
119 5.9290962294020186998954055264528393e-2L,
120 8.6998436081634343903250580992127677e-2L,
121 1.1880960220216759245467951592883642e-1L};
125 int degree = minPadeDegree;
127 if (normTminusI <= maxNormForPade[
degree - minPadeDegree])
break;
132 template <
typename MatrixType>
135 const int minPadeDegree = 3;
136 const int maxPadeDegree = 11;
141 {0.1127016653792583114820734600217600L, 0.5000000000000000000000000000000000L,
142 0.8872983346207416885179265399782400L},
143 {0.0694318442029737123880267555535953L, 0.3300094782075718675986671204483777L,
144 0.6699905217924281324013328795516223L, 0.9305681557970262876119732444464048L},
145 {0.0469100770306680036011865608503035L, 0.2307653449471584544818427896498956L,
146 0.5000000000000000000000000000000000L, 0.7692346550528415455181572103501044L,
147 0.9530899229693319963988134391496965L},
148 {0.0337652428984239860938492227530027L, 0.1693953067668677431693002024900473L,
149 0.3806904069584015456847491391596440L, 0.6193095930415984543152508608403560L,
150 0.8306046932331322568306997975099527L, 0.9662347571015760139061507772469973L},
151 {0.0254460438286207377369051579760744L, 0.1292344072003027800680676133596058L,
152 0.2970774243113014165466967939615193L, 0.5000000000000000000000000000000000L,
153 0.7029225756886985834533032060384807L, 0.8707655927996972199319323866403942L,
154 0.9745539561713792622630948420239256L},
155 {0.0198550717512318841582195657152635L, 0.1016667612931866302042230317620848L,
156 0.2372337950418355070911304754053768L, 0.4082826787521750975302619288199080L,
157 0.5917173212478249024697380711800920L, 0.7627662049581644929088695245946232L,
158 0.8983332387068133697957769682379152L, 0.9801449282487681158417804342847365L},
159 {0.0159198802461869550822118985481636L, 0.0819844463366821028502851059651326L,
160 0.1933142836497048013456489803292629L, 0.3378732882980955354807309926783317L,
161 0.5000000000000000000000000000000000L, 0.6621267117019044645192690073216683L,
162 0.8066857163502951986543510196707371L, 0.9180155536633178971497148940348674L,
163 0.9840801197538130449177881014518364L},
164 {0.0130467357414141399610179939577740L, 0.0674683166555077446339516557882535L,
165 0.1602952158504877968828363174425632L, 0.2833023029353764046003670284171079L,
166 0.4255628305091843945575869994351400L, 0.5744371694908156054424130005648600L,
167 0.7166976970646235953996329715828921L, 0.8397047841495122031171636825574368L,
168 0.9325316833444922553660483442117465L, 0.9869532642585858600389820060422260L},
169 {0.0108856709269715035980309994385713L, 0.0564687001159523504624211153480364L,
170 0.1349239972129753379532918739844233L, 0.2404519353965940920371371652706952L,
171 0.3652284220238275138342340072995692L, 0.5000000000000000000000000000000000L,
172 0.6347715779761724861657659927004308L, 0.7595480646034059079628628347293048L,
173 0.8650760027870246620467081260155767L, 0.9435312998840476495375788846519636L,
174 0.9891143290730284964019690005614287L}};
177 {0.2777777777777777777777777777777778L, 0.4444444444444444444444444444444444L,
178 0.2777777777777777777777777777777778L},
179 {0.1739274225687269286865319746109997L, 0.3260725774312730713134680253890003L,
180 0.3260725774312730713134680253890003L, 0.1739274225687269286865319746109997L},
181 {0.1184634425280945437571320203599587L, 0.2393143352496832340206457574178191L,
182 0.2844444444444444444444444444444444L, 0.2393143352496832340206457574178191L,
183 0.1184634425280945437571320203599587L},
184 {0.0856622461895851725201480710863665L, 0.1803807865240693037849167569188581L,
185 0.2339569672863455236949351719947755L, 0.2339569672863455236949351719947755L,
186 0.1803807865240693037849167569188581L, 0.0856622461895851725201480710863665L},
187 {0.0647424830844348466353057163395410L, 0.1398526957446383339507338857118898L,
188 0.1909150252525594724751848877444876L, 0.2089795918367346938775510204081633L,
189 0.1909150252525594724751848877444876L, 0.1398526957446383339507338857118898L,
190 0.0647424830844348466353057163395410L},
191 {0.0506142681451881295762656771549811L, 0.1111905172266872352721779972131204L,
192 0.1568533229389436436689811009933007L, 0.1813418916891809914825752246385978L,
193 0.1813418916891809914825752246385978L, 0.1568533229389436436689811009933007L,
194 0.1111905172266872352721779972131204L, 0.0506142681451881295762656771549811L},
195 {0.0406371941807872059859460790552618L, 0.0903240803474287020292360156214564L,
196 0.1303053482014677311593714347093164L, 0.1561735385200014200343152032922218L,
197 0.1651196775006298815822625346434870L, 0.1561735385200014200343152032922218L,
198 0.1303053482014677311593714347093164L, 0.0903240803474287020292360156214564L,
199 0.0406371941807872059859460790552618L},
200 {0.0333356721543440687967844049466659L, 0.0747256745752902965728881698288487L,
201 0.1095431812579910219977674671140816L, 0.1346333596549981775456134607847347L,
202 0.1477621123573764350869464973256692L, 0.1477621123573764350869464973256692L,
203 0.1346333596549981775456134607847347L, 0.1095431812579910219977674671140816L,
204 0.0747256745752902965728881698288487L, 0.0333356721543440687967844049466659L},
205 {0.0278342835580868332413768602212743L, 0.0627901847324523123173471496119701L,
206 0.0931451054638671257130488207158280L, 0.1165968822959952399592618524215876L,
207 0.1314022722551233310903444349452546L, 0.1364625433889503153572417641681711L,
208 0.1314022722551233310903444349452546L, 0.1165968822959952399592618524215876L,
209 0.0931451054638671257130488207158280L, 0.0627901847324523123173471496119701L,
210 0.0278342835580868332413768602212743L}};
212 MatrixType TminusI =
T - MatrixType::Identity(
T.rows(),
T.rows());
213 result.setZero(
T.rows(),
T.rows());
219 (MatrixType::Identity(
T.rows(),
T.rows()) + node * TminusI).
template triangularView<Upper>().solve(TminusI);
225 template <
typename MatrixType>
231 int numberOfSquareRoots = 0;
232 int numberOfExtraSquareRoots = 0;
238 maxPadeDegree <= 7 ? 2.6429608311114350e-1L
240 maxPadeDegree <= 8 ? 2.32777776523703892094e-1L
242 maxPadeDegree <= 10 ? 1.05026503471351080481093652651105e-1L
244 1.1880960220216759245467951592883642e-1L);
247 RealScalar normTminusI = (
T - MatrixType::Identity(
T.rows(),
T.rows())).cwiseAbs().colwise().sum().maxCoeff();
248 if (normTminusI < maxNormForPade) {
251 if ((
degree - degree2 <= 1) || (numberOfExtraSquareRoots == 1))
break;
252 ++numberOfExtraSquareRoots;
255 T = sqrtT.template triangularView<Upper>();
256 ++numberOfSquareRoots;
271 template <
typename MatrixType>
281 template <
typename MatrixType>
286 result(0, 0) =
log(
A(0, 0));
287 else if (
A.
rows() == 2)
308 template <
typename Derived>
328 template <
typename ResultType>
329 inline void evalTo(ResultType& result)
const {
350 template <
typename Derived>
358 template <
typename Derived>
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar imag(const AnnoyingScalar &)
Definition: AnnoyingScalar.h:132
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_PI
Definition: MathFunctions.h:16
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 100 >, boost::multiprecision::et_on > Real
Definition: boostmultiprec.cpp:77
Proxy for the matrix logarithm of some matrix (expression).
Definition: MatrixLogarithm.h:309
Index rows() const
Definition: MatrixLogarithm.h:342
internal::ref_selector< Derived >::type DerivedNested
Definition: MatrixLogarithm.h:315
const DerivedNested m_A
Definition: MatrixLogarithm.h:346
Index cols() const
Definition: MatrixLogarithm.h:343
Derived::Index Index
Definition: MatrixLogarithm.h:312
void evalTo(ResultType &result) const
Compute the matrix logarithm.
Definition: MatrixLogarithm.h:329
Derived::Scalar Scalar
Definition: MatrixLogarithm.h:311
MatrixLogarithmReturnValue(const Derived &A)
Constructor.
Definition: MatrixLogarithm.h:322
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
Definition: ReturnByValue.h:50
Helper class for computing matrix logarithm of atomic matrices.
Definition: MatrixLogarithm.h:272
MatrixType compute(const MatrixType &A)
Compute matrix logarithm of atomic matrix.
Definition: MatrixLogarithm.h:282
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 ceil(const bfloat16 &a)
Definition: BFloat16.h:644
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log1p(const bfloat16 &a)
Definition: BFloat16.h:619
void matrix_log_compute_2x2(const MatrixType &A, MatrixType &result)
Compute logarithm of 2x2 triangular matrix.
Definition: MatrixLogarithm.h:41
void matrix_log_compute_pade(MatrixType &result, const MatrixType &T, int degree)
Definition: MatrixLogarithm.h:133
const Scalar & y
Definition: RandomImpl.h:36
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
void matrix_log_compute_big(const MatrixType &A, MatrixType &result)
Compute logarithm of triangular matrices with size > 2.
Definition: MatrixLogarithm.h:226
int matrix_log_get_pade_degree(float normTminusI)
Definition: MatrixLogarithm.h:69
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
DerType::Scalar imag(const AutoDiffScalar< DerType > &)
Definition: AutoDiffScalar.h:490
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void matrix_sqrt_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of triangular matrix.
Definition: MatrixSquareRoot.h:194
list weights
Definition: calibrate.py:94
const Mdouble degree
Definition: ExtendedMath.h:32
Definition: Eigen_Colamd.h:49
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
static void run(const MatrixType &A, AtomicType &atomic, ResultType &result)
Compute the matrix function.
Definition: MatrixLogarithm.h:27
static const int value
Definition: MatrixLogarithm.h:29
NumTraits< Scalar >::Real RealScalar
Definition: MatrixLogarithm.h:28
Definition: MatrixLogarithm.h:22
static const int value
Definition: MatrixLogarithm.h:23
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549
std::conditional_t< bool(traits< T >::Flags &NestByRefBit), T const &, const T > type
Definition: XprHelper.h:507
Derived::PlainObject ReturnType
Definition: MatrixLogarithm.h:352
Definition: ForwardDeclarations.h:21