mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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:
21
test/main.h
21
test/main.h
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user