Adaptions from .lazy() towards .noalias().

Added missing casts.
This commit is contained in:
Hauke Heibel
2009-08-31 17:29:37 +02:00
parent bc7aec0ef5
commit ab6eb6a1a4
8 changed files with 54 additions and 52 deletions

View File

@@ -90,9 +90,9 @@ namespace MatrixExponentialInternal {
{
typedef typename ei_traits<MatrixType>::Scalar Scalar;
const Scalar b[] = {120., 60., 12., 1.};
M2 = (M * M).lazy();
M2.noalias() = M * M;
tmp = b[3]*M2 + b[1]*Id;
U = (M * tmp).lazy();
U.noalias() = M * tmp;
V = b[2]*M2 + b[0]*Id;
}
@@ -115,10 +115,10 @@ namespace MatrixExponentialInternal {
{
typedef typename ei_traits<MatrixType>::Scalar Scalar;
const Scalar b[] = {30240., 15120., 3360., 420., 30., 1.};
M2 = (M * M).lazy();
MatrixType M4 = (M2 * M2).lazy();
M2.noalias() = M * M;
MatrixType M4 = M2 * M2;
tmp = b[5]*M4 + b[3]*M2 + b[1]*Id;
U = (M * tmp).lazy();
U.noalias() = M * tmp;
V = b[4]*M4 + b[2]*M2 + b[0]*Id;
}
@@ -141,11 +141,11 @@ namespace MatrixExponentialInternal {
{
typedef typename ei_traits<MatrixType>::Scalar Scalar;
const Scalar b[] = {17297280., 8648640., 1995840., 277200., 25200., 1512., 56., 1.};
M2 = (M * M).lazy();
MatrixType M4 = (M2 * M2).lazy();
MatrixType M6 = (M4 * M2).lazy();
M2.noalias() = M * M;
MatrixType M4 = M2 * M2;
MatrixType M6 = M4 * M2;
tmp = b[7]*M6 + b[5]*M4 + b[3]*M2 + b[1]*Id;
U = (M * tmp).lazy();
U.noalias() = M * tmp;
V = b[6]*M6 + b[4]*M4 + b[2]*M2 + b[0]*Id;
}
@@ -169,12 +169,12 @@ namespace MatrixExponentialInternal {
typedef typename ei_traits<MatrixType>::Scalar Scalar;
const Scalar b[] = {17643225600., 8821612800., 2075673600., 302702400., 30270240.,
2162160., 110880., 3960., 90., 1.};
M2 = (M * M).lazy();
MatrixType M4 = (M2 * M2).lazy();
MatrixType M6 = (M4 * M2).lazy();
MatrixType M8 = (M6 * M2).lazy();
M2.noalias() = M * M;
MatrixType M4 = M2 * M2;
MatrixType M6 = M4 * M2;
MatrixType M8 = M6 * M2;
tmp = b[9]*M8 + b[7]*M6 + b[5]*M4 + b[3]*M2 + b[1]*Id;
U = (M * tmp).lazy();
U.noalias() = M * tmp;
V = b[8]*M8 + b[6]*M6 + b[4]*M4 + b[2]*M2 + b[0]*Id;
}
@@ -199,15 +199,15 @@ namespace MatrixExponentialInternal {
const Scalar b[] = {64764752532480000., 32382376266240000., 7771770303897600.,
1187353796428800., 129060195264000., 10559470521600., 670442572800.,
33522128640., 1323241920., 40840800., 960960., 16380., 182., 1.};
M2 = (M * M).lazy();
MatrixType M4 = (M2 * M2).lazy();
MatrixType M6 = (M4 * M2).lazy();
M2.noalias() = M * M;
MatrixType M4 = M2 * M2;
MatrixType M6 = M4 * M2;
V = b[13]*M6 + b[11]*M4 + b[9]*M2;
tmp = (M6 * V).lazy();
tmp.noalias() = M6 * V;
tmp += b[7]*M6 + b[5]*M4 + b[3]*M2 + b[1]*Id;
U = (M * tmp).lazy();
U.noalias() = M * tmp;
tmp = b[12]*M6 + b[10]*M4 + b[8]*M2;
V = (M6 * tmp).lazy();
V.noalias() = M6 * tmp;
V += b[6]*M6 + b[4]*M4 + b[2]*M2 + b[0]*Id;
}
@@ -252,7 +252,7 @@ namespace MatrixExponentialInternal {
} else if (l1norm < 1.880152677804762e+000) {
pade5(M, Id, tmp1, tmp2, U, V);
} else {
const float maxnorm = 3.925724783138660;
const float maxnorm = 3.925724783138660f;
*squarings = std::max(0, (int)ceil(log2(l1norm / maxnorm)));
MatrixType A = M / std::pow(typename ei_traits<MatrixType>::Scalar(2), *squarings);
pade7(A, Id, tmp1, tmp2, U, V);
@@ -294,7 +294,7 @@ namespace MatrixExponentialInternal {
{
MatrixType num, den, U, V;
MatrixType Id = MatrixType::Identity(M.rows(), M.cols());
float l1norm = M.cwise().abs().colwise().sum().maxCoeff();
float l1norm = static_cast<float>(M.cwise().abs().colwise().sum().maxCoeff());
int squarings;
computeUV_selector<MatrixType>::run(M, Id, num, den, U, V, l1norm, &squarings);
num = U + V; // numerator of Pade approximant

View File

@@ -43,10 +43,10 @@ void test2dRotation(double tol)
A << 0, 1, -1, 0;
for (int i=0; i<=20; i++)
{
angle = pow(10, i / 5. - 2);
angle = static_cast<T>(pow(10, i / 5. - 2));
B << cos(angle), sin(angle), -sin(angle), cos(angle);
ei_matrix_exponential(angle*A, &C);
VERIFY(C.isApprox(B, tol));
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
}
@@ -59,13 +59,13 @@ void test2dHyperbolicRotation(double tol)
for (int i=0; i<=20; i++)
{
angle = (i-10) / 2.0;
angle = static_cast<T>((i-10) / 2.0);
ch = std::cosh(angle);
sh = std::sinh(angle);
A << 0, angle*imagUnit, -angle*imagUnit, 0;
B << ch, sh*imagUnit, -sh*imagUnit, ch;
ei_matrix_exponential(A, &C);
VERIFY(C.isApprox(B, tol));
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
}
@@ -77,13 +77,13 @@ void testPascal(double tol)
Matrix<T,Dynamic,Dynamic> A(size,size), B(size,size), C(size,size);
A.setZero();
for (int i=0; i<size-1; i++)
A(i+1,i) = i+1;
A(i+1,i) = static_cast<T>(i+1);
B.setZero();
for (int i=0; i<size; i++)
for (int j=0; j<=i; j++)
B(i,j) = binom(i,j);
B(i,j) = static_cast<T>(binom(i,j));
ei_matrix_exponential(A, &C);
VERIFY(C.isApprox(B, tol));
VERIFY(C.isApprox(B, static_cast<T>(tol)));
}
}
@@ -98,11 +98,13 @@ void randomTest(const MatrixType& m, double tol)
MatrixType m1(rows, cols), m2(rows, cols), m3(rows, cols),
identity = MatrixType::Identity(rows, rows);
typedef typename NumTraits<typename ei_traits<MatrixType>::Scalar>::Real RealScalar;
for(int i = 0; i < g_repeat; i++) {
m1 = MatrixType::Random(rows, cols);
ei_matrix_exponential(m1, &m2);
ei_matrix_exponential(-m1, &m3);
VERIFY(identity.isApprox(m2 * m3, tol));
VERIFY(identity.isApprox(m2 * m3, static_cast<RealScalar>(tol)));
}
}