diff --git a/examples/core/00_example_template/example b/examples/core/00_example_template/example index d2100f5..e4195e1 100755 Binary files a/examples/core/00_example_template/example and b/examples/core/00_example_template/example differ diff --git a/examples/core/01_one_sample/example b/examples/core/01_one_sample/example index ad04e6b..a182677 100755 Binary files a/examples/core/01_one_sample/example and b/examples/core/01_one_sample/example differ diff --git a/examples/core/02_time_to_botec/example b/examples/core/02_time_to_botec/example index b60a703..126bc33 100755 Binary files a/examples/core/02_time_to_botec/example and b/examples/core/02_time_to_botec/example differ diff --git a/examples/core/03_gcc_nested_function/example b/examples/core/03_gcc_nested_function/example index 77d231e..f5bd5c1 100755 Binary files a/examples/core/03_gcc_nested_function/example and b/examples/core/03_gcc_nested_function/example differ diff --git a/examples/core/04_gamma_beta/example b/examples/core/04_gamma_beta/example index d04807a..d903507 100755 Binary files a/examples/core/04_gamma_beta/example and b/examples/core/04_gamma_beta/example differ diff --git a/examples/core/05_hundred_lognormals/example b/examples/core/05_hundred_lognormals/example index 48e9c5f..a25f8ba 100755 Binary files a/examples/core/05_hundred_lognormals/example and b/examples/core/05_hundred_lognormals/example differ diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example index ce95d19..cc23c9f 100755 Binary files a/examples/more/00_example_template/example and b/examples/more/00_example_template/example differ diff --git a/examples/more/01_sample_from_cdf/example b/examples/more/01_sample_from_cdf/example index a132934..e7a51ff 100755 Binary files a/examples/more/01_sample_from_cdf/example and b/examples/more/01_sample_from_cdf/example differ diff --git a/examples/more/02_sample_from_cdf_beta/example b/examples/more/02_sample_from_cdf_beta/example index 4c4a03f..39569f4 100755 Binary files a/examples/more/02_sample_from_cdf_beta/example and b/examples/more/02_sample_from_cdf_beta/example differ diff --git a/examples/more/03_ci_beta/example b/examples/more/03_ci_beta/example index e4eb00d..0dd6da1 100755 Binary files a/examples/more/03_ci_beta/example and b/examples/more/03_ci_beta/example differ diff --git a/examples/more/04_nuclear_war/example b/examples/more/04_nuclear_war/example index 7f25c40..b296d20 100755 Binary files a/examples/more/04_nuclear_war/example and b/examples/more/04_nuclear_war/example differ diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example index cd0b419..4a5c586 100755 Binary files a/examples/more/05_burn_10kg_fat/example and b/examples/more/05_burn_10kg_fat/example differ diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example index ce84fda..df19be6 100755 Binary files a/examples/more/06_nuclear_recovery/example and b/examples/more/06_nuclear_recovery/example differ diff --git a/examples/more/07_algebra/example b/examples/more/07_algebra/example index 5043492..ae1efe9 100755 Binary files a/examples/more/07_algebra/example and b/examples/more/07_algebra/example differ diff --git a/examples/more/08_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example index c7f4218..8405818 100755 Binary files a/examples/more/08_algebra_and_conversion/example and b/examples/more/08_algebra_and_conversion/example differ diff --git a/examples/more/09_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example index d960fd5..611b4e9 100755 Binary files a/examples/more/09_ergonomic_algebra/example and b/examples/more/09_ergonomic_algebra/example differ diff --git a/examples/more/10_twitter_thread_example/example b/examples/more/10_twitter_thread_example/example index 1b078a8..95b1d1c 100755 Binary files a/examples/more/10_twitter_thread_example/example and b/examples/more/10_twitter_thread_example/example differ diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example index 59eda25..e65a0d7 100755 Binary files a/examples/more/11_billion_lognormals_paralell/example and b/examples/more/11_billion_lognormals_paralell/example differ diff --git a/examples/more/12_time_to_botec_parallel/example b/examples/more/12_time_to_botec_parallel/example index a60f03e..caf0fd2 100755 Binary files a/examples/more/12_time_to_botec_parallel/example and b/examples/more/12_time_to_botec_parallel/example differ diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example index e6c7274..6544858 100755 Binary files a/examples/more/13_parallelize_min/example and b/examples/more/13_parallelize_min/example differ diff --git a/examples/more/14_check_confidence_interval/example b/examples/more/14_check_confidence_interval/example index 4a3f769..9322f3a 100755 Binary files a/examples/more/14_check_confidence_interval/example and b/examples/more/14_check_confidence_interval/example differ diff --git a/squiggle_more.c b/squiggle_more.c index fe69ab1..9271530 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -6,6 +6,7 @@ #include #include #include +#include // memcpy /* Parallel sampler */ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples) @@ -105,15 +106,24 @@ static int partition(int low, int high, double xs[], int length) static double quickselect(int k, double xs[], int n) { // https://en.wikipedia.org/wiki/Quickselect + + double *ys = malloc((size_t)n * sizeof(double)); + memcpy(ys, xs, (size_t)n * sizeof(double)); + // ^: don't make this operation "destructive" + int low = 0; int high = n - 1; for (;;) { if (low == high) { - return xs[low]; + double result = ys[low]; + free(ys); + return result; } - int pivot = partition(low, high, xs, n); + int pivot = partition(low, high, ys, n); if (pivot == k) { - return xs[pivot]; + double result = ys[pivot]; + free(ys); + return result; } else if (k < pivot) { high = pivot - 1; } else { diff --git a/test/test b/test/test index 594b53f..495bacc 100755 Binary files a/test/test and b/test/test differ