[neurun] Introduce contains in IndexSet (#2457)
author김수진/동작제어Lab(SR)/Engineer/삼성전자 <sjsujin.kim@samsung.com>
Fri, 24 Aug 2018 03:46:10 +0000 (12:46 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 24 Aug 2018 03:46:10 +0000 (12:46 +0900)
This commit introduces contains helper in IndexSet for checking if index of operand is exist.

Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
runtimes/neurun/src/graph/operand/IndexSet.cc
runtimes/neurun/src/graph/operand/IndexSet.h
runtimes/neurun/test/graph/operand/IndexSet.cc

index fb80d17..9f4d46f 100644 (file)
@@ -22,6 +22,11 @@ IndexSet::IndexSet(std::initializer_list<int32_t> list)
   }
 }
 
+bool IndexSet::contains(const Index &index) const
+{
+  return std::find(_set.begin(), _set.end(), index) != _set.end();
+}
+
 } // namespace operand
 } // namespace graph
 } // namespace neurun
index b7379a1..b4992b2 100644 (file)
@@ -27,6 +27,7 @@ public:
   uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
   const std::vector<Index> &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<Index> _set;
index a533796..bc8625c 100644 (file)
@@ -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}));
 }