[neurun] Graph : Introduce operand Set (#2208)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Wed, 8 Aug 2018 08:26:20 +0000 (17:26 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 8 Aug 2018 08:26:20 +0000 (17:26 +0900)
`neurun::graph::operand::Set` holds operands and also has ownership of
them.

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

diff --git a/runtimes/neurun/src/graph/operand/Set.cc b/runtimes/neurun/src/graph/operand/Set.cc
new file mode 100644 (file)
index 0000000..8215241
--- /dev/null
@@ -0,0 +1,33 @@
+#include "Set.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+Index Set::append(const ::internal::tflite::operand::Shape &shape)
+{
+  uint32_t index = _objects.size();
+
+  _objects.emplace_back(new ::internal::tflite::operand::Object{shape});
+
+  return Index{index};
+}
+
+const ::internal::tflite::operand::Object &Set::at(const Index &index) const
+{
+  return *(_objects.at(index.asInt()));
+}
+
+::internal::tflite::operand::Object &Set::at(const Index &index)
+{
+  return *(_objects.at(index.asInt()));
+}
+
+bool Set::exist(const Index &index) const { return index.asInt() < _objects.size(); }
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
diff --git a/runtimes/neurun/src/graph/operand/Set.h b/runtimes/neurun/src/graph/operand/Set.h
new file mode 100644 (file)
index 0000000..0d24f8a
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __NEURUN_GRAPH_OPERAND_SET_H__
+#define __NEURUN_GRAPH_OPERAND_SET_H__
+
+#include <memory>
+#include <vector>
+
+#include "internal/Model.h"
+#include "Index.h"
+
+namespace neurun
+{
+namespace graph
+{
+namespace operand
+{
+
+class Set
+{
+public:
+  Set() = default;
+
+public:
+  Index append(const ::internal::tflite::operand::Shape &);
+
+public:
+  const ::internal::tflite::operand::Object &at(const Index &) const;
+  ::internal::tflite::operand::Object &at(const Index &);
+  bool exist(const Index &) const;
+
+private:
+  std::vector<std::unique_ptr<::internal::tflite::operand::Object>> _objects;
+};
+
+} // namespace operand
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_OPERAND_SET_H__
diff --git a/runtimes/neurun/test/operand/Set.cc b/runtimes/neurun/test/operand/Set.cc
new file mode 100644 (file)
index 0000000..0b6c378
--- /dev/null
@@ -0,0 +1,30 @@
+#include <gtest/gtest.h>
+
+#include "graph/operand/Set.h"
+
+TEST(graph_operand_Set, set_test)
+{
+  neurun::graph::operand::Set set;
+
+  internal::tflite::operand::Shape shape0{3};
+  shape0.dim(0) = 1;
+  shape0.dim(1) = 2;
+  shape0.dim(2) = 3;
+
+  internal::tflite::operand::Shape shape1{4};
+  shape1.dim(0) = 10;
+  shape1.dim(1) = 20;
+  shape1.dim(2) = 30;
+  shape1.dim(3) = 40;
+
+  set.append(shape0);
+  set.append(shape1);
+
+  ASSERT_EQ(set.exist(neurun::graph::operand::Index{0u}), true);
+  ASSERT_EQ(set.exist(neurun::graph::operand::Index{1u}), true);
+  ASSERT_EQ(set.exist(neurun::graph::operand::Index{2u}), false);
+
+  ASSERT_EQ(set.at(neurun::graph::operand::Index{0u}).shape().dim(0), 1);
+  ASSERT_EQ(set.at(neurun::graph::operand::Index{0u}).shape().dim(1), 2);
+  ASSERT_EQ(set.at(neurun::graph::operand::Index{0u}).shape().dim(2), 3);
+}