Skip to content

Commit

Permalink
Bug/1017 prod / sum with empty arrays (#1018)
Browse files Browse the repository at this point in the history
* Check for split in `__reduce_op`

* Check whether x is distributed

Co-authored-by: mtar <m.tarnawa@fz-juelich.de>

Co-authored-by: mtar <m.tarnawa@fz-juelich.de>
Co-authored-by: Claudia Comito <39374113+ClaudiaComito@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 5, 2022
1 parent 398ac0d commit 2fe13c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion heat/core/_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def __reduce_op(
balanced = x.balanced

# if local tensor is empty, replace it with the identity element
if 0 in x.lshape and (axis is None or (x.split in axis)):
if x.is_distributed() and 0 in x.lshape and (axis is None or split in axis):
if neutral is None:
neutral = float("nan")
neutral_shape = x.gshape[:split] + (1,) + x.gshape[split + 1 :]
Expand Down
8 changes: 8 additions & 0 deletions heat/core/tests/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ def test_prod(self):
self.assertEqual(shape_split_axis_tuple_prod.split, None)
self.assertTrue((shape_split_axis_tuple_prod == expected_result).all())

# empty array
empty = ht.array([])
self.assertEqual(ht.prod(empty), ht.array([1.0]))

# exceptions
with self.assertRaises(ValueError):
ht.ones(array_len).prod(axis=1)
Expand Down Expand Up @@ -792,6 +796,10 @@ def test_sum(self):
self.assertEqual(shape_split_axis_tuple_sum.split, None)
self.assertTrue((shape_split_axis_tuple_sum == expected_result).all())

# empty array
empty = ht.array([])
self.assertEqual(ht.sum(empty), ht.array([0.0]))

# exceptions
with self.assertRaises(ValueError):
ht.ones(array_len).sum(axis=1)
Expand Down

0 comments on commit 2fe13c3

Please sign in to comment.