TR-mbed 1.0
Loading...
Searching...
No Matches
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.
14template<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.
22template<typename MatrixType>
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
39template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
41
42template <typename MatrixType>
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();
51 }
52};
53
54template <typename MatrixType>
56{
57 static void run(MatrixType& result, typename MatrixType::Index size)
58 {
59 result = MatrixType::Random(size, size);
60 }
61};
62
63template <typename Derived, typename OtherDerived>
64typename 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}
Matrix3f m
Definition AngleAxis_mimic_euler.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
ComplexSchur< MatrixXcf > schur(4)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseAbs2ReturnType cwiseAbs2() const
Definition MatrixCwiseUnaryOps.h:46
Scalar Scalar int size
Definition benchVecAdd.cpp:17
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition bench_gemm.cpp:48
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition bench_gemm.cpp:49
MatrixXf MatrixType
Definition benchmark-blocking-sizes.cpp:52
@ IsComplex
Definition common.h:98
Derived::RealScalar relerr(const MatrixBase< Derived > &A, const MatrixBase< OtherDerived > &B)
Definition matrix_functions.h:64
static void run(MatrixType &result, typename MatrixType::Index size)
Definition matrix_functions.h:45
static void run(MatrixType &result, typename MatrixType::Index size)
Definition matrix_functions.h:57
Definition matrix_functions.h:40
static void run(MatrixType &m, MatrixType &T, const MatrixType &U)
Definition matrix_functions.h:25
Definition matrix_functions.h:16
static void run(MatrixType &, MatrixType &, const MatrixType &)
Definition matrix_functions.h:17