Skip to content

Commit 3b73ae9

Browse files
author
Kurt Smith
committed
Fixes issue #403.
1 parent 9b34b3a commit 3b73ae9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

distarray/dist/tests/test_distarray.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,22 @@ def test_create_target_subset(self):
722722
self.assertEqual(len(ddpr), len(subtargets))
723723

724724

725+
class TestReductionRegression(ContextTestCase):
726+
''' Separate class necessary b/c need to run on at least 9 engines to exercise
727+
regression.
728+
729+
'''
730+
731+
ntargets = 9
732+
733+
def test_reduction(self):
734+
""" Tests that GH issue 403 is fixed """
735+
arr = numpy.arange(9 * 9).reshape(9, 9)
736+
dist = Distribution(self.context, arr.shape, ('b', 'b'), (9, 1))
737+
darr = self.context.fromndarray(arr, dist)
738+
assert_allclose(darr.sum().tondarray(), arr.sum())
739+
740+
725741
class TestReduceMethods(ContextTestCase):
726742
"""Test reduction methods"""
727743

distarray/local/localarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ def _basic_reducer(reduce_comm, op, func, args, kwargs, out):
954954
out_ndarray = out.ndarray
955955
if out.ndarray.dtype == np.bool:
956956
out.ndarray.dtype = np.uint8
957-
local_reduce = func(*args, **kwargs)
957+
# Use asarray() to coerce np scalars to zero-dimensional arrays.
958+
local_reduce = np.asarray(func(*args, **kwargs))
958959
reduce_comm.Reduce(local_reduce, out_ndarray, op=op, root=0)
959960
return out
960961

0 commit comments

Comments
 (0)