11 #include <unsupported/Eigen/MatrixFunctions> 15 #define VERIFY_IS_APPROX_ABS(a, b) VERIFY(test_isApprox_abs(a, b)) 17 template<
typename Type1,
typename Type2>
20 return ((a-b).array().
abs() < test_precision<typename Type1::RealScalar>()).all();
25 template<
typename MatrixType>
29 typedef typename MatrixType::Scalar Scalar;
30 typedef typename MatrixType::RealScalar RealScalar;
31 MatrixType diag = MatrixType::Zero(size, size);
32 for (Index i = 0; i <
size; ++i) {
33 diag(i, i) = Scalar(RealScalar(internal::random<int>(0,2)))
34 + internal::random<Scalar>() * Scalar(RealScalar(0.01));
36 MatrixType
A = MatrixType::Random(size, size);
37 HouseholderQR<MatrixType> QRofA(A);
38 return QRofA.householderQ().inverse() * diag * QRofA.householderQ();
41 template <typename MatrixType, int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex>
49 template<
typename MatrixType>
55 typedef typename MatrixType::Scalar Scalar;
56 MatrixType diag = MatrixType::Zero(size, size);
59 Index randomInt = internal::random<Index>(-1, 1);
60 if (randomInt == 0 || i == size-1) {
61 diag(i, i) = internal::random<Scalar>() * Scalar(0.01);
64 Scalar alpha = Scalar(randomInt) + internal::random<Scalar>() * Scalar(0.01);
66 diag(i+1, i) = -alpha;
70 MatrixType
A = MatrixType::Random(size, size);
71 HouseholderQR<MatrixType> QRofA(A);
72 return QRofA.householderQ().inverse() * diag * QRofA.householderQ();
77 template<
typename MatrixType>
83 typedef typename MatrixType::Scalar Scalar;
84 typedef typename MatrixType::RealScalar RealScalar;
85 const Scalar imagUnit(0, 1);
86 MatrixType diag = MatrixType::Zero(size, size);
87 for (Index i = 0; i <
size; ++i) {
88 diag(i, i) = Scalar(RealScalar(internal::random<Index>(-1, 1))) * imagUnit
89 + internal::random<Scalar>() * Scalar(RealScalar(0.01));
91 MatrixType
A = MatrixType::Random(size, size);
92 HouseholderQR<MatrixType> QRofA(A);
93 return QRofA.householderQ().inverse() * diag * QRofA.householderQ();
98 template<
typename MatrixType>
101 typedef typename internal::traits<MatrixType>::Scalar Scalar;
103 typedef std::complex<RealScalar> ComplexScalar;
105 VERIFY_IS_APPROX(A.exp(), A.matrixFunction(internal::stem_function_exp<ComplexScalar>));
108 template<
typename MatrixType>
111 typedef typename internal::traits<MatrixType>::Scalar Scalar;
115 RealScalar maxImagPartOfSpectrum = A.eigenvalues().imag().cwiseAbs().maxCoeff();
116 if (maxImagPartOfSpectrum >= RealScalar(0.9L *
EIGEN_PI))
117 scaledA = A * RealScalar(0.9L * EIGEN_PI) / maxImagPartOfSpectrum;
122 MatrixType expA = scaledA.exp();
123 MatrixType logExpA = expA.log();
124 VERIFY_IS_APPROX(logExpA, scaledA);
127 template<
typename MatrixType>
136 template<
typename MatrixType>
139 typedef typename MatrixType::Scalar Scalar;
141 typedef std::complex<RealScalar> ComplexScalar;
142 typedef Matrix<ComplexScalar, MatrixType::RowsAtCompileTime,
143 MatrixType::ColsAtCompileTime, MatrixType::Options> ComplexMatrix;
145 ComplexScalar imagUnit(0,1);
146 ComplexScalar two(2,0);
148 ComplexMatrix Ac = A.template cast<ComplexScalar>();
150 ComplexMatrix exp_iA = (imagUnit * Ac).
exp();
151 ComplexMatrix exp_miA = (-imagUnit * Ac).
exp();
153 ComplexMatrix sinAc = A.sin().template cast<ComplexScalar>();
156 ComplexMatrix cosAc = A.cos().template cast<ComplexScalar>();
160 template<
typename MatrixType>
169 template<
typename MatrixType>
176 const Index
size = m.rows();
177 for (
int i = 0; i < g_repeat; i++) {
178 testMatrix(MatrixType::Random(size, size).eval());
179 testMatrix(randomMatrixWithRealEivals<MatrixType>(size));
void testMatrix(const MatrixType &A)
void testMatrixLogarithm(const MatrixType &A)
void testMatrixExponential(const MatrixType &A)
bool test_isApprox_abs(const Type1 &a, const Type2 &b)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
void testMatrixType(const MatrixType &m)
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 MatrixType run(const typename MatrixType::Index size)
void testHyperbolicFunctions(const MatrixType &A)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
void test_matrix_function()
#define VERIFY_IS_APPROX_ABS(a, b)
MatrixType randomMatrixWithRealEivals(const typename MatrixType::Index size)
EIGEN_DEVICE_FUNC const Scalar & b
static MatrixType run(const typename MatrixType::Index size)
void testGonioFunctions(const MatrixType &A)
static MatrixType run(const typename MatrixType::Index size)