API change: ei_matrix_exponential(A) --> A.exp(), etc

As discussed on mailing list; see
http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2010/02/msg00190.html
This commit is contained in:
Jitse Niesen
2010-03-16 17:26:55 +00:00
parent d536fef1bb
commit 04a4e22c58
11 changed files with 74 additions and 75 deletions

View File

@@ -57,11 +57,11 @@ void test2dRotation(double tol)
angle = static_cast<T>(pow(10, i / 5. - 2));
B << cos(angle), sin(angle), -sin(angle), cos(angle);
C = ei_matrix_function(angle*A, expfn);
C = (angle*A).matrixFunction(expfn);
std::cout << "test2dRotation: i = " << i << " error funm = " << relerr(C, B);
VERIFY(C.isApprox(B, static_cast<T>(tol)));
C = ei_matrix_exponential(angle*A);
C = (angle*A).exp();
std::cout << " error expm = " << relerr(C, B) << "\n";
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
@@ -82,11 +82,11 @@ void test2dHyperbolicRotation(double tol)
A << 0, angle*imagUnit, -angle*imagUnit, 0;
B << ch, sh*imagUnit, -sh*imagUnit, ch;
C = ei_matrix_function(A, expfn);
C = A.matrixFunction(expfn);
std::cout << "test2dHyperbolicRotation: i = " << i << " error funm = " << relerr(C, B);
VERIFY(C.isApprox(B, static_cast<T>(tol)));
C = ei_matrix_exponential(A);
C = A.exp();
std::cout << " error expm = " << relerr(C, B) << "\n";
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
@@ -106,11 +106,11 @@ void testPascal(double tol)
for (int j=0; j<=i; j++)
B(i,j) = static_cast<T>(binom(i,j));
C = ei_matrix_function(A, expfn);
C = A.matrixFunction(expfn);
std::cout << "testPascal: size = " << size << " error funm = " << relerr(C, B);
VERIFY(C.isApprox(B, static_cast<T>(tol)));
C = ei_matrix_exponential(A);
C = A.exp();
std::cout << " error expm = " << relerr(C, B) << "\n";
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
@@ -132,11 +132,11 @@ void randomTest(const MatrixType& m, double tol)
for(int i = 0; i < g_repeat; i++) {
m1 = MatrixType::Random(rows, cols);
m2 = ei_matrix_function(m1, expfn) * ei_matrix_function(-m1, expfn);
m2 = m1.matrixFunction(expfn) * (-m1).matrixFunction(expfn);
std::cout << "randomTest: error funm = " << relerr(identity, m2);
VERIFY(identity.isApprox(m2, static_cast<RealScalar>(tol)));
m2 = ei_matrix_exponential(m1) * ei_matrix_exponential(-m1);
m2 = m1.exp() * (-m1).exp();
std::cout << " error expm = " << relerr(identity, m2) << "\n";
VERIFY(identity.isApprox(m2, static_cast<RealScalar>(tol)));
}

View File

@@ -114,8 +114,7 @@ void testMatrixExponential(const MatrixType& A)
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef std::complex<RealScalar> ComplexScalar;
VERIFY_IS_APPROX(ei_matrix_exponential(A),
ei_matrix_function(A, StdStemFunctions<ComplexScalar>::exp));
VERIFY_IS_APPROX(A.exp(), A.matrixFunction(StdStemFunctions<ComplexScalar>::exp));
}
template<typename MatrixType>
@@ -123,10 +122,8 @@ void testHyperbolicFunctions(const MatrixType& A)
{
// Need to use absolute error because of possible cancellation when
// adding/subtracting expA and expmA.
MatrixType expA = ei_matrix_exponential(A);
MatrixType expmA = ei_matrix_exponential(-A);
VERIFY_IS_APPROX_ABS(ei_matrix_sinh(A), (expA - expmA) / 2);
VERIFY_IS_APPROX_ABS(ei_matrix_cosh(A), (expA + expmA) / 2);
VERIFY_IS_APPROX_ABS(A.sinh(), (A.exp() - (-A).exp()) / 2);
VERIFY_IS_APPROX_ABS(A.cosh(), (A.exp() + (-A).exp()) / 2);
}
template<typename MatrixType>
@@ -143,15 +140,13 @@ void testGonioFunctions(const MatrixType& A)
ComplexMatrix Ac = A.template cast<ComplexScalar>();
ComplexMatrix exp_iA = ei_matrix_exponential(imagUnit * Ac);
ComplexMatrix exp_miA = ei_matrix_exponential(-imagUnit * Ac);
ComplexMatrix exp_iA = (imagUnit * Ac).exp();
ComplexMatrix exp_miA = (-imagUnit * Ac).exp();
MatrixType sinA = ei_matrix_sin(A);
ComplexMatrix sinAc = sinA.template cast<ComplexScalar>();
ComplexMatrix sinAc = A.sin().template cast<ComplexScalar>();
VERIFY_IS_APPROX_ABS(sinAc, (exp_iA - exp_miA) / (two*imagUnit));
MatrixType cosA = ei_matrix_cos(A);
ComplexMatrix cosAc = cosA.template cast<ComplexScalar>();
ComplexMatrix cosAc = A.cos().template cast<ComplexScalar>();
VERIFY_IS_APPROX_ABS(cosAc, (exp_iA + exp_miA) / 2);
}