MatrixLogarithm.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
5 // Copyright (C) 2011 Chen-Pang He <jdh8@ms63.hinet.net>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_MATRIX_LOGARITHM
27 #define EIGEN_MATRIX_LOGARITHM
28 
29 #ifndef M_PI
30 #define M_PI 3.141592653589793238462643383279503L
31 #endif
32 
33 namespace Eigen {
34 
45 template <typename MatrixType>
47 {
48 public:
49 
50  typedef typename MatrixType::Scalar Scalar;
51  // typedef typename MatrixType::Index Index;
52  typedef typename NumTraits<Scalar>::Real RealScalar;
53  // typedef typename internal::stem_function<Scalar>::type StemFunction;
54  // typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
55 
58 
63  MatrixType compute(const MatrixType& A);
64 
65 private:
66 
67  void compute2x2(const MatrixType& A, MatrixType& result);
68  void computeBig(const MatrixType& A, MatrixType& result);
69  static Scalar atanh(Scalar x);
70  int getPadeDegree(float normTminusI);
71  int getPadeDegree(double normTminusI);
72  int getPadeDegree(long double normTminusI);
73  void computePade(MatrixType& result, const MatrixType& T, int degree);
74  void computePade3(MatrixType& result, const MatrixType& T);
75  void computePade4(MatrixType& result, const MatrixType& T);
76  void computePade5(MatrixType& result, const MatrixType& T);
77  void computePade6(MatrixType& result, const MatrixType& T);
78  void computePade7(MatrixType& result, const MatrixType& T);
79  void computePade8(MatrixType& result, const MatrixType& T);
80  void computePade9(MatrixType& result, const MatrixType& T);
81  void computePade10(MatrixType& result, const MatrixType& T);
82  void computePade11(MatrixType& result, const MatrixType& T);
83 
84  static const int minPadeDegree = 3;
85  static const int maxPadeDegree = std::numeric_limits<RealScalar>::digits<= 24? 5: // single precision
86  std::numeric_limits<RealScalar>::digits<= 53? 7: // double precision
87  std::numeric_limits<RealScalar>::digits<= 64? 8: // extended precision
88  std::numeric_limits<RealScalar>::digits<=106? 10: 11; // double-double or quadruple precision
89 
90  // Prevent copying
93 };
94 
96 template <typename MatrixType>
97 MatrixType MatrixLogarithmAtomic<MatrixType>::compute(const MatrixType& A)
98 {
99  using std::log;
100  MatrixType result(A.rows(), A.rows());
101  if (A.rows() == 1)
102  result(0,0) = log(A(0,0));
103  else if (A.rows() == 2)
104  compute2x2(A, result);
105  else
106  computeBig(A, result);
107  return result;
108 }
109 
111 template <typename MatrixType>
112 typename MatrixType::Scalar MatrixLogarithmAtomic<MatrixType>::atanh(typename MatrixType::Scalar x)
113 {
114  using std::abs;
115  using std::sqrt;
116  if (abs(x) > sqrt(NumTraits<Scalar>::epsilon()))
117  return Scalar(0.5) * log((Scalar(1) + x) / (Scalar(1) - x));
118  else
119  return x + x*x*x / Scalar(3);
120 }
121 
123 template <typename MatrixType>
124 void MatrixLogarithmAtomic<MatrixType>::compute2x2(const MatrixType& A, MatrixType& result)
125 {
126  using std::abs;
127  using std::ceil;
128  using std::imag;
129  using std::log;
130 
131  Scalar logA00 = log(A(0,0));
132  Scalar logA11 = log(A(1,1));
133 
134  result(0,0) = logA00;
135  result(1,0) = Scalar(0);
136  result(1,1) = logA11;
137 
138  if (A(0,0) == A(1,1)) {
139  result(0,1) = A(0,1) / A(0,0);
140  } else if ((abs(A(0,0)) < 0.5*abs(A(1,1))) || (abs(A(0,0)) > 2*abs(A(1,1)))) {
141  result(0,1) = A(0,1) * (logA11 - logA00) / (A(1,1) - A(0,0));
142  } else {
143  // computation in previous branch is inaccurate if A(1,1) \approx A(0,0)
144  int unwindingNumber = static_cast<int>(ceil((imag(logA11 - logA00) - M_PI) / (2*M_PI)));
145  Scalar z = (A(1,1) - A(0,0)) / (A(1,1) + A(0,0));
146  result(0,1) = A(0,1) * (Scalar(2) * atanh(z) + Scalar(0,2*M_PI*unwindingNumber)) / (A(1,1) - A(0,0));
147  }
148 }
149 
152 template <typename MatrixType>
153 void MatrixLogarithmAtomic<MatrixType>::computeBig(const MatrixType& A, MatrixType& result)
154 {
155  int numberOfSquareRoots = 0;
156  int numberOfExtraSquareRoots = 0;
157  int degree;
158  MatrixType T = A;
159  const RealScalar maxNormForPade = maxPadeDegree<= 5? 5.3149729967117310e-1: // single precision
160  maxPadeDegree<= 7? 2.6429608311114350e-1: // double precision
161  maxPadeDegree<= 8? 2.32777776523703892094e-1L: // extended precision
162  maxPadeDegree<=10? 1.05026503471351080481093652651105e-1L: // double-double
163  1.1880960220216759245467951592883642e-1L; // quadruple precision
164 
165  while (true) {
166  RealScalar normTminusI = (T - MatrixType::Identity(T.rows(), T.rows())).cwiseAbs().colwise().sum().maxCoeff();
167  if (normTminusI < maxNormForPade) {
168  degree = getPadeDegree(normTminusI);
169  int degree2 = getPadeDegree(normTminusI / RealScalar(2));
170  if ((degree - degree2 <= 1) || (numberOfExtraSquareRoots == 1))
171  break;
172  ++numberOfExtraSquareRoots;
173  }
174  MatrixType sqrtT;
175  MatrixSquareRootTriangular<MatrixType>(T).compute(sqrtT);
176  T = sqrtT;
177  ++numberOfSquareRoots;
178  }
179 
180  computePade(result, T, degree);
181  result *= pow(RealScalar(2), numberOfSquareRoots);
182 }
183 
184 /* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = float) */
185 template <typename MatrixType>
186 int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(float normTminusI)
187 {
188  const float maxNormForPade[] = { 2.5111573934555054e-1 /* degree = 3 */ , 4.0535837411880493e-1,
189  5.3149729967117310e-1 };
190  for (int degree = 3; degree <= maxPadeDegree; ++degree)
191  if (normTminusI <= maxNormForPade[degree - minPadeDegree])
192  return degree;
193  assert(false); // this line should never be reached
194 }
195 
196 /* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = double) */
197 template <typename MatrixType>
198 int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(double normTminusI)
199 {
200  const double maxNormForPade[] = { 1.6206284795015624e-2 /* degree = 3 */ , 5.3873532631381171e-2,
201  1.1352802267628681e-1, 1.8662860613541288e-1, 2.642960831111435e-1 };
202  for (int degree = 3; degree <= maxPadeDegree; ++degree)
203  if (normTminusI <= maxNormForPade[degree - minPadeDegree])
204  return degree;
205  assert(false); // this line should never be reached
206 }
207 
208 /* \brief Get suitable degree for Pade approximation. (specialized for RealScalar = long double) */
209 template <typename MatrixType>
210 int MatrixLogarithmAtomic<MatrixType>::getPadeDegree(long double normTminusI)
211 {
212 #if LDBL_MANT_DIG == 53 // double precision
213  const double maxNormForPade[] = { 1.6206284795015624e-2 /* degree = 3 */ , 5.3873532631381171e-2,
214  1.1352802267628681e-1, 1.8662860613541288e-1, 2.642960831111435e-1 };
215 #elif LDBL_MANT_DIG <= 64 // extended precision
216  const double maxNormForPade[] = { 5.48256690357782863103e-3 /* degree = 3 */, 2.34559162387971167321e-2,
217  5.84603923897347449857e-2, 1.08486423756725170223e-1, 1.68385767881294446649e-1,
218  2.32777776523703892094e-1 };
219 #elif LDBL_MANT_DIG <= 106 // double-double
220  const double maxNormForPade[] = { 8.58970550342939562202529664318890e-5 /* degree = 3 */,
221  9.34074328446359654039446552677759e-4, 4.26117194647672175773064114582860e-3,
222  1.21546224740281848743149666560464e-2, 2.61100544998339436713088248557444e-2,
223  4.66170074627052749243018566390567e-2, 7.32585144444135027565872014932387e-2,
224  1.05026503471351080481093652651105e-1 };
225 #else // quadruple precision
226  const double maxNormForPade[] = { 4.7419931187193005048501568167858103e-5 /* degree = 3 */,
227  5.8853168473544560470387769480192666e-4, 2.9216120366601315391789493628113520e-3,
228  8.8415758124319434347116734705174308e-3, 1.9850836029449446668518049562565291e-2,
229  3.6688019729653446926585242192447447e-2, 5.9290962294020186998954055264528393e-2,
230  8.6998436081634343903250580992127677e-2, 1.1880960220216759245467951592883642e-1 };
231 #endif
232  for (int degree = 3; degree <= maxPadeDegree; ++degree)
233  if (normTminusI <= maxNormForPade[degree - minPadeDegree])
234  return degree;
235  assert(false); // this line should never be reached
236 }
237 
238 /* \brief Compute Pade approximation to matrix logarithm */
239 template <typename MatrixType>
240 void MatrixLogarithmAtomic<MatrixType>::computePade(MatrixType& result, const MatrixType& T, int degree)
241 {
242  switch (degree) {
243  case 3: computePade3(result, T); break;
244  case 4: computePade4(result, T); break;
245  case 5: computePade5(result, T); break;
246  case 6: computePade6(result, T); break;
247  case 7: computePade7(result, T); break;
248  case 8: computePade8(result, T); break;
249  case 9: computePade9(result, T); break;
250  case 10: computePade10(result, T); break;
251  case 11: computePade11(result, T); break;
252  default: assert(false); // should never happen
253  }
254 }
255 
256 template <typename MatrixType>
257 void MatrixLogarithmAtomic<MatrixType>::computePade3(MatrixType& result, const MatrixType& T)
258 {
259  const int degree = 3;
260  const RealScalar nodes[] = { 0.1127016653792583114820734600217600L, 0.5000000000000000000000000000000000L,
261  0.8872983346207416885179265399782400L };
262  const RealScalar weights[] = { 0.2777777777777777777777777777777778L, 0.4444444444444444444444444444444444L,
263  0.2777777777777777777777777777777778L };
264  assert(degree <= maxPadeDegree);
265  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
266  result.setZero(T.rows(), T.rows());
267  for (int k = 0; k < degree; ++k)
268  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
269  .template triangularView<Upper>().solve(TminusI);
270 }
271 
272 template <typename MatrixType>
273 void MatrixLogarithmAtomic<MatrixType>::computePade4(MatrixType& result, const MatrixType& T)
274 {
275  const int degree = 4;
276  const RealScalar nodes[] = { 0.0694318442029737123880267555535953L, 0.3300094782075718675986671204483777L,
277  0.6699905217924281324013328795516223L, 0.9305681557970262876119732444464048L };
278  const RealScalar weights[] = { 0.1739274225687269286865319746109997L, 0.3260725774312730713134680253890003L,
279  0.3260725774312730713134680253890003L, 0.1739274225687269286865319746109997L };
280  assert(degree <= maxPadeDegree);
281  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
282  result.setZero(T.rows(), T.rows());
283  for (int k = 0; k < degree; ++k)
284  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
285  .template triangularView<Upper>().solve(TminusI);
286 }
287 
288 template <typename MatrixType>
289 void MatrixLogarithmAtomic<MatrixType>::computePade5(MatrixType& result, const MatrixType& T)
290 {
291  const int degree = 5;
292  const RealScalar nodes[] = { 0.0469100770306680036011865608503035L, 0.2307653449471584544818427896498956L,
293  0.5000000000000000000000000000000000L, 0.7692346550528415455181572103501044L,
294  0.9530899229693319963988134391496965L };
295  const RealScalar weights[] = { 0.1184634425280945437571320203599587L, 0.2393143352496832340206457574178191L,
296  0.2844444444444444444444444444444444L, 0.2393143352496832340206457574178191L,
297  0.1184634425280945437571320203599587L };
298  assert(degree <= maxPadeDegree);
299  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
300  result.setZero(T.rows(), T.rows());
301  for (int k = 0; k < degree; ++k)
302  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
303  .template triangularView<Upper>().solve(TminusI);
304 }
305 
306 template <typename MatrixType>
307 void MatrixLogarithmAtomic<MatrixType>::computePade6(MatrixType& result, const MatrixType& T)
308 {
309  const int degree = 6;
310  const RealScalar nodes[] = { 0.0337652428984239860938492227530027L, 0.1693953067668677431693002024900473L,
311  0.3806904069584015456847491391596440L, 0.6193095930415984543152508608403560L,
312  0.8306046932331322568306997975099527L, 0.9662347571015760139061507772469973L };
313  const RealScalar weights[] = { 0.0856622461895851725201480710863665L, 0.1803807865240693037849167569188581L,
314  0.2339569672863455236949351719947755L, 0.2339569672863455236949351719947755L,
315  0.1803807865240693037849167569188581L, 0.0856622461895851725201480710863665L };
316  assert(degree <= maxPadeDegree);
317  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
318  result.setZero(T.rows(), T.rows());
319  for (int k = 0; k < degree; ++k)
320  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
321  .template triangularView<Upper>().solve(TminusI);
322 }
323 
324 template <typename MatrixType>
325 void MatrixLogarithmAtomic<MatrixType>::computePade7(MatrixType& result, const MatrixType& T)
326 {
327  const int degree = 7;
328  const RealScalar nodes[] = { 0.0254460438286207377369051579760744L, 0.1292344072003027800680676133596058L,
329  0.2970774243113014165466967939615193L, 0.5000000000000000000000000000000000L,
330  0.7029225756886985834533032060384807L, 0.8707655927996972199319323866403942L,
331  0.9745539561713792622630948420239256L };
332  const RealScalar weights[] = { 0.0647424830844348466353057163395410L, 0.1398526957446383339507338857118898L,
333  0.1909150252525594724751848877444876L, 0.2089795918367346938775510204081633L,
334  0.1909150252525594724751848877444876L, 0.1398526957446383339507338857118898L,
335  0.0647424830844348466353057163395410L };
336  assert(degree <= maxPadeDegree);
337  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
338  result.setZero(T.rows(), T.rows());
339  for (int k = 0; k < degree; ++k)
340  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
341  .template triangularView<Upper>().solve(TminusI);
342 }
343 
344 template <typename MatrixType>
345 void MatrixLogarithmAtomic<MatrixType>::computePade8(MatrixType& result, const MatrixType& T)
346 {
347  const int degree = 8;
348  const RealScalar nodes[] = { 0.0198550717512318841582195657152635L, 0.1016667612931866302042230317620848L,
349  0.2372337950418355070911304754053768L, 0.4082826787521750975302619288199080L,
350  0.5917173212478249024697380711800920L, 0.7627662049581644929088695245946232L,
351  0.8983332387068133697957769682379152L, 0.9801449282487681158417804342847365L };
352  const RealScalar weights[] = { 0.0506142681451881295762656771549811L, 0.1111905172266872352721779972131204L,
353  0.1568533229389436436689811009933007L, 0.1813418916891809914825752246385978L,
354  0.1813418916891809914825752246385978L, 0.1568533229389436436689811009933007L,
355  0.1111905172266872352721779972131204L, 0.0506142681451881295762656771549811L };
356  assert(degree <= maxPadeDegree);
357  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
358  result.setZero(T.rows(), T.rows());
359  for (int k = 0; k < degree; ++k)
360  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
361  .template triangularView<Upper>().solve(TminusI);
362 }
363 
364 template <typename MatrixType>
365 void MatrixLogarithmAtomic<MatrixType>::computePade9(MatrixType& result, const MatrixType& T)
366 {
367  const int degree = 9;
368  const RealScalar nodes[] = { 0.0159198802461869550822118985481636L, 0.0819844463366821028502851059651326L,
369  0.1933142836497048013456489803292629L, 0.3378732882980955354807309926783317L,
370  0.5000000000000000000000000000000000L, 0.6621267117019044645192690073216683L,
371  0.8066857163502951986543510196707371L, 0.9180155536633178971497148940348674L,
372  0.9840801197538130449177881014518364L };
373  const RealScalar weights[] = { 0.0406371941807872059859460790552618L, 0.0903240803474287020292360156214564L,
374  0.1303053482014677311593714347093164L, 0.1561735385200014200343152032922218L,
375  0.1651196775006298815822625346434870L, 0.1561735385200014200343152032922218L,
376  0.1303053482014677311593714347093164L, 0.0903240803474287020292360156214564L,
377  0.0406371941807872059859460790552618L };
378  assert(degree <= maxPadeDegree);
379  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
380  result.setZero(T.rows(), T.rows());
381  for (int k = 0; k < degree; ++k)
382  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
383  .template triangularView<Upper>().solve(TminusI);
384 }
385 
386 template <typename MatrixType>
387 void MatrixLogarithmAtomic<MatrixType>::computePade10(MatrixType& result, const MatrixType& T)
388 {
389  const int degree = 10;
390  const RealScalar nodes[] = { 0.0130467357414141399610179939577740L, 0.0674683166555077446339516557882535L,
391  0.1602952158504877968828363174425632L, 0.2833023029353764046003670284171079L,
392  0.4255628305091843945575869994351400L, 0.5744371694908156054424130005648600L,
393  0.7166976970646235953996329715828921L, 0.8397047841495122031171636825574368L,
394  0.9325316833444922553660483442117465L, 0.9869532642585858600389820060422260L };
395  const RealScalar weights[] = { 0.0333356721543440687967844049466659L, 0.0747256745752902965728881698288487L,
396  0.1095431812579910219977674671140816L, 0.1346333596549981775456134607847347L,
397  0.1477621123573764350869464973256692L, 0.1477621123573764350869464973256692L,
398  0.1346333596549981775456134607847347L, 0.1095431812579910219977674671140816L,
399  0.0747256745752902965728881698288487L, 0.0333356721543440687967844049466659L };
400  assert(degree <= maxPadeDegree);
401  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
402  result.setZero(T.rows(), T.rows());
403  for (int k = 0; k < degree; ++k)
404  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
405  .template triangularView<Upper>().solve(TminusI);
406 }
407 
408 template <typename MatrixType>
409 void MatrixLogarithmAtomic<MatrixType>::computePade11(MatrixType& result, const MatrixType& T)
410 {
411  const int degree = 11;
412  const RealScalar nodes[] = { 0.0108856709269715035980309994385713L, 0.0564687001159523504624211153480364L,
413  0.1349239972129753379532918739844233L, 0.2404519353965940920371371652706952L,
414  0.3652284220238275138342340072995692L, 0.5000000000000000000000000000000000L,
415  0.6347715779761724861657659927004308L, 0.7595480646034059079628628347293048L,
416  0.8650760027870246620467081260155767L, 0.9435312998840476495375788846519636L,
417  0.9891143290730284964019690005614287L };
418  const RealScalar weights[] = { 0.0278342835580868332413768602212743L, 0.0627901847324523123173471496119701L,
419  0.0931451054638671257130488207158280L, 0.1165968822959952399592618524215876L,
420  0.1314022722551233310903444349452546L, 0.1364625433889503153572417641681711L,
421  0.1314022722551233310903444349452546L, 0.1165968822959952399592618524215876L,
422  0.0931451054638671257130488207158280L, 0.0627901847324523123173471496119701L,
423  0.0278342835580868332413768602212743L };
424  assert(degree <= maxPadeDegree);
425  MatrixType TminusI = T - MatrixType::Identity(T.rows(), T.rows());
426  result.setZero(T.rows(), T.rows());
427  for (int k = 0; k < degree; ++k)
428  result += weights[k] * (MatrixType::Identity(T.rows(), T.rows()) + nodes[k] * TminusI)
429  .template triangularView<Upper>().solve(TminusI);
430 }
431 
444 template<typename Derived> class MatrixLogarithmReturnValue
445 : public ReturnByValue<MatrixLogarithmReturnValue<Derived> >
446 {
447 public:
448 
449  typedef typename Derived::Scalar Scalar;
450  typedef typename Derived::Index Index;
451 
456  MatrixLogarithmReturnValue(const Derived& A) : m_A(A) { }
457 
462  template <typename ResultType>
463  inline void evalTo(ResultType& result) const
464  {
465  typedef typename Derived::PlainObject PlainObject;
466  typedef internal::traits<PlainObject> Traits;
467  static const int RowsAtCompileTime = Traits::RowsAtCompileTime;
468  static const int ColsAtCompileTime = Traits::ColsAtCompileTime;
469  static const int Options = PlainObject::Options;
470  typedef std::complex<typename NumTraits<Scalar>::Real> ComplexScalar;
471  typedef Matrix<ComplexScalar, Dynamic, Dynamic, Options, RowsAtCompileTime, ColsAtCompileTime> DynMatrixType;
472  typedef MatrixLogarithmAtomic<DynMatrixType> AtomicType;
473  AtomicType atomic;
474 
475  const PlainObject Aevaluated = m_A.eval();
476  MatrixFunction<PlainObject, AtomicType> mf(Aevaluated, atomic);
477  mf.compute(result);
478  }
479 
480  Index rows() const { return m_A.rows(); }
481  Index cols() const { return m_A.cols(); }
482 
483 private:
484  typename internal::nested<Derived>::type m_A;
485 
487 };
488 
489 namespace internal {
490  template<typename Derived>
491  struct traits<MatrixLogarithmReturnValue<Derived> >
492  {
493  typedef typename Derived::PlainObject ReturnType;
494  };
495 }
496 
497 
498 /********** MatrixBase method **********/
499 
500 
501 template <typename Derived>
502 const MatrixLogarithmReturnValue<Derived> MatrixBase<Derived>::log() const
503 {
504  eigen_assert(rows() == cols());
505  return MatrixLogarithmReturnValue<Derived>(derived());
506 }
507 
508 } // end namespace Eigen
509 
510 #endif // EIGEN_MATRIX_LOGARITHM