mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Enable and fix -Wdouble-conversion warnings
This commit is contained in:
@@ -49,7 +49,7 @@ void check_inf_nan(bool dryrun) {
|
||||
VERIFY( !m.allFinite() );
|
||||
VERIFY( m.hasNaN() );
|
||||
}
|
||||
m(4) /= 0.0;
|
||||
m(4) /= T(0.0);
|
||||
if(dryrun)
|
||||
{
|
||||
std::cout << "std::isfinite(" << m(4) << ") = "; check((std::isfinite)(m(4)),false); std::cout << " ; numext::isfinite = "; check((numext::isfinite)(m(4)), false); std::cout << "\n";
|
||||
|
||||
@@ -97,9 +97,9 @@ template<typename Scalar> void lines()
|
||||
Vector u = Vector::Random();
|
||||
Vector v = Vector::Random();
|
||||
Scalar a = internal::random<Scalar>();
|
||||
while (abs(a-1) < 1e-4) a = internal::random<Scalar>();
|
||||
while (u.norm() < 1e-4) u = Vector::Random();
|
||||
while (v.norm() < 1e-4) v = Vector::Random();
|
||||
while (abs(a-1) < Scalar(1e-4)) a = internal::random<Scalar>();
|
||||
while (u.norm() < Scalar(1e-4)) u = Vector::Random();
|
||||
while (v.norm() < Scalar(1e-4)) v = Vector::Random();
|
||||
|
||||
HLine line_u = HLine::Through(center + u, center + a*u);
|
||||
HLine line_v = HLine::Through(center + v, center + a*v);
|
||||
@@ -111,14 +111,14 @@ template<typename Scalar> void lines()
|
||||
Vector result = line_u.intersection(line_v);
|
||||
|
||||
// the lines should intersect at the point we called "center"
|
||||
if(abs(a-1) > 1e-2 && abs(v.normalized().dot(u.normalized()))<0.9)
|
||||
if(abs(a-1) > Scalar(1e-2) && abs(v.normalized().dot(u.normalized()))<Scalar(0.9))
|
||||
VERIFY_IS_APPROX(result, center);
|
||||
|
||||
// check conversions between two types of lines
|
||||
PLine pl(line_u); // gcc 3.3 will commit suicide if we don't name this variable
|
||||
HLine line_u2(pl);
|
||||
CoeffsType converted_coeffs = line_u2.coeffs();
|
||||
if(line_u2.normal().dot(line_u.normal())<0.)
|
||||
if(line_u2.normal().dot(line_u.normal())<Scalar(0))
|
||||
converted_coeffs = -line_u2.coeffs();
|
||||
VERIFY(line_u.coeffs().isApprox(converted_coeffs));
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ template<typename QuatType> void check_slerp(const QuatType& q0, const QuatType&
|
||||
Scalar largeEps = test_precision<Scalar>();
|
||||
|
||||
Scalar theta_tot = AA(q1*q0.inverse()).angle();
|
||||
if(theta_tot>EIGEN_PI)
|
||||
if(theta_tot>Scalar(EIGEN_PI))
|
||||
theta_tot = Scalar(2.*EIGEN_PI)-theta_tot;
|
||||
for(Scalar t=0; t<=Scalar(1.001); t+=Scalar(0.1))
|
||||
{
|
||||
@@ -115,8 +115,8 @@ template<typename Scalar, int Options> void quaternion(void)
|
||||
// Do not execute the test if the rotation angle is almost zero, or
|
||||
// the rotation axis and v1 are almost parallel.
|
||||
if (abs(aa.angle()) > 5*test_precision<Scalar>()
|
||||
&& (aa.axis() - v1.normalized()).norm() < 1.99
|
||||
&& (aa.axis() + v1.normalized()).norm() < 1.99)
|
||||
&& (aa.axis() - v1.normalized()).norm() < Scalar(1.99)
|
||||
&& (aa.axis() + v1.normalized()).norm() < Scalar(1.99))
|
||||
{
|
||||
VERIFY_IS_NOT_APPROX(q1 * v1, Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1);
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ template<typename Scalar, int Mode, int Options> void transformations()
|
||||
Scalar a2 = R0.slerp(Scalar(k+1)/Scalar(path_steps), R1).angle();
|
||||
l += std::abs(a2-a1);
|
||||
}
|
||||
VERIFY(l<=EIGEN_PI*(Scalar(1)+NumTraits<Scalar>::epsilon()*Scalar(path_steps/2)));
|
||||
VERIFY(l<=Scalar(EIGEN_PI)*(Scalar(1)+NumTraits<Scalar>::epsilon()*Scalar(path_steps/2)));
|
||||
|
||||
// check basic features
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
|
||||
*/
|
||||
typedef typename MatrixType::Index Index;
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::RealScalar RealScalar;
|
||||
|
||||
Index rows = m.rows();
|
||||
Index cols = m.cols();
|
||||
@@ -32,7 +33,7 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
|
||||
m3(rows, cols);
|
||||
|
||||
Scalar s1 = internal::random<Scalar>();
|
||||
while (abs(s1)<1e-3) s1 = internal::random<Scalar>();
|
||||
while (abs(s1)<RealScalar(1e-3)) s1 = internal::random<Scalar>();
|
||||
|
||||
Index r = internal::random<Index>(0, rows-1),
|
||||
c = internal::random<Index>(0, cols-1);
|
||||
|
||||
@@ -387,7 +387,7 @@ template<typename Scalar> void packetmath_real()
|
||||
data2[i] = internal::random<Scalar>(0,1) * std::pow(Scalar(10), internal::random<Scalar>(-6,6));
|
||||
}
|
||||
|
||||
if(internal::random<float>(0,1)<0.1)
|
||||
if(internal::random<float>(0,1)<0.1f)
|
||||
data1[internal::random<int>(0, PacketSize)] = 0;
|
||||
CHECK_CWISE1_IF(PacketTraits::HasSqrt, std::sqrt, internal::psqrt);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasLog, std::log, internal::plog);
|
||||
|
||||
@@ -206,7 +206,7 @@ template<typename MatrixType> void qr_kahan_matrix()
|
||||
RealScalar c = std::sqrt(1 - s*s);
|
||||
for (Index i = 0; i < rows; ++i) {
|
||||
m1(i, i) = pow(s, i);
|
||||
m1.row(i).tail(rows - i - 1) = -pow(s, i) * c * MatrixType::Ones(1, rows - i - 1);
|
||||
m1.row(i).tail(rows - i - 1) = -RealScalar(pow(s, i)) * c * MatrixType::Ones(1, rows - i - 1);
|
||||
}
|
||||
m1 = (m1 + m1.transpose()).eval();
|
||||
ColPivHouseholderQR<MatrixType> qr(m1);
|
||||
|
||||
@@ -232,11 +232,11 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
for (Index i=0; i<m2.rows(); ++i)
|
||||
{
|
||||
float x = internal::random<float>(0,1);
|
||||
if (x<0.1)
|
||||
if (x<0.1f)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
else if (x<0.5)
|
||||
else if (x<0.5f)
|
||||
{
|
||||
countFalseNonZero++;
|
||||
m2.insert(i,j) = Scalar(0);
|
||||
|
||||
@@ -150,7 +150,7 @@ template<typename SparseMatrixType> void sparse_block(const SparseMatrixType& re
|
||||
DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
|
||||
SparseMatrixType m2(rows, cols);
|
||||
initSparse<Scalar>(density, refMat2, m2);
|
||||
if(internal::random<float>(0,1)>0.5) m2.makeCompressed();
|
||||
if(internal::random<float>(0,1)>0.5f) m2.makeCompressed();
|
||||
Index j0 = internal::random<Index>(0,outer-2);
|
||||
Index j1 = internal::random<Index>(0,outer-2);
|
||||
Index n0 = internal::random<Index>(1,outer-(std::max)(j0,j1));
|
||||
|
||||
@@ -245,7 +245,7 @@ template<typename SparseMatrixType> void sparse_product()
|
||||
for (int k=0; k<mS.outerSize(); ++k)
|
||||
for (typename SparseMatrixType::InnerIterator it(mS,k); it; ++it)
|
||||
if (it.index() == k)
|
||||
it.valueRef() *= 0.5;
|
||||
it.valueRef() *= Scalar(0.5);
|
||||
|
||||
VERIFY_IS_APPROX(refS.adjoint(), refS);
|
||||
VERIFY_IS_APPROX(mS.adjoint(), mS);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
template<typename Scalar,typename StorageIndex> void sparse_vector(int rows, int cols)
|
||||
{
|
||||
double densityMat = (std::max)(8./(rows*cols), 0.01);
|
||||
double densityVec = (std::max)(8./float(rows), 0.1);
|
||||
double densityVec = (std::max)(8./(rows), 0.1);
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
|
||||
typedef Matrix<Scalar,Dynamic,1> DenseVector;
|
||||
typedef SparseVector<Scalar,0,StorageIndex> SparseVectorType;
|
||||
|
||||
@@ -54,7 +54,7 @@ template<typename Scalar> void test_sparseqr_scalar()
|
||||
|
||||
b = dA * DenseVector::Random(A.cols());
|
||||
solver.compute(A);
|
||||
if(internal::random<float>(0,1)>0.5)
|
||||
if(internal::random<float>(0,1)>0.5f)
|
||||
solver.factorize(A); // this checks that calling analyzePattern is not needed if the pattern do not change.
|
||||
if (solver.info() != Success)
|
||||
{
|
||||
|
||||
@@ -141,14 +141,14 @@ void svd_least_square(const MatrixType& m, unsigned int computationOptions)
|
||||
using std::abs;
|
||||
|
||||
SolutionType y(x);
|
||||
y.row(k) = (1.+2*NumTraits<RealScalar>::epsilon())*x.row(k);
|
||||
y.row(k) = (RealScalar(1)+2*NumTraits<RealScalar>::epsilon())*x.row(k);
|
||||
RealScalar residual_y = (m*y-rhs).norm();
|
||||
VERIFY( test_isMuchSmallerThan(abs(residual_y-residual), rhs_norm) || residual < residual_y );
|
||||
if(internal::is_same<RealScalar,float>::value) ++g_test_level;
|
||||
VERIFY( test_isApprox(residual_y,residual) || residual < residual_y );
|
||||
if(internal::is_same<RealScalar,float>::value) --g_test_level;
|
||||
|
||||
y.row(k) = (1.-2*NumTraits<RealScalar>::epsilon())*x.row(k);
|
||||
y.row(k) = (RealScalar(1)-2*NumTraits<RealScalar>::epsilon())*x.row(k);
|
||||
residual_y = (m*y-rhs).norm();
|
||||
VERIFY( test_isMuchSmallerThan(abs(residual_y-residual), rhs_norm) || residual < residual_y );
|
||||
if(internal::is_same<RealScalar,float>::value) ++g_test_level;
|
||||
|
||||
@@ -54,7 +54,7 @@ void svd_fill_random(MatrixType &m, int Option = 0)
|
||||
}
|
||||
|
||||
Matrix<Scalar,Dynamic,1> samples(7);
|
||||
samples << 0, 5.60844e-313, -5.60844e-313, 4.94e-324, -4.94e-324, -1./NumTraits<RealScalar>::highest(), 1./NumTraits<RealScalar>::highest();
|
||||
samples << 0, 5.60844e-313, -5.60844e-313, 4.94e-324, -4.94e-324, -RealScalar(1)/NumTraits<RealScalar>::highest(), RealScalar(1)/NumTraits<RealScalar>::highest();
|
||||
|
||||
if(Option==Symmetric)
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ template<typename MatrixType> void triangular_square(const MatrixType& m)
|
||||
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
for (int i=0; i<rows; ++i)
|
||||
while (numext::abs2(m1(i,i))<1e-1) m1(i,i) = internal::random<Scalar>();
|
||||
while (numext::abs2(m1(i,i))<RealScalar(1e-1)) m1(i,i) = internal::random<Scalar>();
|
||||
|
||||
Transpose<MatrixType> trm4(m4);
|
||||
// test back and forward subsitution with a vector as the rhs
|
||||
@@ -78,7 +78,7 @@ template<typename MatrixType> void triangular_square(const MatrixType& m)
|
||||
m3 = m1.template triangularView<Lower>();
|
||||
VERIFY(v2.isApprox(m3.conjugate() * (m1.conjugate().template triangularView<Lower>().solve(v2)), largerEps));
|
||||
|
||||
// test back and forward subsitution with a matrix as the rhs
|
||||
// test back and forward substitution with a matrix as the rhs
|
||||
m3 = m1.template triangularView<Upper>();
|
||||
VERIFY(m2.isApprox(m3.adjoint() * (m1.adjoint().template triangularView<Lower>().solve(m2)), largerEps));
|
||||
m3 = m1.template triangularView<Lower>();
|
||||
|
||||
Reference in New Issue
Block a user