From 4662539c60385c81b915a19457108c49a18ee39e Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 9 Dec 2023 19:00:43 +0000 Subject: [PATCH] run formatting pass --- examples/core/02_time_to_botec/example.c | 14 +++++++++++--- examples/core/03_gcc_nested_function/example.c | 14 +++++++++++--- examples/core/04_gamma_beta/example.c | 4 ++-- examples/more/04_nuclear_war/example.c | 4 ++-- examples/more/05_burn_10kg_fat/example.c | 2 +- examples/more/06_nuclear_recovery/example.c | 6 +++--- examples/more/10_twitter_thread_example/example.c | 4 ++-- .../more/11_billion_lognormals_paralell/example.c | 2 +- examples/more/12_time_to_botec_parallel/example.c | 14 +++++++++++--- examples/more/13_parallelize_min/example.c | 4 ++-- .../more/14_check_confidence_interval/example.c | 2 +- squiggle.c | 2 +- squiggle_more.c | 12 ++++++------ 13 files changed, 54 insertions(+), 30 deletions(-) diff --git a/examples/core/02_time_to_botec/example.c b/examples/core/02_time_to_botec/example.c index 21aa12c..9d0aa21 100644 --- a/examples/core/02_time_to_botec/example.c +++ b/examples/core/02_time_to_botec/example.c @@ -12,8 +12,16 @@ int main() double p_b = 0.5; double p_c = p_a * p_b; - double sample_0(uint64_t * seed) { UNUSED(seed); return 0; } - double sample_1(uint64_t * seed) { UNUSED(seed); return 1; } + double sample_0(uint64_t * seed) + { + UNUSED(seed); + return 0; + } + double sample_1(uint64_t * seed) + { + UNUSED(seed); + return 1; + } double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); } double sample_many(uint64_t * seed) { return sample_to(2, 10, seed); } @@ -22,7 +30,7 @@ int main() double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many }; int n_samples = 1000000; - double* result_many = (double*)malloc((size_t) n_samples * sizeof(double)); + double* result_many = (double*)malloc((size_t)n_samples * sizeof(double)); for (int i = 0; i < n_samples; i++) { result_many[i] = sample_mixture(samplers, weights, n_dists, seed); } diff --git a/examples/core/03_gcc_nested_function/example.c b/examples/core/03_gcc_nested_function/example.c index b376bea..d00e983 100644 --- a/examples/core/03_gcc_nested_function/example.c +++ b/examples/core/03_gcc_nested_function/example.c @@ -15,8 +15,16 @@ int main() int n_dists = 4; // These are nested functions. They will not compile without gcc. - double sample_0(uint64_t * seed) { UNUSED(seed); return 0; } - double sample_1(uint64_t * seed) { UNUSED(seed); return 1; } + double sample_0(uint64_t * seed) + { + UNUSED(seed); + return 0; + } + double sample_1(uint64_t * seed) + { + UNUSED(seed); + return 1; + } double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); } double sample_many(uint64_t * seed) { return sample_to(2, 10, seed); } @@ -24,7 +32,7 @@ int main() double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; int n_samples = 1000000; - double* result_many = (double*)malloc((size_t) n_samples * sizeof(double)); + double* result_many = (double*)malloc((size_t)n_samples * sizeof(double)); for (int i = 0; i < n_samples; i++) { result_many[i] = sample_mixture(samplers, weights, n_dists, seed); } diff --git a/examples/core/04_gamma_beta/example.c b/examples/core/04_gamma_beta/example.c index 2612662..d606be4 100644 --- a/examples/core/04_gamma_beta/example.c +++ b/examples/core/04_gamma_beta/example.c @@ -19,7 +19,7 @@ int main() printf("\n"); */ - double* gamma_1_array = malloc(sizeof(double) * (size_t) n); + double* gamma_1_array = malloc(sizeof(double) * (size_t)n); for (int i = 0; i < n; i++) { double gamma_1 = sample_gamma(1.0, seed); // printf("sample_gamma(1.0): %f\n", gamma_1); @@ -29,7 +29,7 @@ int main() free(gamma_1_array); printf("\n"); - double* beta_1_2_array = malloc(sizeof(double) * (size_t) n); + double* beta_1_2_array = malloc(sizeof(double) * (size_t)n); for (int i = 0; i < n; i++) { double beta_1_2 = sample_beta(1, 2.0, seed); // printf("sample_beta(1.0, 2.0): %f\n", beta_1_2); diff --git a/examples/more/04_nuclear_war/example.c b/examples/more/04_nuclear_war/example.c index be62bde..9cf0678 100644 --- a/examples/more/04_nuclear_war/example.c +++ b/examples/more/04_nuclear_war/example.c @@ -49,7 +49,7 @@ int main() int n = 1000 * 1000; - double* mixture_result = malloc(sizeof(double) * (size_t) n); + double* mixture_result = malloc(sizeof(double) * (size_t)n); for (int i = 0; i < n; i++) { mixture_result[i] = mixture(seed); } @@ -63,7 +63,7 @@ int main() ci ci_90 = sampler_get_90_ci(mixture, 1000000, seed); printf("mean: %f\n", array_mean(mixture_result, n)); printf("90%% confidence interval: [%f, %f]\n", ci_90.low, ci_90.high); - + free(mixture_result); free(seed); } diff --git a/examples/more/05_burn_10kg_fat/example.c b/examples/more/05_burn_10kg_fat/example.c index 2fb7298..a2b7d82 100644 --- a/examples/more/05_burn_10kg_fat/example.c +++ b/examples/more/05_burn_10kg_fat/example.c @@ -28,7 +28,7 @@ int main() int n = 1000 * 1000; - double* result = malloc(sizeof(double) * (size_t) n); + double* result = malloc(sizeof(double) * (size_t)n); for (int i = 0; i < n; i++) { result[i] = sample_minutes_per_day_jumping_rope_needed_to_burn_10kg(seed); } diff --git a/examples/more/06_nuclear_recovery/example.c b/examples/more/06_nuclear_recovery/example.c index 0ff68b7..f3cbeaf 100644 --- a/examples/more/06_nuclear_recovery/example.c +++ b/examples/more/06_nuclear_recovery/example.c @@ -53,7 +53,7 @@ int main() ci ci_90_2023 = sampler_get_90_ci(yearly_probability_nuclear_collapse_2023, 1000000, seed); printf("90%% confidence interval: [%f, %f]\n", ci_90_2023.low, ci_90_2023.high); - double* yearly_probability_nuclear_collapse_2023_samples = malloc(sizeof(double) * (size_t) num_samples); + double* yearly_probability_nuclear_collapse_2023_samples = malloc(sizeof(double) * (size_t)num_samples); for (int i = 0; i < num_samples; i++) { yearly_probability_nuclear_collapse_2023_samples[i] = yearly_probability_nuclear_collapse_2023(seed); } @@ -64,7 +64,7 @@ int main() ci ci_90_2070 = sampler_get_90_ci(yearly_probability_nuclear_collapse_after_recovery_example, 1000000, seed); printf("90%% confidence interval: [%f, %f]\n", ci_90_2070.low, ci_90_2070.high); - double* yearly_probability_nuclear_collapse_after_recovery_samples = malloc(sizeof(double) * (size_t) num_samples); + double* yearly_probability_nuclear_collapse_after_recovery_samples = malloc(sizeof(double) * (size_t)num_samples); for (int i = 0; i < num_samples; i++) { yearly_probability_nuclear_collapse_after_recovery_samples[i] = yearly_probability_nuclear_collapse_after_recovery_example(seed); } @@ -75,7 +75,7 @@ int main() ci ci_90_antiinductive = sampler_get_90_ci(yearly_probability_nuclear_collapse_after_recovery_antiinductive, 1000000, seed); printf("90%% confidence interval: [%f, %f]\n", ci_90_antiinductive.low, ci_90_antiinductive.high); - double* yearly_probability_nuclear_collapse_after_recovery_antiinductive_samples = malloc(sizeof(double) * (size_t) num_samples); + double* yearly_probability_nuclear_collapse_after_recovery_antiinductive_samples = malloc(sizeof(double) * (size_t)num_samples); for (int i = 0; i < num_samples; i++) { yearly_probability_nuclear_collapse_after_recovery_antiinductive_samples[i] = yearly_probability_nuclear_collapse_after_recovery_antiinductive(seed); } diff --git a/examples/more/10_twitter_thread_example/example.c b/examples/more/10_twitter_thread_example/example.c index 5c67dd8..7ddd0ec 100644 --- a/examples/more/10_twitter_thread_example/example.c +++ b/examples/more/10_twitter_thread_example/example.c @@ -5,13 +5,13 @@ double sample_0(uint64_t* seed) { - UNUSED(seed); + UNUSED(seed); return 0; } double sample_1(uint64_t* seed) { - UNUSED(seed); + UNUSED(seed); return 1; } diff --git a/examples/more/11_billion_lognormals_paralell/example.c b/examples/more/11_billion_lognormals_paralell/example.c index cd74903..35cfc47 100644 --- a/examples/more/11_billion_lognormals_paralell/example.c +++ b/examples/more/11_billion_lognormals_paralell/example.c @@ -17,7 +17,7 @@ int main() { return sample_lognormal(0, 10, seed); } - double* results = malloc((size_t) n_samples * sizeof(double)); + double* results = malloc((size_t)n_samples * sizeof(double)); sampler_parallel(sampler, results, n_threads, n_samples); double avg = array_sum(results, n_samples) / n_samples; diff --git a/examples/more/12_time_to_botec_parallel/example.c b/examples/more/12_time_to_botec_parallel/example.c index 682d69c..e366e14 100644 --- a/examples/more/12_time_to_botec_parallel/example.c +++ b/examples/more/12_time_to_botec_parallel/example.c @@ -9,8 +9,16 @@ int main() double p_b = 0.5; double p_c = p_a * p_b; - double sample_0(uint64_t * seed) { UNUSED(seed); return 0; } - double sample_1(uint64_t * seed) { UNUSED(seed); return 1; } + double sample_0(uint64_t * seed) + { + UNUSED(seed); + return 0; + } + double sample_1(uint64_t * seed) + { + UNUSED(seed); + return 1; + } double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); } double sample_many(uint64_t * seed) { return sample_to(2, 10, seed); } @@ -23,7 +31,7 @@ int main() } int n_samples = 1000 * 1000, n_threads = 16; - double* results = malloc((size_t) n_samples * sizeof(double)); + double* results = malloc((size_t)n_samples * sizeof(double)); sampler_parallel(sampler_result, results, n_threads, n_samples); printf("Avg: %f\n", array_sum(results, n_samples) / n_samples); free(results); diff --git a/examples/more/13_parallelize_min/example.c b/examples/more/13_parallelize_min/example.c index b12eb70..288b281 100644 --- a/examples/more/13_parallelize_min/example.c +++ b/examples/more/13_parallelize_min/example.c @@ -30,7 +30,7 @@ int main() } int n_samples = 1000000, n_threads = 16; - double* results = malloc((size_t) n_samples * sizeof(double)); + double* results = malloc((size_t)n_samples * sizeof(double)); sampler_parallel(sample_min_of_1000, results, n_threads, n_samples); printf("Mean of the distribution of (taking the min of 1000 samples of a normal(5,2)): %f\n", array_mean(results, n_samples)); free(results); @@ -51,7 +51,7 @@ int main() { return sample_min_of_n(seed, quotient); } - double* results_quotient = malloc((size_t) quotient * sizeof(double)); + double* results_quotient = malloc((size_t)quotient * sizeof(double)); sampler_parallel(sample_min_of_quotient, results_quotient, n_threads, quotient); double min = results_quotient[0]; diff --git a/examples/more/14_check_confidence_interval/example.c b/examples/more/14_check_confidence_interval/example.c index e99a0d3..400b814 100644 --- a/examples/more/14_check_confidence_interval/example.c +++ b/examples/more/14_check_confidence_interval/example.c @@ -10,7 +10,7 @@ int main() *seed = 1000; // xorshift can't start with a seed of 0 int n = 1000000; - double* xs = malloc(sizeof(double) * (size_t) n); + double* xs = malloc(sizeof(double) * (size_t)n); for (int i = 0; i < n; i++) { xs[i] = sample_to(10, 100, seed); } diff --git a/squiggle.c b/squiggle.c index f1c647e..d20d91b 100644 --- a/squiggle.c +++ b/squiggle.c @@ -204,7 +204,7 @@ double sample_mixture(double (*samplers[])(uint64_t*), double* weights, int n_di { // Sample from samples with frequency proportional to their weights. double sum_weights = array_sum(weights, n_dists); - double* cumsummed_normalized_weights = (double*)malloc((size_t) n_dists * sizeof(double)); + double* cumsummed_normalized_weights = (double*)malloc((size_t)n_dists * sizeof(double)); cumsummed_normalized_weights[0] = weights[0] / sum_weights; for (int i = 1; i < n_dists; i++) { cumsummed_normalized_weights[i] = cumsummed_normalized_weights[i - 1] + weights[i] / sum_weights; diff --git a/squiggle_more.c b/squiggle_more.c index 1806bb0..fe69ab1 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -28,7 +28,7 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_ int quotient = n_samples / n_threads; int divisor_multiple = quotient * n_threads; - uint64_t** seeds = malloc((size_t) n_threads * sizeof(uint64_t*)); + uint64_t** seeds = malloc((size_t)n_threads * sizeof(uint64_t*)); srand(1); for (int i = 0; i < n_threads; i++) { seeds[i] = malloc(sizeof(uint64_t)); @@ -83,12 +83,12 @@ static void swp(int i, int j, double xs[]) static int partition(int low, int high, double xs[], int length) { - if(low > high || high >= length){ + if (low > high || high >= length) { printf("Invariant violated for function partition in %s (%d)", __FILE__, __LINE__); exit(1); } // Note: the scratchpad/ folder in commit 578bfa27 has printfs sprinkled throughout - int pivot = low + (int) floor((high - low) / 2); + int pivot = low + (int)floor((high - low) / 2); double pivot_value = xs[pivot]; swp(pivot, high, xs); int gt = low; /* This pointer will iterate until finding an element which is greater than the pivot. Then it will move elements that are smaller before it--more specifically, it will move elements to its position and then increment. As a result all elements between gt and i will be greater than the pivot. */ @@ -125,8 +125,8 @@ static double quickselect(int k, double xs[], int n) ci array_get_ci(ci interval, double* xs, int n) { - int low_k = (int) floor(interval.low * n); - int high_k = (int) ceil(interval.high * n); + int low_k = (int)floor(interval.low * n); + int high_k = (int)ceil(interval.high * n); ci result = { .low = quickselect(low_k, xs, n), .high = quickselect(high_k, xs, n), @@ -141,7 +141,7 @@ ci array_get_90_ci(double xs[], int n) ci sampler_get_ci(ci interval, double (*sampler)(uint64_t*), int n, uint64_t* seed) { UNUSED(seed); // don't want to use it right now, but want to preserve ability to do so (e.g., remove parallelism from internals). Also nicer for consistency. - double* xs = malloc((size_t) n * sizeof(double)); + double* xs = malloc((size_t)n * sizeof(double)); sampler_parallel(sampler, xs, 16, n); ci result = array_get_ci(interval, xs, n); free(xs);