make format
This commit is contained in:
parent
93a502552e
commit
6273ba69a0
10
C/samples.c
10
C/samples.c
|
@ -99,7 +99,7 @@ float ur_normal(unsigned int* seed)
|
||||||
|
|
||||||
inline float random_uniform(float from, float to, unsigned int* seed)
|
inline float random_uniform(float from, float to, unsigned int* seed)
|
||||||
{
|
{
|
||||||
return ((float) rand_r(seed) / (float)RAND_MAX) * (to - from) + from;
|
return ((float)rand_r(seed) / (float)RAND_MAX) * (to - from) + from;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float random_normal(float mean, float sigma, unsigned int* seed)
|
inline float random_normal(float mean, float sigma, unsigned int* seed)
|
||||||
|
@ -123,7 +123,7 @@ inline float random_to(float low, float high, unsigned int* seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mixture function
|
// Mixture function
|
||||||
void mixture(float (*samplers[])(unsigned int* ), float* weights, int n_dists, float** results, int n_threads)
|
void mixture(float (*samplers[])(unsigned int*), float* weights, int n_dists, float** results, int n_threads)
|
||||||
{
|
{
|
||||||
// You can see a simpler version of this function in the git history
|
// You can see a simpler version of this function in the git history
|
||||||
// or in C-02-better-algorithm-one-thread/
|
// or in C-02-better-algorithm-one-thread/
|
||||||
|
@ -140,7 +140,7 @@ void mixture(float (*samplers[])(unsigned int* ), float* weights, int n_dists, f
|
||||||
float p1;
|
float p1;
|
||||||
int sample_index, i, own_length;
|
int sample_index, i, own_length;
|
||||||
unsigned int* seeds[n_threads];
|
unsigned int* seeds[n_threads];
|
||||||
for(unsigned int i=0; i<n_threads; i++){
|
for (unsigned int i = 0; i < n_threads; i++) {
|
||||||
seeds[i] = malloc(sizeof(unsigned int));
|
seeds[i] = malloc(sizeof(unsigned int));
|
||||||
*seeds[i] = i;
|
*seeds[i] = i;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ void mixture(float (*samplers[])(unsigned int* ), float* weights, int n_dists, f
|
||||||
}
|
}
|
||||||
free(normalized_weights);
|
free(normalized_weights);
|
||||||
free(cummulative_weights);
|
free(cummulative_weights);
|
||||||
for(unsigned int i=0; i<n_threads; i++){
|
for (unsigned int i = 0; i < n_threads; i++) {
|
||||||
free(seeds[i]);
|
free(seeds[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ int main()
|
||||||
// Generate mixture
|
// Generate mixture
|
||||||
int n_dists = 4;
|
int n_dists = 4;
|
||||||
float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
|
||||||
float (*samplers[])(unsigned int* ) = { sample_0, sample_1, sample_few, sample_many };
|
float (*samplers[])(unsigned int*) = { sample_0, sample_1, sample_few, sample_many };
|
||||||
|
|
||||||
mixture(samplers, weights, n_dists, dist_mixture, n_threads);
|
mixture(samplers, weights, n_dists, dist_mixture, n_threads);
|
||||||
printf("Sum(dist_mixture, N)/N = %f\n", split_array_sum(dist_mixture, N, n_threads) / N);
|
printf("Sum(dist_mixture, N)/N = %f\n", split_array_sum(dist_mixture, N, n_threads) / N);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user