if EIGEN_NICE_RANDOM is defined, the random functions will return numbers with

few bits left of the comma and for floating-point types will never return zero.
This replaces the custom functions in test/main.h, so one does not anymore need
to think about that when writing tests.
This commit is contained in:
Benoit Jacob
2008-09-01 17:31:21 +00:00
parent 49ff9b204c
commit 46fe7a3d9e
15 changed files with 78 additions and 83 deletions

View File

@@ -135,6 +135,7 @@ namespace Eigen
#define EIGEN_INTERNAL_DEBUGGING
#define EIGEN_NICE_RANDOM
#include <Eigen/Core>
namespace Eigen {
@@ -221,26 +222,6 @@ inline bool test_ei_isMuchSmallerThan(const MatrixBase<Derived>& m,
return m.isMuchSmallerThan(s, test_precision<typename ei_traits<Derived>::Scalar>());
}
template<typename T> T test_random();
template<> int test_random() { return ei_random<int>(-100,100); }
template<> float test_random() { return float(ei_random<int>(-1000,1000)) / 256.f; }
template<> double test_random() { return double(ei_random<int>(-1000,1000)) / 256.; }
template<> std::complex<float> test_random()
{ return std::complex<float>(test_random<float>(),test_random<float>()); }
template<> std::complex<double> test_random()
{ return std::complex<double>(test_random<double>(),test_random<double>()); }
template<typename MatrixType>
MatrixType test_random_matrix(int rows = MatrixType::RowsAtCompileTime, int cols = MatrixType::ColsAtCompileTime)
{
MatrixType res(rows, cols);
for (int j=0; j<cols; ++j)
for (int i=0; i<rows; ++i)
res.coeffRef(i,j) = test_random<typename MatrixType::Scalar>();
return res;
}
} // end namespace Eigen