From b56ec075647653c80ff5388c823916aaa6195d90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Wed, 17 Oct 2018 10:14:51 +0900 Subject: [PATCH] [neurun] Workaround for operand::Set iteration (#3196) `OperandPass` sometimes manipulate the set while iteration, this workaround forces the `iterate` method to iterate only elements that has been existed from the beginning of the iteration. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/operand/Set.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/runtimes/neurun/src/graph/operand/Set.cc b/runtimes/neurun/src/graph/operand/Set.cc index 60dad23..dff690a 100644 --- a/runtimes/neurun/src/graph/operand/Set.cc +++ b/runtimes/neurun/src/graph/operand/Set.cc @@ -57,9 +57,25 @@ void Set::iterate(const std::function &fn) void Set::iterate(const std::function &fn) { + // TODO Remove this workaround + // This implementation is a workaround in case of adding operands while iteration + // + // // Original Implementation (We probably should be back to this) + // for (auto &e : _objects) + // { + // fn(e.first, *e.second); + // } + + std::list l; + for (auto &e : _objects) { - fn(e.first, *e.second); + l.push_back(e.first); + } + + for (auto index : l) + { + fn(index, *_objects[index]); } } -- 2.7.4