Skip to content

Commit b21dfbe

Browse files
committed
Keep the intermediate values in float64.
1 parent 2fbe721 commit b21dfbe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bottleneck/src/move_template.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ mover(char *name,
7474
/* dtype = [['float64'], ['float32']] */
7575
MOVE(move_sum, DTYPE0) {
7676
Py_ssize_t count;
77-
npy_DTYPE0 asum, ai, aold;
77+
// Keep the intermediate values in float64 to reduce precision error.
78+
// See issue pydata/bottleneck#164.
79+
npy_float64 asum, ai, aold;
7880
INIT(NPY_DTYPE0)
7981
BN_BEGIN_ALLOW_THREADS
8082
WHILE {
@@ -156,7 +158,9 @@ MOVE_MAIN(move_sum, 0)
156158
/* dtype = [['float64'], ['float32']] */
157159
MOVE(move_mean, DTYPE0) {
158160
Py_ssize_t count;
159-
npy_DTYPE0 asum, ai, aold, count_inv;
161+
// Keep the intermediate values in float64 to reduce precision error.
162+
// See issue pydata/bottleneck#164.
163+
npy_float64 asum, ai, aold, count_inv;
160164
INIT(NPY_DTYPE0)
161165
BN_BEGIN_ALLOW_THREADS
162166
WHILE {
@@ -244,7 +248,9 @@ MOVE_MAIN(move_mean, 0)
244248
/* dtype = [['float64'], ['float32']] */
245249
MOVE(NAME, DTYPE0) {
246250
Py_ssize_t count;
247-
npy_DTYPE0 delta, amean, assqdm, ai, aold, yi, count_inv, ddof_inv;
251+
// Keep the intermediate values in float64 to reduce precision error.
252+
// See issue pydata/bottleneck#164.
253+
npy_float64 delta, amean, assqdm, ai, aold, yi, count_inv, ddof_inv;
248254
INIT(NPY_DTYPE0)
249255
BN_BEGIN_ALLOW_THREADS
250256
WHILE {

0 commit comments

Comments
 (0)