15 for (
int i=0; i<k; i++)
16 res = res * (n-k+i+1) / (i+1);
29 Matrix<T,2,2>
A, B, C;
33 for (
int i=0; i<=20; i++)
35 angle =
static_cast<T
>(
pow(10, i / 5. - 2));
38 C = (angle*A).matrixFunction(
expfn);
39 std::cout <<
"test2dRotation: i = " << i <<
" error funm = " <<
relerr(C, B);
40 VERIFY(C.isApprox(B, static_cast<T>(tol)));
43 std::cout <<
" error expm = " <<
relerr(C, B) <<
"\n";
44 VERIFY(C.isApprox(B, static_cast<T>(tol)));
51 Matrix<std::complex<T>,2,2>
A, B, C;
52 std::complex<T> imagUnit(0,1);
55 for (
int i=0; i<=20; i++)
57 angle =
static_cast<T
>((i-10) / 2.0);
60 A << 0, angle*imagUnit, -angle*imagUnit, 0;
61 B << ch, sh*imagUnit, -sh*imagUnit, ch;
63 C = A.matrixFunction(
expfn);
64 std::cout <<
"test2dHyperbolicRotation: i = " << i <<
" error funm = " <<
relerr(C, B);
65 VERIFY(C.isApprox(B, static_cast<T>(tol)));
68 std::cout <<
" error expm = " <<
relerr(C, B) <<
"\n";
69 VERIFY(C.isApprox(B, static_cast<T>(tol)));
80 for (
int i=0; i<
size-1; i++)
81 A(i+1,i) =
static_cast<T
>(i+1);
83 for (
int i=0; i<
size; i++)
84 for (
int j=0; j<=i; j++)
85 B(i,j) =
static_cast<T
>(
binom(i,j));
87 C =
A.matrixFunction(
expfn);
88 std::cout <<
"testPascal: size = " << size <<
" error funm = " <<
relerr(C, B);
89 VERIFY(C.isApprox(B, static_cast<T>(tol)));
92 std::cout <<
" error expm = " <<
relerr(C, B) <<
"\n";
93 VERIFY(C.isApprox(B, static_cast<T>(tol)));
97 template<
typename MatrixType>
105 MatrixType m1(rows, cols), m2(rows, cols), identity = MatrixType::Identity(rows, cols);
107 typedef typename NumTraits<typename internal::traits<MatrixType>::Scalar>::Real RealScalar;
109 for(
int i = 0; i < g_repeat; i++) {
110 m1 = MatrixType::Random(rows, cols);
112 m2 = m1.matrixFunction(
expfn) * (-m1).matrixFunction(
expfn);
113 std::cout <<
"randomTest: error funm = " <<
relerr(identity, m2);
114 VERIFY(identity.isApprox(m2, static_cast<RealScalar>(tol)));
116 m2 = m1.exp() * (-m1).
exp();
117 std::cout <<
" error expm = " <<
relerr(identity, m2) <<
"\n";
118 VERIFY(identity.isApprox(m2, static_cast<RealScalar>(tol)));
124 CALL_SUBTEST_2(test2dRotation<double>(1e-13));
125 CALL_SUBTEST_1(test2dRotation<float>(2e-5));
126 CALL_SUBTEST_8(test2dRotation<long double>(1e-13));
127 CALL_SUBTEST_2(test2dHyperbolicRotation<double>(1e-14));
128 CALL_SUBTEST_1(test2dHyperbolicRotation<float>(1e-5));
129 CALL_SUBTEST_8(test2dHyperbolicRotation<long double>(1e-14));
130 CALL_SUBTEST_6(testPascal<float>(1e-6));
131 CALL_SUBTEST_5(testPascal<double>(1e-15));
132 CALL_SUBTEST_2(
randomTest(Matrix2d(), 1e-13));
133 CALL_SUBTEST_7(
randomTest(Matrix<double,3,3,RowMajor>(), 1e-13));
134 CALL_SUBTEST_3(
randomTest(Matrix4cd(), 1e-13));
135 CALL_SUBTEST_4(
randomTest(MatrixXd(8,8), 1e-13));
137 CALL_SUBTEST_5(
randomTest(Matrix3cf(), 1e-4));
139 CALL_SUBTEST_6(
randomTest(MatrixXf(8,8), 1e-4));
140 CALL_SUBTEST_9(
randomTest(Matrix<long double,Dynamic,Dynamic>(7,7), 1e-13));
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
void test2dRotation(double tol)
void testPascal(double tol)
EIGEN_DEVICE_FUNC const CoshReturnType cosh() const
static constexpr size_t size(Tuple< Args... > &)
Provides access to the number of elements in a tuple as a compile-time constant expression.
double binom(int n, int k)
Derived::RealScalar relerr(const MatrixBase< Derived > &A, const MatrixBase< OtherDerived > &B)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
void test2dHyperbolicRotation(double tol)
internal::enable_if< !(internal::is_same< typename Derived::Scalar, ScalarExponent >::value)&&EIGEN_SCALAR_BINARY_SUPPORTED(pow, typename Derived::Scalar, ScalarExponent), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, ScalarExponent, pow) >::type pow(const Eigen::ArrayBase< Derived > &x, const ScalarExponent &exponent)
EIGEN_DEVICE_FUNC const SinhReturnType sinh() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
void randomTest(const MatrixType &m, double tol)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
void test_matrix_exponential()