diff --git a/C/samples/samples b/C/samples/samples index daa280ab..f0e7e3aa 100755 Binary files a/C/samples/samples and b/C/samples/samples differ diff --git a/C/samples/samples.c b/C/samples/samples.c index 1614b962..95f8ff02 100755 --- a/C/samples/samples.c +++ b/C/samples/samples.c @@ -4,7 +4,7 @@ #include #include -#define N 10000000 +#define N 1000000 /* * For very high values of N, you will want to increase the maximum stack trace, otherwise you will suffer a segmentation fault * In Ubuntu/bash you can do this with $ ulimit -Ss 256000 ## ~256Mbs @@ -89,9 +89,10 @@ void mixture(gsl_rng * r, double *dists[], double *weights, int n, double *resul } } if(index_found == 0) { - printf("\nThis shouldn't have happened"); + printf("\nThis shouldn't be able to happen"); // gsl_rng_free (r); // abort(); // this shouldn't have happened. + }else{ int sample_index = (int) floor(p_2 * N); results[i] = dists[index_counter][sample_index]; diff --git a/R/samples.R b/R/samples.R index 22f492d6..602463f0 100644 --- a/R/samples.R +++ b/R/samples.R @@ -25,6 +25,9 @@ mixture <- function(samples_list, weights_array, n=DEFAULT_N){ # note that this for(i in c(1:n)){ helper_which_list = which(cummulative_sums > helper_probs[i]) # helper_loc = ifelse(is.na(helper_which_list[1]), 1, helper_which_list[1]) + if(is.na(helper_which_list[1])){ + print("This should never happen") + } helper_loc = helper_which_list[1] target_samples = samples_list[[helper_loc]] result = sample(target_samples, 1) diff --git a/js/samples.js b/js/samples.js index c56f463a..b7a5c0dc 100644 --- a/js/samples.js +++ b/js/samples.js @@ -38,6 +38,9 @@ const mixture = (dists_array, weights_array, n = DEFAULT_N) => { const helper_probs = [...new Array(n)].map(_ => Math.random()) const results = helper_probs.map(p => { let match_index = cummulative_sums.findIndex(x => x > p) + if(match_index == -1){ + console.log("Error: This should never happen.") + } let target_loc = match_index // == -1 ? 0 : match_index let target_samples = dists_array[target_loc] return target_samples[Math.floor(Math.random() * target_samples.length)]; diff --git a/python/samples.py b/python/samples.py index 0c6ddeb8..e29208f6 100644 --- a/python/samples.py +++ b/python/samples.py @@ -32,7 +32,8 @@ def mixture(samples_list, weights_array, n=DEFAULT_N): helper_list = [j for j in range( len(cummulative_sums)) if cummulative_sums[j] > helper_probs[i]] if len(helper_list) == 0: - helper_loc = 0 + helper_loc = 0 # continue + print("This should never happen") else: helper_loc = helper_list[0] target_samples = samples_list[helper_loc]