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:
parent
8c1b4c6894
commit
7004606f00
@ -32,24 +32,18 @@
|
|||||||
#include <vector> // for vector
|
#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::uniform_real_distribution<T> uniform_dist(T(-1), T(1));
|
||||||
std::default_random_engine e1(r());
|
for (unsigned int i = 0; i < n; i++)
|
||||||
std::uniform_real_distribution<float> uniform_dist(-1, 1);
|
buf[i] = uniform_dist(e1);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
|
void load_random_data(void *data, volk_gnsssdr_type_t type, unsigned int n)
|
||||||
{
|
{
|
||||||
std::random_device r;
|
std::random_device r;
|
||||||
|
std::default_random_engine e1(r());
|
||||||
std::default_random_engine e2(r());
|
std::default_random_engine e2(r());
|
||||||
|
|
||||||
if (type.is_complex) n *= 2;
|
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.is_float)
|
||||||
{
|
{
|
||||||
if (type.size == 8)
|
if (type.size == 8)
|
||||||
random_floats<double>((double *)data, n);
|
random_values<double>((double *)data, n, e1);
|
||||||
else
|
else
|
||||||
random_floats<float>((float *)data, n);
|
random_values<float>((float *)data, n, e1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -124,9 +124,6 @@ public:
|
|||||||
************************************************/
|
************************************************/
|
||||||
volk_gnsssdr_type_t volk_gnsssdr_type_from_string(std::string);
|
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(
|
bool run_volk_gnsssdr_tests(
|
||||||
volk_gnsssdr_func_desc_t,
|
volk_gnsssdr_func_desc_t,
|
||||||
void (*)(),
|
void (*)(),
|
||||||
|
Loading…
Reference in New Issue
Block a user