From ae5596cd3da9311e498b9211ab1d791c8ed1652c 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, 8 Aug 2018 17:26:20 +0900 Subject: [PATCH] [neurun] Graph : Introduce operand Set (#2208) `neurun::graph::operand::Set` holds operands and also has ownership of them. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/operand/Set.cc | 33 +++++++++++++++++++++++++++ runtimes/neurun/src/graph/operand/Set.h | 38 ++++++++++++++++++++++++++++++++ runtimes/neurun/test/operand/Set.cc | 30 +++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 runtimes/neurun/src/graph/operand/Set.cc create mode 100644 runtimes/neurun/src/graph/operand/Set.h create mode 100644 runtimes/neurun/test/operand/Set.cc diff --git a/runtimes/neurun/src/graph/operand/Set.cc b/runtimes/neurun/src/graph/operand/Set.cc new file mode 100644 index 0000000..8215241 --- /dev/null +++ b/runtimes/neurun/src/graph/operand/Set.cc @@ -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 index 0000000..0d24f8a --- /dev/null +++ b/runtimes/neurun/src/graph/operand/Set.h @@ -0,0 +1,38 @@ +#ifndef __NEURUN_GRAPH_OPERAND_SET_H__ +#define __NEURUN_GRAPH_OPERAND_SET_H__ + +#include +#include + +#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> _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 index 0000000..0b6c378 --- /dev/null +++ b/runtimes/neurun/test/operand/Set.cc @@ -0,0 +1,30 @@ +#include + +#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); +} -- 2.7.4