matrix_functions.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009-2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 #include <unsupported/Eigen/MatrixFunctions>
12 
13 // For complex matrices, any matrix is fine.
14 template<typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
16 {
17  static void run(MatrixType&, MatrixType&, const MatrixType&)
18  { }
19 };
20 
21 // For real matrices, make sure none of the eigenvalues are negative.
22 template<typename MatrixType>
23 struct processTriangularMatrix<MatrixType,0>
24 {
25  static void run(MatrixType& m, MatrixType& T, const MatrixType& U)
26  {
27  const Index size = m.cols();
28 
29  for (Index i=0; i < size; ++i) {
30  if (i == size - 1 || T.coeff(i+1,i) == 0)
31  T.coeffRef(i,i) = std::abs(T.coeff(i,i));
32  else
33  ++i;
34  }
35  m = U * T * U.transpose();
36  }
37 };
38 
39 template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
41 
42 template <typename MatrixType>
43 struct generateTestMatrix<MatrixType,0>
44 {
45  static void run(MatrixType& result, typename MatrixType::Index size)
46  {
47  result = MatrixType::Random(size, size);
48  RealSchur<MatrixType> schur(result);
49  MatrixType T = schur.matrixT();
50  processTriangularMatrix<MatrixType>::run(result, T, schur.matrixU());
51  }
52 };
53 
54 template <typename MatrixType>
55 struct generateTestMatrix<MatrixType,1>
56 {
57  static void run(MatrixType& result, typename MatrixType::Index size)
58  {
59  result = MatrixType::Random(size, size);
60  }
61 };
62 
63 template <typename Derived, typename OtherDerived>
64 typename Derived::RealScalar relerr(const MatrixBase<Derived>& A, const MatrixBase<OtherDerived>& B)
65 {
66  return std::sqrt((A - B).cwiseAbs2().sum() / (std::min)(A.cwiseAbs2().sum(), B.cwiseAbs2().sum()));
67 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseAbs2ReturnType cwiseAbs2() const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
static void run(MatrixType &result, typename MatrixType::Index size)
Derived::RealScalar relerr(const MatrixBase< Derived > &A, const MatrixBase< OtherDerived > &B)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Definition: mpreal.h:2381
static void run(MatrixType &, MatrixType &, const MatrixType &)
static void run(MatrixType &result, typename MatrixType::Index size)
static void run(MatrixType &m, MatrixType &T, const MatrixType &U)


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:25