[neurun] Graph : Introduce operand IndexSet (#2209)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 8 Aug 2018 08:36:25 +0000 (17:36 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 8 Aug 2018 08:36:25 +0000 (17:36 +0900)
`neurun::graph::operand::IndexSet` is a list of `Index`.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/operand/IndexSet.cc [new file with mode: 0644]
runtimes/neurun/src/graph/operand/IndexSet.h [new file with mode: 0644]
runtimes/neurun/test/operand/IndexSet.cc [new file with mode: 0644]

diff --git a/runtimes/neurun/src/graph/operand/IndexSet.cc b/runtimes/neurun/src/graph/operand/IndexSet.cc
new file mode 100644 (file)
index 0000000..fb80d17
--- /dev/null
@@ -0,0 +1,27 @@
+#include "IndexSet.h"
+
+#include <algorithm>
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+IndexSet::IndexSet(std::initializer_list<Index> list) : _set(list)
+{
+  // DO NOTHING
+}
+
+IndexSet::IndexSet(std::initializer_list<int32_t> list)
+{
+  for (auto val : list)
+  {
+    _set.emplace_back(static_cast<uint32_t>(val));
+  }
+}
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
diff --git a/runtimes/neurun/src/graph/operand/IndexSet.h b/runtimes/neurun/src/graph/operand/IndexSet.h
new file mode 100644 (file)
index 0000000..df57b84
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __NEURUN_GRAPH_OPERAND_INDEX_SET_H__
+#define __NEURUN_GRAPH_OPERAND_INDEX_SET_H__
+
+#include <initializer_list>
+#include <vector>
+
+#include "graph/operand/Index.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+class IndexSet
+{
+public:
+  IndexSet(void) = default;
+  IndexSet(std::initializer_list<Index> list);
+  IndexSet(std::initializer_list<int32_t> list);
+
+public:
+  void append(const Index &index) { _set.emplace_back(index); }
+
+public:
+  uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
+  const Index &at(uint32_t set_index) const { return _set.at(set_index); }
+  const std::vector<Index> &list() const { return _set; }
+
+private:
+  std::vector<Index> _set;
+};
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_INDEX_SET_H__
diff --git a/runtimes/neurun/test/operand/IndexSet.cc b/runtimes/neurun/test/operand/IndexSet.cc
new file mode 100644 (file)
index 0000000..b9754fd
--- /dev/null
@@ -0,0 +1,20 @@
+#include <gtest/gtest.h>
+
+#include "graph/operand/IndexSet.h"
+
+using neurun::graph::operand::Index;
+using neurun::graph::operand::IndexSet;
+
+TEST(graph_operand_IndexSet, index_set_test)
+{
+  IndexSet iset{0, 1, 2, 3};
+
+  ASSERT_EQ(iset.size(), 4);
+
+  iset.append(Index{4});
+
+  ASSERT_EQ(iset.size(), 5);
+
+  ASSERT_EQ(iset.at(0), 0);
+  ASSERT_EQ(iset.at(4), 4);
+}