diff --git a/examples/core/01_one_sample/example.c b/examples/core/01_one_sample/example.c index ef3b90b..9c3978e 100644 --- a/examples/core/01_one_sample/example.c +++ b/examples/core/01_one_sample/example.c @@ -5,11 +5,13 @@ // Estimate functions double sample_0(uint64_t* seed) { + UNUSED(seed); return 0; } double sample_1(uint64_t* seed) { + UNUSED(seed); return 1; } diff --git a/examples/core/02_time_to_botec/example.c b/examples/core/02_time_to_botec/example.c index 908b8df..199135f 100644 --- a/examples/core/02_time_to_botec/example.c +++ b/examples/core/02_time_to_botec/example.c @@ -12,8 +12,8 @@ int main() double p_b = 0.5; double p_c = p_a * p_b; - double sample_0(uint64_t * seed) { return 0; } - double sample_1(uint64_t * 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); } diff --git a/examples/core/03_gcc_nested_function/example.c b/examples/core/03_gcc_nested_function/example.c index 54dcd0f..8c8bb30 100644 --- a/examples/core/03_gcc_nested_function/example.c +++ b/examples/core/03_gcc_nested_function/example.c @@ -15,8 +15,8 @@ int main() int n_dists = 4; // These are nested functions. They will not compile without gcc. - double sample_0(uint64_t * seed) { return 0; } - double sample_1(uint64_t * 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); } diff --git a/examples/core/makefile b/examples/core/makefile index 48b1706..8389813 100644 --- a/examples/core/makefile +++ b/examples/core/makefile @@ -23,9 +23,8 @@ DEPS=$(SQUIGGLE) $(MATH) ## Flags DEBUG= #'-g' -WARN=-Wall -Wextra -Wno-unused-parameter +WARN=-Wall -Wextra STANDARD=-std=c99 -WARNINGS=-Wall OPTIMIZED=-O3 #-Ofast ## Formatter @@ -34,10 +33,10 @@ FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) ## make all all: - $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 00_example_template/$(SRC) $(DEPS) -o 00_example_template/$(OUTPUT) - $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 01_one_sample/$(SRC) $(DEPS) -o 01_one_sample/$(OUTPUT) - $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 02_time_to_botec/$(SRC) $(DEPS) -o 02_time_to_botec/$(OUTPUT) - $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 03_gcc_nested_function/$(SRC) $(DEPS) -o 03_gcc_nested_function/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 00_example_template/$(SRC) $(DEPS) -o 00_example_template/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 01_one_sample/$(SRC) $(DEPS) -o 01_one_sample/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 02_time_to_botec/$(SRC) $(DEPS) -o 02_time_to_botec/$(OUTPUT) + $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 03_gcc_nested_function/$(SRC) $(DEPS) -o 03_gcc_nested_function/$(OUTPUT) $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 04_gamma_beta/$(SRC) $(DEPS) -o 04_gamma_beta/$(OUTPUT) $(CC) $(OPTIMIZED) $(DEBUG) $(WARN) 05_hundred_lognormals/$(SRC) $(DEPS) -o 05_hundred_lognormals/$(OUTPUT) diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example index 13faf0b..a2a250c 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 fa30618..43f755b 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 09a872d..0abba93 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 dd0554a..0aa47ae 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 162faa5..326e9e8 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 78ce7aa..7587f9e 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 99590aa..e2a805d 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 1ec780a..3d6fa9d 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 4b206e5..faedee9 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 47723d9..18c369b 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 5a93e07..e38184b 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/10_twitter_thread_example/example.c b/examples/more/10_twitter_thread_example/example.c index c7d8937..5c67dd8 100644 --- a/examples/more/10_twitter_thread_example/example.c +++ b/examples/more/10_twitter_thread_example/example.c @@ -5,11 +5,13 @@ double sample_0(uint64_t* seed) { + UNUSED(seed); return 0; } double sample_1(uint64_t* seed) { + UNUSED(seed); return 1; } diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example index 7289d0a..428a9ef 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 756ea5c..372be00 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/12_time_to_botec_parallel/example.c b/examples/more/12_time_to_botec_parallel/example.c index 72974cf..82c344f 100644 --- a/examples/more/12_time_to_botec_parallel/example.c +++ b/examples/more/12_time_to_botec_parallel/example.c @@ -9,8 +9,8 @@ int main() double p_b = 0.5; double p_c = p_a * p_b; - double sample_0(uint64_t * seed) { return 0; } - double sample_1(uint64_t * 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); } diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example index f44dd39..6b18753 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 633ea0b..293742c 100755 Binary files a/examples/more/14_check_confidence_interval/example and b/examples/more/14_check_confidence_interval/example differ diff --git a/examples/more/makefile b/examples/more/makefile index b9a6108..3ecb356 100644 --- a/examples/more/makefile +++ b/examples/more/makefile @@ -25,7 +25,7 @@ DEPS=$(SQUIGGLE) $(SQUIGGLE_MORE) $(MATH) $(OPENMP) ## Flags DEBUG= #'-g' -WARN=-Wall -Wextra -Wno-unused-parameter +WARN=-Wall -Wextra STANDARD=-std=c99 WARNINGS=-Wall OPTIMIZED=-O3 #-Ofast diff --git a/squiggle.c b/squiggle.c index 0e5950f..ab37da9 100644 --- a/squiggle.c +++ b/squiggle.c @@ -3,9 +3,11 @@ #include #include -// math constants +// Defs #define PI 3.14159265358979323846 // M_PI in gcc gnu99 #define NORMAL90CONFIDENCE 1.6448536269514727 +#define UNUSED(x) (void)(x) +// ^ https://stackoverflow.com/questions/3599160/how-can-i-suppress-unused-parameter-warnings-in-c // Pseudo Random number generators diff --git a/squiggle.h b/squiggle.h index 6f18038..8fe507e 100644 --- a/squiggle.h +++ b/squiggle.h @@ -30,4 +30,7 @@ double array_std(double* array, int length); // Mixture function double sample_mixture(double (*samplers[])(uint64_t*), double* weights, int n_dists, uint64_t* seed); +// Trick to mute unused variable warning. Useful for nested functions +#define UNUSED(x) (void)(x) + #endif diff --git a/squiggle_more.c b/squiggle_more.c index de3494f..dc75565 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -83,6 +83,10 @@ 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){ + 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 + floor((high - low) / 2); double pivot_value = xs[pivot]; @@ -136,6 +140,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(n * sizeof(double)); sampler_parallel(sampler, xs, 16, n); ci result = array_get_ci(interval, xs, n); @@ -216,7 +221,7 @@ typedef struct box_t { box process_error(const char* error_msg, int should_exit, char* file, int line) { if (should_exit) { - printf("@, in %s (%d)", file, line); + printf("%s, @, in %s (%d)", error_msg, file, line); exit(1); } else { char error_msg[MAX_ERROR_LENGTH];