From 48459f932233823293ef1ff6d41fd59cdddd0486 Mon Sep 17 00:00:00 2001 From: Przemyslaw Tredak Date: Tue, 30 Apr 2019 21:18:11 +0200 Subject: [PATCH] Fix iterator over symbol when multiple children have the same name (#14597) --- python/mxnet/symbol/symbol.py | 2 +- tests/python/unittest/test_symbol.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/mxnet/symbol/symbol.py b/python/mxnet/symbol/symbol.py index 4bf60a6a1fcd..0924b2fd9ee8 100644 --- a/python/mxnet/symbol/symbol.py +++ b/python/mxnet/symbol/symbol.py @@ -90,7 +90,7 @@ def __iter__(self): """ - return (self[i] for i in self.list_outputs()) + return (self[i] for i in range(len(self))) def __add__(self, other): """x.__add__(y) <=> x+y diff --git a/tests/python/unittest/test_symbol.py b/tests/python/unittest/test_symbol.py index b290ff344227..2dfe3e44eedb 100644 --- a/tests/python/unittest/test_symbol.py +++ b/tests/python/unittest/test_symbol.py @@ -367,6 +367,11 @@ def test_simple_bind_gradient_graph_possible_with_cycle(): res = data + data + data + data + data + data + data + data res.simple_bind(ctx=mx.cpu(), data=(1,)) +def test_children_same_name(): + a = mx.sym.Variable('data') + b = a + a + for c in b.get_children(): + pass if __name__ == '__main__': import nose