diff --git a/test/nullary.cpp b/test/nullary.cpp index 3adfc33fe..6e91ddd52 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -51,8 +51,8 @@ void testVectorType(const VectorType& base) { typedef typename ei_traits::Scalar Scalar; Scalar low = ei_random(-500,500); - Scalar high = ei_random(-500,500); - if (low>high) std::swap(low,high); + Scalar high = ei_random(-500,500); + if (low>high) std::swap(low,high); const int size = base.size(); const Scalar step = (high-low)/(size-1); @@ -91,7 +91,7 @@ void testVectorType(const VectorType& base) Matrix size_changer(size+50); size_changer.setLinSpaced(low,high,size); - VERIFY( size_changer.size() == size ); + VERIFY( size_changer.size() == size ); } template diff --git a/test/stable_norm.cpp b/test/stable_norm.cpp index b0c6e0183..a308b34eb 100644 --- a/test/stable_norm.cpp +++ b/test/stable_norm.cpp @@ -24,6 +24,11 @@ #include "main.h" +template bool isFinite(const T& x) +{ + return x==x && x>=NumTraits::lowest() && x<=NumTraits::highest(); +} + template void stable_norm(const MatrixType& m) { /* this test covers the following files: @@ -50,7 +55,7 @@ template void stable_norm(const MatrixType& m) int rows = m.rows(); int cols = m.cols(); - Scalar big = ei_abs(ei_random()) * (std::numeric_limits::max() * RealScalar(1e-4)); + Scalar big = ei_random()) * (std::numeric_limits::max() * RealScalar(1e-4); Scalar small = static_cast(1)/big; MatrixType vzero = MatrixType::Zero(rows, cols), @@ -68,22 +73,36 @@ template void stable_norm(const MatrixType& m) RealScalar size = static_cast(m.size()); - // test overflow -/* VERIFY_IS_NOT_APPROX(static_cast(vbig.norm()), ei_sqrt(size)*big); // here the default norm must fail - Does not succeed on gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1, Intel Core 2 Duo T7300 with no SSE optimizations -*/ + // test isFinite + VERIFY(!isFinite( ei_abs(big)/RealScalar(0))); + VERIFY(!isFinite(-ei_abs(big)/RealScalar(0))); + VERIFY(!isFinite(ei_sqrt(-ei_abs(big)))); - VERIFY_IS_APPROX(static_cast(vbig.stableNorm()), ei_sqrt(size)*big); - VERIFY_IS_APPROX(static_cast(vbig.blueNorm()), ei_sqrt(size)*big); - VERIFY_IS_APPROX(static_cast(vbig.hypotNorm()), ei_sqrt(size)*big); + // test overflow + VERIFY(isFinite(ei_sqrt(size)*ei_abs(big))); + #ifdef EIGEN_VECTORIZE_SSE + // since x87 FPU uses 80bits of precision overflow is not detected + if(ei_packet_traits::size>1) + { + VERIFY_IS_NOT_APPROX(static_cast(vbig.norm()), ei_sqrt(size)*big); // here the default norm must fail + } + #endif + VERIFY_IS_APPROX(vbig.stableNorm(), ei_sqrt(size)*ei_abs(big)); + VERIFY_IS_APPROX(vbig.blueNorm(), ei_sqrt(size)*ei_abs(big)); + VERIFY_IS_APPROX(vbig.hypotNorm(), ei_sqrt(size)*ei_abs(big)); // test underflow -/* VERIFY_IS_NOT_APPROX(static_cast(vsmall.norm()), ei_sqrt(size)*small); // here the default norm must fail - Does not succeed on gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1, Intel Core 2 Duo T7300 with no SSE optimizations -*/ - VERIFY_IS_APPROX(static_cast(vsmall.stableNorm()), ei_sqrt(size)*small); - VERIFY_IS_APPROX(static_cast(vsmall.blueNorm()), ei_sqrt(size)*small); - VERIFY_IS_APPROX(static_cast(vsmall.hypotNorm()), ei_sqrt(size)*small); + VERIFY(isFinite(ei_sqrt(size)*ei_abs(small))); + #ifdef EIGEN_VECTORIZE_SSE + // since x87 FPU uses 80bits of precision underflow is not detected + if(ei_packet_traits::size>1) + { + VERIFY_IS_NOT_APPROX(static_cast(vsmall.norm()), ei_sqrt(size)*small); // here the default norm must fail + } + #endif + VERIFY_IS_APPROX(vsmall.stableNorm(), ei_sqrt(size)*ei_abs(small)); + VERIFY_IS_APPROX(vsmall.blueNorm(), ei_sqrt(size)*ei_abs(small)); + VERIFY_IS_APPROX(vsmall.hypotNorm(), ei_sqrt(size)*ei_abs(small)); // Test compilation of cwise() version VERIFY_IS_APPROX(vrand.colwise().stableNorm(), vrand.colwise().norm());