diff options
author | seberg <sebastian@sipsolutions.net> | 2014-02-20 15:44:49 +0100 |
---|---|---|
committer | seberg <sebastian@sipsolutions.net> | 2014-02-20 15:44:49 +0100 |
commit | 0178b12f3cd9804df066d0045a75180177962831 (patch) | |
tree | 22ea499d97c5d24268630590fed5dd7202b88e27 | |
parent | 3aaf365b34158ceca0f80cb42e64a7e362302214 (diff) | |
parent | 871c73b181706937ef7e14aecb24b23f65ed0993 (diff) | |
download | numpy-0178b12f3cd9804df066d0045a75180177962831.tar.gz |
Merge pull request #4321 from juliantaylor/half-sum-fix
BUG: fix initialized half sum
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index a0edbc6dc..d6921efee 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -1791,20 +1791,19 @@ NPY_NO_EXPORT void HALF_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { if (IS_BINARY_REDUCE) { + char *iop1 = args[0]; + float io1 = npy_half_to_float(*(npy_half *)iop1); #if @PW@ - npy_half * iop1 = (npy_half *)args[0]; npy_intp n = dimensions[0]; - *iop1 @OP@= npy_float_to_half(pairwise_sum_HALF((npy_half *)args[1], n, - steps[1] / (npy_intp)sizeof(npy_half))); + io1 @OP@= pairwise_sum_HALF((npy_half *)args[1], n, + steps[1] / (npy_intp)sizeof(npy_half)); #else - char *iop1 = args[0]; - float io1 = npy_half_to_float(*(npy_half *)iop1); BINARY_REDUCE_LOOP_INNER { io1 @OP@= npy_half_to_float(*(npy_half *)ip2); } - *((npy_half *)iop1) = npy_float_to_half(io1); #endif + *((npy_half *)iop1) = npy_float_to_half(io1); } else { BINARY_LOOP { diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index b217936f7..f5a98431c 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -340,6 +340,10 @@ class TestUfunc(TestCase): assert_almost_equal(np.sum(d[-1::-2]), 250.) assert_almost_equal(np.sum(d[::-3]), 167.) assert_almost_equal(np.sum(d[-1::-3]), 167.) + # sum with first reduction entry != 0 + d = np.ones((1,), dtype=dt) + d += d + assert_almost_equal(d, 2.) def test_sum_complex(self): for dt in (np.complex64, np.complex128, np.clongdouble): @@ -361,6 +365,10 @@ class TestUfunc(TestCase): assert_almost_equal(np.sum(d[-1::-2]), 250. + 250j) assert_almost_equal(np.sum(d[::-3]), 167. + 167j) assert_almost_equal(np.sum(d[-1::-3]), 167. + 167j) + # sum with first reduction entry != 0 + d = np.ones((1,), dtype=dt) + 1j + d += d + assert_almost_equal(d, 2. + 2j) def test_inner1d(self): a = np.arange(6).reshape((2, 3)) |