From: 이한종/동작제어Lab(SR)/Engineer/삼성전자 Date: Wed, 8 Aug 2018 08:26:20 +0000 (+0900) Subject: [neurun] Graph : Introduce operand Set (#2208) X-Git-Tag: 0.2~326 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae5596cd3da9311e498b9211ab1d791c8ed1652c;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] Graph : Introduce operand Set (#2208) `neurun::graph::operand::Set` holds operands and also has ownership of them. Signed-off-by: Hanjoung Lee --- 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); +}