mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-27 07:29:52 +08:00
Fixed most conversion warnings in MatrixFunctions module
This commit is contained in:
parent
6a510fe69c
commit
0ec8afde57
@ -72,10 +72,10 @@ MatrixType MatrixFunctionAtomic<MatrixType>::compute(const MatrixType& A)
|
||||
MatrixType F = m_f(avgEival, 0) * MatrixType::Identity(rows, rows);
|
||||
MatrixType P = Ashifted;
|
||||
MatrixType Fincr;
|
||||
for (Index s = 1; s < 1.1 * rows + 10; s++) { // upper limit is fairly arbitrary
|
||||
for (Index s = 1; double(s) < 1.1 * double(rows) + 10.0; s++) { // upper limit is fairly arbitrary
|
||||
Fincr = m_f(avgEival, static_cast<int>(s)) * P;
|
||||
F += Fincr;
|
||||
P = Scalar(RealScalar(1.0/(s + 1))) * P * Ashifted;
|
||||
P = Scalar(RealScalar(1)/RealScalar(s + 1)) * P * Ashifted;
|
||||
|
||||
// test whether Taylor series converged
|
||||
const RealScalar F_norm = F.cwiseAbs().rowwise().sum().maxCoeff();
|
||||
|
@ -62,8 +62,8 @@ void matrix_log_compute_2x2(const MatrixType& A, MatrixType& result)
|
||||
else
|
||||
{
|
||||
// computation in previous branch is inaccurate if A(1,1) \approx A(0,0)
|
||||
int unwindingNumber = static_cast<int>(ceil((imag(logA11 - logA00) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI)));
|
||||
result(0,1) = A(0,1) * (numext::log1p(y/A(0,0)) + Scalar(0,2*EIGEN_PI*unwindingNumber)) / y;
|
||||
RealScalar unwindingNumber = ceil((imag(logA11 - logA00) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI));
|
||||
result(0,1) = A(0,1) * (numext::log1p(y/A(0,0)) + Scalar(0,RealScalar(2*EIGEN_PI)*unwindingNumber)) / y;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,8 @@ void matrix_log_compute_pade(MatrixType& result, const MatrixType& T, int degree
|
||||
const int minPadeDegree = 3;
|
||||
const int maxPadeDegree = 11;
|
||||
assert(degree >= minPadeDegree && degree <= maxPadeDegree);
|
||||
|
||||
// FIXME this creates float-conversion-warnings if these are enabled.
|
||||
// Either manually convert each value, or disable the warning locally
|
||||
const RealScalar nodes[][maxPadeDegree] = {
|
||||
{ 0.1127016653792583114820734600217600L, 0.5000000000000000000000000000000000L, // degree 3
|
||||
0.8872983346207416885179265399782400L },
|
||||
@ -232,12 +233,13 @@ void matrix_log_compute_big(const MatrixType& A, MatrixType& result)
|
||||
int degree;
|
||||
MatrixType T = A, sqrtT;
|
||||
|
||||
int maxPadeDegree = matrix_log_max_pade_degree<Scalar>::value;
|
||||
const RealScalar maxNormForPade = maxPadeDegree<= 5? 5.3149729967117310e-1L: // single precision
|
||||
const int maxPadeDegree = matrix_log_max_pade_degree<Scalar>::value;
|
||||
const RealScalar maxNormForPade = RealScalar(
|
||||
maxPadeDegree<= 5? 5.3149729967117310e-1L: // single precision
|
||||
maxPadeDegree<= 7? 2.6429608311114350e-1L: // double precision
|
||||
maxPadeDegree<= 8? 2.32777776523703892094e-1L: // extended precision
|
||||
maxPadeDegree<=10? 1.05026503471351080481093652651105e-1L: // double-double
|
||||
1.1880960220216759245467951592883642e-1L; // quadruple precision
|
||||
1.1880960220216759245467951592883642e-1L); // quadruple precision
|
||||
|
||||
while (true) {
|
||||
RealScalar normTminusI = (T - MatrixType::Identity(T.rows(), T.rows())).cwiseAbs().colwise().sum().maxCoeff();
|
||||
@ -254,7 +256,7 @@ void matrix_log_compute_big(const MatrixType& A, MatrixType& result)
|
||||
}
|
||||
|
||||
matrix_log_compute_pade(result, T, degree);
|
||||
result *= pow(RealScalar(2), numberOfSquareRoots);
|
||||
result *= pow(RealScalar(2), RealScalar(numberOfSquareRoots)); // TODO replace by bitshift if possible
|
||||
}
|
||||
|
||||
/** \ingroup MatrixFunctions_Module
|
||||
|
@ -160,11 +160,11 @@ template<typename MatrixType>
|
||||
void MatrixPowerAtomic<MatrixType>::computePade(int degree, const MatrixType& IminusT, ResultType& res) const
|
||||
{
|
||||
int i = 2*degree;
|
||||
res = (m_p-degree) / (2*i-2) * IminusT;
|
||||
res = (m_p-RealScalar(degree)) / RealScalar(2*i-2) * IminusT;
|
||||
|
||||
for (--i; i; --i) {
|
||||
res = (MatrixType::Identity(IminusT.rows(), IminusT.cols()) + res).template triangularView<Upper>()
|
||||
.solve((i==1 ? -m_p : i&1 ? (-m_p-i/2)/(2*i) : (m_p-i/2)/(2*i-2)) * IminusT).eval();
|
||||
.solve((i==1 ? -m_p : i&1 ? (-m_p-RealScalar(i/2))/RealScalar(2*i) : (m_p-RealScalar(i/2))/RealScalar(2*i-2)) * IminusT).eval();
|
||||
}
|
||||
res += MatrixType::Identity(IminusT.rows(), IminusT.cols());
|
||||
}
|
||||
@ -194,11 +194,12 @@ void MatrixPowerAtomic<MatrixType>::computeBig(ResultType& res) const
|
||||
{
|
||||
using std::ldexp;
|
||||
const int digits = std::numeric_limits<RealScalar>::digits;
|
||||
const RealScalar maxNormForPade = digits <= 24? 4.3386528e-1L // single precision
|
||||
const RealScalar maxNormForPade = RealScalar(
|
||||
digits <= 24? 4.3386528e-1L // single precision
|
||||
: digits <= 53? 2.789358995219730e-1L // double precision
|
||||
: digits <= 64? 2.4471944416607995472e-1L // extended precision
|
||||
: digits <= 106? 1.1016843812851143391275867258512e-1L // double-double
|
||||
: 9.134603732914548552537150753385375e-2L; // quadruple precision
|
||||
: 9.134603732914548552537150753385375e-2L); // quadruple precision
|
||||
MatrixType IminusT, sqrtT, T = m_A.template triangularView<Upper>();
|
||||
RealScalar normIminusT;
|
||||
int degree, degree2, numberOfSquareRoots = 0;
|
||||
@ -296,8 +297,8 @@ MatrixPowerAtomic<MatrixType>::computeSuperDiag(const ComplexScalar& curr, const
|
||||
|
||||
ComplexScalar logCurr = log(curr);
|
||||
ComplexScalar logPrev = log(prev);
|
||||
int unwindingNumber = ceil((numext::imag(logCurr - logPrev) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI));
|
||||
ComplexScalar w = numext::log1p((curr-prev)/prev)/RealScalar(2) + ComplexScalar(0, EIGEN_PI*unwindingNumber);
|
||||
RealScalar unwindingNumber = ceil((numext::imag(logCurr - logPrev) - RealScalar(EIGEN_PI)) / RealScalar(2*EIGEN_PI));
|
||||
ComplexScalar w = numext::log1p((curr-prev)/prev)/RealScalar(2) + ComplexScalar(0, RealScalar(EIGEN_PI)*unwindingNumber);
|
||||
return RealScalar(2) * exp(RealScalar(0.5) * p * (logCurr + logPrev)) * sinh(p * w) / (curr - prev);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ void test2dRotation(const T& tol)
|
||||
MatrixPower<Matrix<T,2,2> > Apow(A);
|
||||
|
||||
for (int i=0; i<=20; ++i) {
|
||||
angle = std::pow(T(10), (i-10) / T(5.));
|
||||
angle = std::pow(T(10), T(i-10) / T(5.));
|
||||
c = std::cos(angle);
|
||||
s = std::sin(angle);
|
||||
B << c, s, -s, c;
|
||||
@ -61,7 +61,7 @@ void test3dRotation(const T& tol)
|
||||
for (int i=0; i<=20; ++i) {
|
||||
v = Matrix<T,3,1>::Random();
|
||||
v.normalize();
|
||||
angle = std::pow(T(10), (i-10) / T(5.));
|
||||
angle = std::pow(T(10), T(i-10) / T(5.));
|
||||
VERIFY(AngleAxis<T>(angle, v).matrix().isApprox(AngleAxis<T>(1,v).matrix().pow(angle), tol));
|
||||
}
|
||||
}
|
||||
@ -153,52 +153,52 @@ typedef Matrix<long double,Dynamic,Dynamic> MatrixXe;
|
||||
EIGEN_DECLARE_TEST(matrix_power)
|
||||
{
|
||||
CALL_SUBTEST_2(test2dRotation<double>(1e-13));
|
||||
CALL_SUBTEST_1(test2dRotation<float>(2e-5)); // was 1e-5, relaxed for clang 2.8 / linux / x86-64
|
||||
CALL_SUBTEST_1(test2dRotation<float>(2e-5f)); // was 1e-5, relaxed for clang 2.8 / linux / x86-64
|
||||
CALL_SUBTEST_9(test2dRotation<long double>(1e-13L));
|
||||
CALL_SUBTEST_2(test2dHyperbolicRotation<double>(1e-14));
|
||||
CALL_SUBTEST_1(test2dHyperbolicRotation<float>(1e-5));
|
||||
CALL_SUBTEST_1(test2dHyperbolicRotation<float>(1e-5f));
|
||||
CALL_SUBTEST_9(test2dHyperbolicRotation<long double>(1e-14L));
|
||||
|
||||
CALL_SUBTEST_10(test3dRotation<double>(1e-13));
|
||||
CALL_SUBTEST_11(test3dRotation<float>(1e-5));
|
||||
CALL_SUBTEST_11(test3dRotation<float>(1e-5f));
|
||||
CALL_SUBTEST_12(test3dRotation<long double>(1e-13L));
|
||||
|
||||
CALL_SUBTEST_2(testGeneral(Matrix2d(), 1e-13));
|
||||
CALL_SUBTEST_7(testGeneral(Matrix3dRowMajor(), 1e-13));
|
||||
CALL_SUBTEST_3(testGeneral(Matrix4cd(), 1e-13));
|
||||
CALL_SUBTEST_4(testGeneral(MatrixXd(8,8), 2e-12));
|
||||
CALL_SUBTEST_1(testGeneral(Matrix2f(), 1e-4));
|
||||
CALL_SUBTEST_5(testGeneral(Matrix3cf(), 1e-4));
|
||||
CALL_SUBTEST_8(testGeneral(Matrix4f(), 1e-4));
|
||||
CALL_SUBTEST_6(testGeneral(MatrixXf(2,2), 1e-3)); // see bug 614
|
||||
CALL_SUBTEST_1(testGeneral(Matrix2f(), 1e-4f));
|
||||
CALL_SUBTEST_5(testGeneral(Matrix3cf(), 1e-4f));
|
||||
CALL_SUBTEST_8(testGeneral(Matrix4f(), 1e-4f));
|
||||
CALL_SUBTEST_6(testGeneral(MatrixXf(2,2), 1e-3f)); // see bug 614
|
||||
CALL_SUBTEST_9(testGeneral(MatrixXe(7,7), 1e-13L));
|
||||
CALL_SUBTEST_10(testGeneral(Matrix3d(), 1e-13));
|
||||
CALL_SUBTEST_11(testGeneral(Matrix3f(), 1e-4));
|
||||
CALL_SUBTEST_11(testGeneral(Matrix3f(), 1e-4f));
|
||||
CALL_SUBTEST_12(testGeneral(Matrix3e(), 1e-13L));
|
||||
|
||||
CALL_SUBTEST_2(testSingular(Matrix2d(), 1e-13));
|
||||
CALL_SUBTEST_7(testSingular(Matrix3dRowMajor(), 1e-13));
|
||||
CALL_SUBTEST_3(testSingular(Matrix4cd(), 1e-13));
|
||||
CALL_SUBTEST_4(testSingular(MatrixXd(8,8), 2e-12));
|
||||
CALL_SUBTEST_1(testSingular(Matrix2f(), 1e-4));
|
||||
CALL_SUBTEST_5(testSingular(Matrix3cf(), 1e-4));
|
||||
CALL_SUBTEST_8(testSingular(Matrix4f(), 1e-4));
|
||||
CALL_SUBTEST_6(testSingular(MatrixXf(2,2), 1e-3));
|
||||
CALL_SUBTEST_1(testSingular(Matrix2f(), 1e-4f));
|
||||
CALL_SUBTEST_5(testSingular(Matrix3cf(), 1e-4f));
|
||||
CALL_SUBTEST_8(testSingular(Matrix4f(), 1e-4f));
|
||||
CALL_SUBTEST_6(testSingular(MatrixXf(2,2), 1e-3f));
|
||||
CALL_SUBTEST_9(testSingular(MatrixXe(7,7), 1e-13L));
|
||||
CALL_SUBTEST_10(testSingular(Matrix3d(), 1e-13));
|
||||
CALL_SUBTEST_11(testSingular(Matrix3f(), 1e-4));
|
||||
CALL_SUBTEST_11(testSingular(Matrix3f(), 1e-4f));
|
||||
CALL_SUBTEST_12(testSingular(Matrix3e(), 1e-13L));
|
||||
|
||||
CALL_SUBTEST_2(testLogThenExp(Matrix2d(), 1e-13));
|
||||
CALL_SUBTEST_7(testLogThenExp(Matrix3dRowMajor(), 1e-13));
|
||||
CALL_SUBTEST_3(testLogThenExp(Matrix4cd(), 1e-13));
|
||||
CALL_SUBTEST_4(testLogThenExp(MatrixXd(8,8), 2e-12));
|
||||
CALL_SUBTEST_1(testLogThenExp(Matrix2f(), 1e-4));
|
||||
CALL_SUBTEST_5(testLogThenExp(Matrix3cf(), 1e-4));
|
||||
CALL_SUBTEST_8(testLogThenExp(Matrix4f(), 1e-4));
|
||||
CALL_SUBTEST_6(testLogThenExp(MatrixXf(2,2), 1e-3));
|
||||
CALL_SUBTEST_1(testLogThenExp(Matrix2f(), 1e-4f));
|
||||
CALL_SUBTEST_5(testLogThenExp(Matrix3cf(), 1e-4f));
|
||||
CALL_SUBTEST_8(testLogThenExp(Matrix4f(), 1e-4f));
|
||||
CALL_SUBTEST_6(testLogThenExp(MatrixXf(2,2), 1e-3f));
|
||||
CALL_SUBTEST_9(testLogThenExp(MatrixXe(7,7), 1e-13L));
|
||||
CALL_SUBTEST_10(testLogThenExp(Matrix3d(), 1e-13));
|
||||
CALL_SUBTEST_11(testLogThenExp(Matrix3f(), 1e-4));
|
||||
CALL_SUBTEST_11(testLogThenExp(Matrix3f(), 1e-4f));
|
||||
CALL_SUBTEST_12(testLogThenExp(Matrix3e(), 1e-13L));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user