fix: improve warnings for a check which should never fail

This commit is contained in:
NunoSempere 2022-12-01 16:10:29 +00:00
parent 72884d8e1e
commit 071bf00d7a
5 changed files with 11 additions and 3 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#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];

View File

@ -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)

View File

@ -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)];

View File

@ -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]