1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

Reuse random generator engine for speedup

This commit is contained in:
Carles Fernandez 2019-05-26 20:21:48 +02:00
parent 8c1b4c6894
commit 7004606f00
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 8 additions and 17 deletions

View File

@ -32,24 +32,18 @@
#include <vector> // for vector
float uniform()
template <typename T>
void random_values(T *buf, unsigned int n, std::default_random_engine &e1)
{
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<float> uniform_dist(-1, 1);
return uniform_dist(e1); // uniformly (-1, 1)
}
template <class t>
void random_floats(t *buf, unsigned n)
{
for (unsigned i = 0; i < n; i++)
buf[i] = uniform();
std::uniform_real_distribution<T> uniform_dist(T(-1), T(1));
for (unsigned int i = 0; i < n; i++)
buf[i] = uniform_dist(e1);
}
void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
{
std::random_device r;
std::default_random_engine e1(r());
std::default_random_engine e2(r());
if (type.is_complex) n *= 2;
@ -57,9 +51,9 @@ void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
if (type.is_float)
{
if (type.size == 8)
random_floats<double>((double *)data, n);
random_values<double>((double *)data, n, e1);
else
random_floats<float>((float *)data, n);
random_values<float>((float *)data, n, e1);
}
else
{

View File

@ -124,9 +124,6 @@ public:
************************************************/
volk_gnsssdr_type_t volk_gnsssdr_type_from_string(std::string);
float uniform(void);
void random_floats(float *buf, unsigned n);
bool run_volk_gnsssdr_tests(
volk_gnsssdr_func_desc_t,
void (*)(),