Skip to content

Commit

Permalink
Fixed style and added check for bounds in [-pi,pi] interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
Androp0v authored and bashtage committed Feb 26, 2021
1 parent b16dc4a commit f26a7d2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions numpy/random/src/distributions/distributions.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,19 +844,30 @@ double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa) {
}
if (kappa < 1e-8) {
return M_PI * (2 * next_double(bitgen_state) - 1);
} else {
}
else {
/* with double precision rho is zero until 1.4e-8 */
if (kappa < 1e-5) {
/*
* second order taylor expansion around kappa = 0
* precise until relatively large kappas as second order is 0
*/
s = (1. / kappa + kappa);
} else {
/* Fallback to normal distribution for big values of kappa*/
if (kappa > 1e6){
return mu + sqrt(1/kappa) * random_standard_normal(bitgen_state);
}else{
}
else {
/* Fallback to normal distribution for big values of kappa */
if (kappa > 1e6) {
result = mu + sqrt(1. / kappa) * random_standard_normal(bitgen_state);
/* Check if result is within bounds */
if (result < -M_PI) {
return result + 2*M_PI;
}
if (result > M_PI) {
return result - 2*M_PI;
}
return result;
}
else {
double r = 1 + sqrt(1 + 4 * kappa * kappa);
double rho = (r - sqrt(2 * r)) / (2 * kappa);
s = (1 + rho * rho) / (2 * rho);
Expand Down

0 comments on commit f26a7d2

Please sign in to comment.