From: 김수진/동작제어Lab(SR)/Engineer/삼성전자 Date: Fri, 24 Aug 2018 03:46:10 +0000 (+0900) Subject: [neurun] Introduce contains in IndexSet (#2457) X-Git-Tag: 0.2~181 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0860ad4ea6b7a59f8220d93c2af86bca63e60e0;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Introduce contains in IndexSet (#2457) This commit introduces contains helper in IndexSet for checking if index of operand is exist. Signed-off-by: sjsujinkim --- diff --git a/runtimes/neurun/src/graph/operand/IndexSet.cc b/runtimes/neurun/src/graph/operand/IndexSet.cc index fb80d17..9f4d46f 100644 --- a/runtimes/neurun/src/graph/operand/IndexSet.cc +++ b/runtimes/neurun/src/graph/operand/IndexSet.cc @@ -22,6 +22,11 @@ IndexSet::IndexSet(std::initializer_list list) } } +bool IndexSet::contains(const Index &index) const +{ + return std::find(_set.begin(), _set.end(), index) != _set.end(); +} + } // namespace operand } // namespace graph } // namespace neurun diff --git a/runtimes/neurun/src/graph/operand/IndexSet.h b/runtimes/neurun/src/graph/operand/IndexSet.h index b7379a1..b4992b2 100644 --- a/runtimes/neurun/src/graph/operand/IndexSet.h +++ b/runtimes/neurun/src/graph/operand/IndexSet.h @@ -27,6 +27,7 @@ public: uint32_t size() const { return static_cast(_set.size()); } const std::vector &list() const { return _set; } const Index &at(IO::Index set_index) const { return _set.at(set_index.asInt()); } + bool contains(const Index &index) const; private: std::vector _set; diff --git a/runtimes/neurun/test/graph/operand/IndexSet.cc b/runtimes/neurun/test/graph/operand/IndexSet.cc index a533796..bc8625c 100644 --- a/runtimes/neurun/test/graph/operand/IndexSet.cc +++ b/runtimes/neurun/test/graph/operand/IndexSet.cc @@ -20,4 +20,8 @@ TEST(graph_operand_IndexSet, index_set_test) ASSERT_EQ(iset.at(index1), 2); ASSERT_EQ(iset.at(index2), 10); + + ASSERT_TRUE(iset.contains(Index{2})); + ASSERT_TRUE(iset.contains(Index{10})); + ASSERT_FALSE(iset.contains(Index{11})); }