From 930a431012bcf651956176745d23e9da116ae092 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 23 Jul 2023 11:27:17 +0200 Subject: [PATCH] test correlated/uncorrelated example code. --- README.md | 78 ++++++++++++++++++++++++- scratchpad/correlated/correlated | Bin 0 -> 22112 bytes scratchpad/correlated/correlated.c | 21 +++++++ scratchpad/correlated/makefile | 53 +++++++++++++++++ scratchpad/uncorrelated/makefile | 53 +++++++++++++++++ scratchpad/uncorrelated/uncorrelated | Bin 0 -> 22152 bytes scratchpad/uncorrelated/uncorrelated.c | 24 ++++++++ 7 files changed, 228 insertions(+), 1 deletion(-) create mode 100755 scratchpad/correlated/correlated create mode 100644 scratchpad/correlated/correlated.c create mode 100644 scratchpad/correlated/makefile create mode 100644 scratchpad/uncorrelated/makefile create mode 100755 scratchpad/uncorrelated/uncorrelated create mode 100644 scratchpad/uncorrelated/uncorrelated.c diff --git a/README.md b/README.md index 2d77667..5fc3c87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Squiggle.c -A self-contained C99 library that provides a subset of [Squiggle](https://www.squiggle-language.com/)'s functionality in C. It should be fast, but at the margin, simplicity of implementation wins over speed. +A self-contained C99 library that provides a subset of [Squiggle](https://www.squiggle-language.com/)'s functionality in C. ## Why C? @@ -70,6 +70,82 @@ The first approach produces terser programs but might not scale. The second appr Behaviour on error can be toggled by the `EXIT_ON_ERROR` variable. This library also provides a convenient macro, `PROCESS_ERROR`, to make error handling in either case much terser—see the usage in example 4 in the examples/ folder. +## Design choices + +This code should aim to be fast, but at the margin, simplicity of implementation wins over speed. For example, there are various possible algorithms to sample a distribution, one of which is faster in part of the domain, I'm choosing to only have one algorithm and pay the—normally small—performance penalty. + +## Correlated samples + +In the parent [squiggle](https://www.squiggle-language.com/) language, there is some ambiguity about what this code means: + +``` +a = 1 to 10 +b = 2 * a +c = b/a +c +``` + +Should `c` be equal to `2`? or should it be equal to 2 times the expected ratio of two independent draws from a (`2 * a/a`, as it were)? + +In squiggle.c, this ambiguity doesn't exist, at the cost of greater verbosity: + +```c +// correlated samples +// gcc -O3 correlated.c squiggle.c -lm -o correlated + +#include "squiggle.h" +#include +#include +#include + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with a seed of 0 + + float a = sample_to(1, 10, seed); + float b = 2 * a; + float c = b / a; + + printf("a: %f, b: %f, c: %f\n", a, b, c); + // a: 0.607162, b: 1.214325, c: 0.500000 + + free(seed); +} +``` + +vs + +```c +// uncorrelated samples +// gcc -O3 uncorrelated.c ../../squiggle.c -lm -o uncorrelated + +#include "squiggle.h" +#include +#include +#include + +float draw_xyz(uint32_t* seed){ + // function could also be placed inside main with gcc nested functions extension. + return sample_to(1, 20, seed); +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with a seed of 0 + + float a = draw_xyz(seed); + float b = 2 * draw_xyz(seed); + float c = b / a; + + printf("a: %f, b: %f, c: %f\n", a, b, c); + // a: 0.522484, b: 10.283501, c: 19.681936 + + free(seed) +} +``` + ## Related projects - [Squiggle](https://www.squiggle-language.com/) diff --git a/scratchpad/correlated/correlated b/scratchpad/correlated/correlated new file mode 100755 index 0000000000000000000000000000000000000000..533ab80326f7b88a6e83d5af6cc51403ac303745 GIT binary patch literal 22112 zcmeHPe^gZ0oxjY0k_hw022z@6oLWpt8V4|HHHncipbv|YC^m@bI5Gor3Il&v?zt^4#d-(49#n_ZFrz1LqksccZ4 zBtwbx)esX;d76qOBl`a+asnfIJn)NVqT{7+qd-pO6p@$5!KVOsrAP{9GsswW{Nv!= zj`P z)Y8D(A8HHL^ZyKNJ!@^*!U9`c0W}7xzB*Z-x3#S?7^?TyZT=j}8$+lC71Vu>0B^mo zv57VNnwnbb2oIWMz23U5K5u za5VerWOi;ccc*(UTw>$1A{}#W5Q-#aaSZJ?Aep{LLVdhHa3YWMN;d#T33s1 z5P0PZK@~nCgCUb90+PZNe`=+`X|A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P^c1CitGWH^oI}xhav!M7C_TkLXVF*ZA&RPVS0!(q zKZm5g8h>@aq3DQGlvItMf`4w&SLZ8=s`~*YZ>|5dMPHr6D0)DyCraO1|LZ8AvkoPu z?$6cx5UuixSM+V@Y9@Vk-dwo|Ad-?3+$gW`4^Tj{tLj(h2I~EmYGTp+qonlIIQ|WvSx_cS)vxYHoFziSDo=Hp z(^Of1kr_l@>3_*G literal 0 HcmV?d00001 diff --git a/scratchpad/correlated/correlated.c b/scratchpad/correlated/correlated.c new file mode 100644 index 0000000..cd53eae --- /dev/null +++ b/scratchpad/correlated/correlated.c @@ -0,0 +1,21 @@ +// correlated samples + +#include "../../squiggle.h" +#include +#include +#include + +int main() +{ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + float a = sample_to(1, 10, seed); + float b = 2 * a; + float c = a / b; + + printf("a: %f, b: %f, c: %f\n", a, b, c); + + free(seed); +} diff --git a/scratchpad/correlated/makefile b/scratchpad/correlated/makefile new file mode 100644 index 0000000..90a3e63 --- /dev/null +++ b/scratchpad/correlated/makefile @@ -0,0 +1,53 @@ +# Interface: +# make +# make build +# make format +# make run + +# Compiler +CC=gcc +# CC=tcc # <= faster compilation + +# Main file +SRC=correlated.c ../../squiggle.c +OUTPUT=correlated + +## Dependencies +MATH=-lm + +## Flags +DEBUG= #'-g' +STANDARD=-std=c99 +WARNINGS=-Wall +OPTIMIZED=-O3 #-Ofast +# OPENMP=-fopenmp + +## Formatter +STYLE_BLUEPRINT=webkit +FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + +## make build +build: $(SRC) + $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT) + +format: $(SRC) + $(FORMATTER) $(SRC) + +run: $(SRC) $(OUTPUT) + OMP_NUM_THREADS=1 ./$(OUTPUT) && echo + +time-linux: + @echo "Requires /bin/time, found on GNU/Linux systems" && echo + + @echo "Running 100x and taking avg time $(OUTPUT)" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&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 diff --git a/scratchpad/uncorrelated/makefile b/scratchpad/uncorrelated/makefile new file mode 100644 index 0000000..bf9f32d --- /dev/null +++ b/scratchpad/uncorrelated/makefile @@ -0,0 +1,53 @@ +# Interface: +# make +# make build +# make format +# make run + +# Compiler +CC=gcc +# CC=tcc # <= faster compilation + +# Main file +SRC=uncorrelated.c ../../squiggle.c +OUTPUT=uncorrelated + +## Dependencies +MATH=-lm + +## Flags +DEBUG= #'-g' +STANDARD=-std=c99 +WARNINGS=-Wall +OPTIMIZED=-O3 #-Ofast +# OPENMP=-fopenmp + +## Formatter +STYLE_BLUEPRINT=webkit +FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + +## make build +build: $(SRC) + $(CC) $(OPTIMIZED) $(DEBUG) $(SRC) $(MATH) -o $(OUTPUT) + +format: $(SRC) + $(FORMATTER) $(SRC) + +run: $(SRC) $(OUTPUT) + OMP_NUM_THREADS=1 ./$(OUTPUT) && echo + +time-linux: + @echo "Requires /bin/time, found on GNU/Linux systems" && echo + + @echo "Running 100x and taking avg time $(OUTPUT)" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&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 diff --git a/scratchpad/uncorrelated/uncorrelated b/scratchpad/uncorrelated/uncorrelated new file mode 100755 index 0000000000000000000000000000000000000000..2ba1a2c4aa43f457eb3dbf289422b956a749c3b7 GIT binary patch literal 22152 zcmeHP4|G)3nZL;-5G9#6sfk7f8EL5T50eCe0!qn*1YT&6fXOz5z;s9^B-{KWnUP>y ziiUtAM(G}F+pXP$yX{ubwmq!dZo#9=BoPQ`Yd~#Ly4!$QX9#Falu||B{=WNX^5!w= zx;@*oyXWMdWWM|T?)QE7-tT_*zWeT*dEY25U7DDXz*MraFEHY^eMTS!vY`JSnE@$a z^H~}`r?Z>bB=AWb6XgYhpj4z2iLo?A;xOD;Ma_ET8-0<`(^tgOe(9G1NtGV4q*p2RDy5#H zOvy{C{7F8c|M}9NR_a6R0j?JvU@6MSVDwJH}bK_kUW*YbKsZP_6(gb&)@muOMh5(dtrLux|zxb)k!jx zNM8*x@sy{jNHU`T4Gzqifr@d(klf{iU3 zS^K6oe;xm1VCz_G%Vy^5Xa&^JO!d{s`aG>|4bA>KPfh(-P~PB2EvTU8D+GAzybX=4 z$=lf2QbTyNN!H`3>F|2$8k)V04fj*q$fj&tlNWW=wfTH(S!qe(63=YcY}eee{DQIU z=cCy<(cGP`IdDlLpA|`%Ym@Mw#JS1%Ol0)Q_-6ug3CPo&EWm%@h6Y>-CbKss7X0QD zm_Etu_mbbq`6Tu}cuJ(d2~@2c84V3-G~+HwOxUwU?fI`K`-yB4Rf?q6ceSp5`5J+j ztq@ejp+*c6O94A^Tia}c{66rT?lx@n0Xh7Hl2}tJr#^ZP8o)=oAb0`7>OK<^0ZMH ziS$Hy+Q^JV{yECihG8V~RFtQU!bs$sQJyvkBasK9JZ%g{BAcQ-Z3spp-Y8ESqLIj| zC{G)qk%&9W(?($=k{{)1gD?`gS@G!I`7coKiWu)7_zDZZ!on9@_(c|eu7#gv;b&U- zX%;@y!lzmIWDEZZj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<9SNeb`Ll;8Y$TCmYirLQRcg2AjGy>BfLDykl3 zK6>XZ_Dr$`1%lD#fjXUI(LIN1 pk6M4IShZbfh|h=U!h&?OCE!%OqLl9W;_E-NLP*?TQLwP=KLN4m`Xc}U literal 0 HcmV?d00001 diff --git a/scratchpad/uncorrelated/uncorrelated.c b/scratchpad/uncorrelated/uncorrelated.c new file mode 100644 index 0000000..4fbe05d --- /dev/null +++ b/scratchpad/uncorrelated/uncorrelated.c @@ -0,0 +1,24 @@ +// uncorrelated samples + +#include "../../squiggle.h" +#include +#include +#include + +float draw_xyz(uint32_t* seed){ + // function could also be placed inside main with gcc nested functions extension. + return sample_to(1, 20, seed); +} + +int main(){ + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + float a = draw_xyz(seed); + float b = 2 * draw_xyz(seed); + float c = b / a; + + printf("a: %f, b: %f, c: %f\n", a, b, c); + +}