Parallel PopGen Package
shared.cu
1 /*
2  * shared.cu
3  *
4  * Author: David Lawrie
5  * for cuda and rand functions used by both go_fish and by sfs
6  */
7 
8 #include "../_internal/shared.cuh"
9 
10 __device__ int RNG::ApproxRandBinomHelper(unsigned int i, float mean, float var, float N){
11  if(mean <= RNG_MEAN_BOUNDARY_NORM){
12  if(N < RNG_N_BOUNDARY_POIS_BINOM){ return binomcdfinv(uint_float_01(i), mean, mean/N, N); } else{ return poiscdfinv(uint_float_01(i), mean); }
13  }
14  else if(mean >= N-RNG_MEAN_BOUNDARY_NORM){ //flip side of binomial, when 1-p is small
15  if(N < RNG_N_BOUNDARY_POIS_BINOM){ return N - binomcdfinv(uint_float_01(i), N-mean, (N-mean)/N, N); } else{ return N - poiscdfinv(uint_float_01(i), N-mean); }
16  }
17  return round(normcdfinv(uint_float_01(i))*sqrtf(var)+mean);
18 }