continue minimizing nested functions

This commit is contained in:
NunoSempere 2024-01-29 18:35:34 +01:00
parent fa832cbd17
commit 86b12db894
3 changed files with 15 additions and 10 deletions

View File

@ -3,6 +3,10 @@
#include <stdio.h>
#include <stdlib.h>
double sample_model(uint64_t* seed){
return sample_to(1, 10, seed);
}
int main()
{
// set randomness seed

View File

@ -3,6 +3,10 @@
#include <stdio.h>
#include <stdlib.h>
double sample_model(uint64_t * seed)
{
return sample_lognormal(0, 10, seed);
}
// Estimate functions
int main()
{
@ -13,13 +17,9 @@ int main()
int n_samples = 1000 * 1000 * 1000;
int n_threads = 16;
double sampler(uint64_t * seed)
{
return sample_lognormal(0, 10, seed);
}
double* results = malloc((size_t)n_samples * sizeof(double));
sampler_parallel(sampler, results, n_threads, n_samples);
sampler_parallel(sample_model, results, n_threads, n_samples);
double avg = array_sum(results, n_samples) / n_samples;
printf("Average of 1B lognormal(0,10): %f\n", avg);

View File

@ -3,7 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
int main()
double sampler_result(uint64_t * seed)
{
double p_a = 0.8;
double p_b = 0.5;
@ -17,10 +17,11 @@ int main()
int n_dists = 4;
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
double sampler_result(uint64_t * seed)
{
return sample_mixture(samplers, weights, n_dists, seed);
}
return sample_mixture(samplers, weights, n_dists, seed);
}
int main()
{
int n_samples = 1000 * 1000, n_threads = 16;
double* results = malloc((size_t)n_samples * sizeof(double));