| 15 | } |
| 16 | |
| 17 | template<typename MatrixType> void stable_norm(const MatrixType& m) |
| 18 | { |
| 19 | /* this test covers the following files: |
| 20 | StableNorm.h |
| 21 | */ |
| 22 | using std::sqrt; |
| 23 | using std::abs; |
| 24 | typedef typename MatrixType::Scalar Scalar; |
| 25 | typedef typename NumTraits<Scalar>::Real RealScalar; |
| 26 | |
| 27 | bool complex_real_product_ok = true; |
| 28 | |
| 29 | // Check the basic machine-dependent constants. |
| 30 | { |
| 31 | int ibeta, it, iemin, iemax; |
| 32 | |
| 33 | ibeta = std::numeric_limits<RealScalar>::radix; // base for floating-point numbers |
| 34 | it = std::numeric_limits<RealScalar>::digits; // number of base-beta digits in mantissa |
| 35 | iemin = std::numeric_limits<RealScalar>::min_exponent; // minimum exponent |
| 36 | iemax = std::numeric_limits<RealScalar>::max_exponent; // maximum exponent |
| 37 | |
| 38 | VERIFY( (!(iemin > 1 - 2*it || 1+it>iemax || (it==2 && ibeta<5) || (it<=4 && ibeta <= 3 ) || it<2)) |
| 39 | && "the stable norm algorithm cannot be guaranteed on this computer"); |
| 40 | |
| 41 | Scalar inf = std::numeric_limits<RealScalar>::infinity(); |
| 42 | if(NumTraits<Scalar>::IsComplex && (numext::isnan)(inf*RealScalar(1)) ) |
| 43 | { |
| 44 | complex_real_product_ok = false; |
| 45 | static bool first = true; |
| 46 | if(first) |
| 47 | std::cerr << "WARNING: compiler mess up complex*real product, " << inf << " * " << 1.0 << " = " << inf*RealScalar(1) << std::endl; |
| 48 | first = false; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | |
| 53 | Index rows = m.rows(); |
| 54 | Index cols = m.cols(); |
| 55 | |
| 56 | // get a non-zero random factor |
| 57 | Scalar factor = internal::random<Scalar>(); |
| 58 | while(numext::abs2(factor)<RealScalar(1e-4)) |
| 59 | factor = internal::random<Scalar>(); |
| 60 | Scalar big = factor * ((std::numeric_limits<RealScalar>::max)() * RealScalar(1e-4)); |
| 61 | |
| 62 | factor = internal::random<Scalar>(); |
| 63 | while(numext::abs2(factor)<RealScalar(1e-4)) |
| 64 | factor = internal::random<Scalar>(); |
| 65 | Scalar small = factor * ((std::numeric_limits<RealScalar>::min)() * RealScalar(1e4)); |
| 66 | |
| 67 | Scalar one(1); |
| 68 | |
| 69 | MatrixType vzero = MatrixType::Zero(rows, cols), |
| 70 | vrand = MatrixType::Random(rows, cols), |
| 71 | vbig(rows, cols), |
| 72 | vsmall(rows,cols); |
| 73 | |
| 74 | vbig.fill(big); |
no test coverage detected