mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-25 18:50:40 +08:00
Fix failures in redux test caused by underflow in .prod() test.
This commit is contained in:
parent
9e667e28f5
commit
9bf4d709e4
@ -35,6 +35,10 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
|
||||
|
||||
MatrixType m1 = MatrixType::Random(rows, cols);
|
||||
|
||||
// The entries of m1 are uniformly distributed in [0,1], so m1.prod() is very small. This may lead to test
|
||||
// failures if we underflow into denormals. Thus, we scale so that entires are close to 1.
|
||||
MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + Scalar(0.2) * m1;
|
||||
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows, cols).sum(), Scalar(1));
|
||||
VERIFY_IS_APPROX(MatrixType::Ones(rows, cols).sum(), Scalar(float(rows*cols))); // the float() here to shut up excessive MSVC warning about int->complex conversion being lossy
|
||||
Scalar s(0), p(1), minc(internal::real(m1.coeff(0))), maxc(internal::real(m1.coeff(0)));
|
||||
@ -42,7 +46,7 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
|
||||
for(int i = 0; i < rows; i++)
|
||||
{
|
||||
s += m1(i,j);
|
||||
p *= m1(i,j);
|
||||
p *= m1_for_prod(i,j);
|
||||
minc = (std::min)(internal::real(minc), internal::real(m1(i,j)));
|
||||
maxc = (std::max)(internal::real(maxc), internal::real(m1(i,j)));
|
||||
}
|
||||
@ -50,7 +54,7 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
|
||||
|
||||
VERIFY_IS_APPROX(m1.sum(), s);
|
||||
VERIFY_IS_APPROX(m1.mean(), mean);
|
||||
VERIFY_IS_APPROX(m1.prod(), p);
|
||||
VERIFY_IS_APPROX(m1_for_prod.prod(), p);
|
||||
VERIFY_IS_APPROX(m1.real().minCoeff(), internal::real(minc));
|
||||
VERIFY_IS_APPROX(m1.real().maxCoeff(), internal::real(maxc));
|
||||
|
||||
@ -61,7 +65,7 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
|
||||
Index c1 = internal::random<Index>(c0+1,cols)-c0;
|
||||
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).sum(), m1.block(r0,c0,r1,c1).eval().sum());
|
||||
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).mean(), m1.block(r0,c0,r1,c1).eval().mean());
|
||||
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).prod(), m1.block(r0,c0,r1,c1).eval().prod());
|
||||
VERIFY_IS_APPROX(m1_for_prod.block(r0,c0,r1,c1).prod(), m1_for_prod.block(r0,c0,r1,c1).eval().prod());
|
||||
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().minCoeff(), m1.block(r0,c0,r1,c1).real().eval().minCoeff());
|
||||
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().maxCoeff(), m1.block(r0,c0,r1,c1).real().eval().maxCoeff());
|
||||
|
||||
@ -78,6 +82,8 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
|
||||
Index size = w.size();
|
||||
|
||||
VectorType v = VectorType::Random(size);
|
||||
VectorType v_for_prod = VectorType::Ones(size) + Scalar(0.2) * v; // see comment above declaration of m1_for_prod
|
||||
|
||||
for(int i = 1; i < size; i++)
|
||||
{
|
||||
Scalar s(0), p(1);
|
||||
@ -85,12 +91,12 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
|
||||
for(int j = 0; j < i; j++)
|
||||
{
|
||||
s += v[j];
|
||||
p *= v[j];
|
||||
p *= v_for_prod[j];
|
||||
minc = (std::min)(minc, internal::real(v[j]));
|
||||
maxc = (std::max)(maxc, internal::real(v[j]));
|
||||
}
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(internal::abs(s - v.head(i).sum()), Scalar(1));
|
||||
VERIFY_IS_APPROX(p, v.head(i).prod());
|
||||
VERIFY_IS_APPROX(p, v_for_prod.head(i).prod());
|
||||
VERIFY_IS_APPROX(minc, v.real().head(i).minCoeff());
|
||||
VERIFY_IS_APPROX(maxc, v.real().head(i).maxCoeff());
|
||||
}
|
||||
@ -102,12 +108,12 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
|
||||
for(int j = i; j < size; j++)
|
||||
{
|
||||
s += v[j];
|
||||
p *= v[j];
|
||||
p *= v_for_prod[j];
|
||||
minc = (std::min)(minc, internal::real(v[j]));
|
||||
maxc = (std::max)(maxc, internal::real(v[j]));
|
||||
}
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(internal::abs(s - v.tail(size-i).sum()), Scalar(1));
|
||||
VERIFY_IS_APPROX(p, v.tail(size-i).prod());
|
||||
VERIFY_IS_APPROX(p, v_for_prod.tail(size-i).prod());
|
||||
VERIFY_IS_APPROX(minc, v.real().tail(size-i).minCoeff());
|
||||
VERIFY_IS_APPROX(maxc, v.real().tail(size-i).maxCoeff());
|
||||
}
|
||||
@ -119,12 +125,12 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
|
||||
for(int j = i; j < size-i; j++)
|
||||
{
|
||||
s += v[j];
|
||||
p *= v[j];
|
||||
p *= v_for_prod[j];
|
||||
minc = (std::min)(minc, internal::real(v[j]));
|
||||
maxc = (std::max)(maxc, internal::real(v[j]));
|
||||
}
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(internal::abs(s - v.segment(i, size-2*i).sum()), Scalar(1));
|
||||
VERIFY_IS_APPROX(p, v.segment(i, size-2*i).prod());
|
||||
VERIFY_IS_APPROX(p, v_for_prod.segment(i, size-2*i).prod());
|
||||
VERIFY_IS_APPROX(minc, v.real().segment(i, size-2*i).minCoeff());
|
||||
VERIFY_IS_APPROX(maxc, v.real().segment(i, size-2*i).maxCoeff());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user