From 1b0383cf1a6df78e7568237254bf87a4c4d6cfdb Mon Sep 17 00:00:00 2001 From: Przemek Tredak Date: Tue, 2 Apr 2019 06:50:08 -0700 Subject: [PATCH] Fix iterator over symbol when multiple children have the same name --- 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 0c0a0a1e3c88..8644b9671b71 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