15 Matrix<T,2,2>
A, B, C;
19 MatrixPower<Matrix<T,2,2> > Apow(A);
21 for (
int i=0; i<=20; ++i) {
22 angle =
std::pow(T(10), (i-10) / T(5.));
28 std::cout <<
"test2dRotation: i = " << i <<
" error powerm = " <<
relerr(C,B) <<
'\n';
29 VERIFY(C.isApprox(B, tol));
36 Matrix<std::complex<T>,2,2>
A, B, C;
40 A << ch, ish, -ish, ch;
41 MatrixPower<Matrix<std::complex<T>,2,2> > Apow(A);
43 for (
int i=0; i<=20; ++i) {
46 ish = std::complex<T>(0,
std::sinh(angle));
47 B << ch, ish, -ish, ch;
50 std::cout <<
"test2dHyperbolicRotation: i = " << i <<
" error powerm = " <<
relerr(C,B) <<
'\n';
51 VERIFY(C.isApprox(B, tol));
61 for (
int i=0; i<=20; ++i) {
62 v = Matrix<T,3,1>::Random();
64 angle =
std::pow(T(10), (i-10) / T(5.));
65 VERIFY(AngleAxis<T>(angle, v).matrix().isApprox(AngleAxis<T>(1,v).matrix().
pow(angle), tol));
69 template<
typename MatrixType>
70 void testGeneral(
const MatrixType& m,
const typename MatrixType::RealScalar& tol)
72 typedef typename MatrixType::RealScalar RealScalar;
73 MatrixType m1, m2, m3, m4, m5;
76 for (
int i=0; i < g_repeat; ++i) {
78 MatrixPower<MatrixType> mpow(m1);
80 x = internal::random<RealScalar>();
81 y = internal::random<RealScalar>();
86 m5.noalias() = m2 * m3;
87 VERIFY(m4.isApprox(m5, tol));
91 VERIFY(m4.isApprox(m5, tol));
95 VERIFY(m4.isApprox(m5, tol));
99 template<
typename MatrixType>
100 void testSingular(
const MatrixType& m_const,
const typename MatrixType::RealScalar& tol)
104 MatrixType& m =
const_cast<MatrixType&
>(m_const);
106 const int IsComplex = NumTraits<typename internal::traits<MatrixType>::Scalar>::IsComplex;
107 typedef typename internal::conditional<IsComplex, TriangularView<MatrixType,Upper>,
const MatrixType&>::type TriangularType;
108 typename internal::conditional< IsComplex, ComplexSchur<MatrixType>, RealSchur<MatrixType> >::type schur;
111 for (
int i=0; i < g_repeat; ++i) {
117 const MatrixType& U = schur.matrixU();
119 MatrixPower<MatrixType> mpow(m);
122 VERIFY(mpow(0.5L).isApprox(U * (TriangularType(T) * U.adjoint()), tol));
125 VERIFY(mpow(0.25L).isApprox(U * (TriangularType(T) * U.adjoint()), tol));
128 VERIFY(mpow(0.125L).isApprox(U * (TriangularType(T) * U.adjoint()), tol));
132 template<
typename MatrixType>
133 void testLogThenExp(
const MatrixType& m_const,
const typename MatrixType::RealScalar& tol)
137 MatrixType& m =
const_cast<MatrixType&
>(m_const);
139 typedef typename MatrixType::Scalar Scalar;
142 for (
int i=0; i < g_repeat; ++i) {
144 x = internal::random<Scalar>();
145 VERIFY(m.pow(x).isApprox((x * m.log()).
exp(), tol));
151 typedef Matrix<long double,Dynamic,Dynamic>
MatrixXe;
155 CALL_SUBTEST_2(test2dRotation<double>(1e-13));
156 CALL_SUBTEST_1(test2dRotation<float>(2e-5));
157 CALL_SUBTEST_9(test2dRotation<long double>(1e-13L));
158 CALL_SUBTEST_2(test2dHyperbolicRotation<double>(1e-14));
159 CALL_SUBTEST_1(test2dHyperbolicRotation<float>(1e-5));
160 CALL_SUBTEST_9(test2dHyperbolicRotation<long double>(1e-14L));
162 CALL_SUBTEST_10(test3dRotation<double>(1e-13));
163 CALL_SUBTEST_11(test3dRotation<float>(1e-5));
164 CALL_SUBTEST_12(test3dRotation<long double>(1e-13L));
void testGeneral(const MatrixType &m, const typename MatrixType::RealScalar &tol)
void test3dRotation(const T &tol)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
Matrix< double, 3, 3, RowMajor > Matrix3dRowMajor
const mpreal ldexp(const mpreal &v, mp_exp_t exp)
EIGEN_DEVICE_FUNC const CoshReturnType cosh() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
Matrix< long double, 3, 3 > Matrix3e
Derived::RealScalar relerr(const MatrixBase< Derived > &A, const MatrixBase< OtherDerived > &B)
void test2dHyperbolicRotation(const T &tol)
void testSingular(const MatrixType &m_const, const typename MatrixType::RealScalar &tol)
void testLogThenExp(const MatrixType &m_const, const typename MatrixType::RealScalar &tol)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
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
void test2dRotation(const T &tol)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
static void run(MatrixType &, MatrixType &, const MatrixType &)
Matrix< long double, Dynamic, Dynamic > MatrixXe
void run(Expr &expr, Dev &dev)