diff --git a/C/C-01-simple/samples b/C/C-01-simple/samples index b16b392a..2495363b 100755 Binary files a/C/C-01-simple/samples and b/C/C-01-simple/samples differ diff --git a/C/squiggle_c/example_simple/example b/C/squiggle_c/examples/01_one_sample/example similarity index 100% rename from C/squiggle_c/example_simple/example rename to C/squiggle_c/examples/01_one_sample/example diff --git a/C/squiggle_c/examples/01_one_sample/example.c b/C/squiggle_c/examples/01_one_sample/example.c new file mode 100644 index 00000000..bbea2ebb --- /dev/null +++ b/C/squiggle_c/examples/01_one_sample/example.c @@ -0,0 +1,50 @@ +#include "../../squiggle.h" +#include +#include +#include + +// Estimate functions +float sample_0(uint32_t* seed) +{ + return 0; +} + +float sample_1(uint32_t* seed) +{ + return 1; +} + +float sample_few(uint32_t* seed) +{ + return random_to(1, 3, seed); +} + +float sample_many(uint32_t* seed) +{ + return random_to(2, 10, seed); +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + float p_a = 0.8; + float p_b = 0.5; + float p_c = p_a * p_b; + + int n_dists = 4; + float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; + float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; + + float result_one = mixture(samplers, weights, n_dists, seed); + printf("result_one: %f\n", result_one); +} + +/* +Aggregation mechanisms: +- Quantiles (requires a sort) +- Sum +- Average +- Std +*/ diff --git a/C/squiggle_c/example_simple/makefile b/C/squiggle_c/examples/01_one_sample/makefile similarity index 100% rename from C/squiggle_c/example_simple/makefile rename to C/squiggle_c/examples/01_one_sample/makefile diff --git a/C/squiggle_c/examples/02_many_samples/example b/C/squiggle_c/examples/02_many_samples/example new file mode 100755 index 00000000..b3db352f Binary files /dev/null and b/C/squiggle_c/examples/02_many_samples/example differ diff --git a/C/squiggle_c/example_simple/example.c b/C/squiggle_c/examples/02_many_samples/example.c similarity index 89% rename from C/squiggle_c/example_simple/example.c rename to C/squiggle_c/examples/02_many_samples/example.c index 2113b6c8..001d7321 100644 --- a/C/squiggle_c/example_simple/example.c +++ b/C/squiggle_c/examples/02_many_samples/example.c @@ -1,7 +1,7 @@ -#include "../squiggle.h" #include #include #include +#include "../../squiggle.h" // Estimate functions float sample_0(uint32_t* seed) @@ -37,9 +37,6 @@ int main(){ float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; - float result_one = mixture(samplers, weights, n_dists, seed); - printf("result_one: %f\n", result_one); - int n_samples = 1000000; float* result_many = (float *) malloc(n_samples * sizeof(float)); for(int i=0; i&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo + +## Profiling + +profile-linux: + echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar" + echo "Must be run as sudo" + $(CC) $(SRC) $(MATH) -o $(OUTPUT) + sudo perf record $(OUTPUT) + sudo perf report + rm perf.data