[pypy-commit] pypy default: test and fix for noncommutative accumulate segfault
bdkearns
noreply at buildbot.pypy.org
Tue Oct 29 20:33:12 CET 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r67700:db79497dfb4f
Date: 2013-10-29 13:37 -0400
http://bitbucket.org/pypy/pypy/changeset/db79497dfb4f/
Log: test and fix for noncommutative accumulate segfault
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -162,7 +162,13 @@
def compute_reduce_cumulative(obj, out, calc_dtype, func, identity):
obj_iter = obj.create_iter()
out_iter = out.create_iter()
- cur_value = identity.convert_to(calc_dtype)
+ if identity is None:
+ cur_value = obj_iter.getitem().convert_to(calc_dtype)
+ out_iter.setitem(cur_value)
+ out_iter.next()
+ obj_iter.next()
+ else:
+ cur_value = identity.convert_to(calc_dtype)
shapelen = len(obj.get_shape())
while not obj_iter.done():
reduce_cum_driver.jit_merge_point(shapelen=shapelen, func=func,
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -1066,3 +1066,14 @@
print b
assert (b == [[0, 0, 1], [1, 3, 5]]).all()
assert b.dtype == int
+
+ def test_noncommutative_reduce_accumulate(self):
+ import numpypy as np
+ tosubtract = np.arange(5)
+ todivide = np.array([2.0, 0.5, 0.25])
+ assert np.subtract.reduce(tosubtract) == -10
+ assert np.divide.reduce(todivide) == 16.0
+ assert (np.subtract.accumulate(tosubtract) ==
+ np.array([0, -1, -3, -6, -10])).all()
+ assert (np.divide.accumulate(todivide) ==
+ np.array([2., 4., 16.])).all()
More information about the pypy-commit
mailing list