From b21dfbe86d76c31492aa710d1a5e14c66250d1f4 Mon Sep 17 00:00:00 2001 From: jkadbear Date: Sat, 19 Mar 2022 21:41:05 +0800 Subject: [PATCH] Keep the intermediate values in float64. --- bottleneck/src/move_template.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bottleneck/src/move_template.c b/bottleneck/src/move_template.c index 8a589703d..2b230172e 100644 --- a/bottleneck/src/move_template.c +++ b/bottleneck/src/move_template.c @@ -74,7 +74,9 @@ mover(char *name, /* dtype = [['float64'], ['float32']] */ MOVE(move_sum, DTYPE0) { Py_ssize_t count; - npy_DTYPE0 asum, ai, aold; + // Keep the intermediate values in float64 to reduce precision error. + // See issue pydata/bottleneck#164. + npy_float64 asum, ai, aold; INIT(NPY_DTYPE0) BN_BEGIN_ALLOW_THREADS WHILE { @@ -156,7 +158,9 @@ MOVE_MAIN(move_sum, 0) /* dtype = [['float64'], ['float32']] */ MOVE(move_mean, DTYPE0) { Py_ssize_t count; - npy_DTYPE0 asum, ai, aold, count_inv; + // Keep the intermediate values in float64 to reduce precision error. + // See issue pydata/bottleneck#164. + npy_float64 asum, ai, aold, count_inv; INIT(NPY_DTYPE0) BN_BEGIN_ALLOW_THREADS WHILE { @@ -244,7 +248,9 @@ MOVE_MAIN(move_mean, 0) /* dtype = [['float64'], ['float32']] */ MOVE(NAME, DTYPE0) { Py_ssize_t count; - npy_DTYPE0 delta, amean, assqdm, ai, aold, yi, count_inv, ddof_inv; + // Keep the intermediate values in float64 to reduce precision error. + // See issue pydata/bottleneck#164. + npy_float64 delta, amean, assqdm, ai, aold, yi, count_inv, ddof_inv; INIT(NPY_DTYPE0) BN_BEGIN_ALLOW_THREADS WHILE {