Skip to content

bpo-37798: Minor code formatting and comment clean-ups #15526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Modules/_statisticsmodule.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* statistics accelerator C extensor: _statistics module. */
/* statistics accelerator C extension: _statistics module. */

#include "Python.h"
#include "structmember.h"
Expand All @@ -10,11 +10,13 @@ module _statistics
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=864a6f59b76123b2]*/


static PyMethodDef speedups_methods[] = {
_STATISTICS__NORMAL_DIST_INV_CDF_METHODDEF
{NULL, NULL, 0, NULL}
};
/*
* There is no closed-form solution to the inverse CDF for the normal
* distribution, so we use a rational approximation instead:
* Wichura, M.J. (1988). "Algorithm AS241: The Percentage Points of the
* Normal Distribution". Applied Statistics. Blackwell Publishing. 37
* (3): 477–484. doi:10.2307/2347330. JSTOR 2347330.
*/

/*[clinic input]
_statistics._normal_dist_inv_cdf -> double
Expand All @@ -34,7 +36,7 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu,
// Algorithm AS 241: The Percentage Points of the Normal Distribution
if(fabs(q) <= 0.425) {
r = 0.180625 - q * q;
// Hash sum AB: 55.88319 28806 14901 4439
// Hash sum-55.8831928806149014439
num = (((((((2.5090809287301226727e+3 * r +
3.3430575583588128105e+4) * r +
6.7265770927008700853e+4) * r +
Expand All @@ -54,11 +56,11 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu,
x = num / den;
return mu + (x * sigma);
}
r = q <= 0.0? p : 1.0-p;
r = (q <= 0.0) ? p : (1.0 - p);
r = sqrt(-log(r));
if (r <= 5.0) {
r = r - 1.6;
// Hash sum CD: 49.33206 50330 16102 89036
// Hash sum-49.33206503301610289036
num = (((((((7.74545014278341407640e-4 * r +
2.27238449892691845833e-2) * r +
2.41780725177450611770e-1) * r +
Expand All @@ -77,7 +79,7 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu,
1.0);
} else {
r -= 5.0;
// Hash sum EF: 47.52583 31754 92896 71629
// Hash sum-47.52583317549289671629
num = (((((((2.01033439929228813265e-7 * r +
2.71155556874348757815e-5) * r +
1.24266094738807843860e-3) * r +
Expand All @@ -96,23 +98,30 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu,
1.0);
}
x = num / den;
if (q < 0.0) x = -x;
if (q < 0.0) {
x = -x;
}
return mu + (x * sigma);
}


static PyMethodDef statistics_methods[] = {
_STATISTICS__NORMAL_DIST_INV_CDF_METHODDEF
{NULL, NULL, 0, NULL}
};

static struct PyModuleDef statisticsmodule = {
PyModuleDef_HEAD_INIT,
"_statistics",
_statistics__normal_dist_inv_cdf__doc__,
-1,
speedups_methods,
statistics_methods,
NULL,
NULL,
NULL,
NULL
};


PyMODINIT_FUNC
PyInit__statistics(void)
{
Expand Down