From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 7 Sep 2018 02:12:31 +0000 (+0900) Subject: [coco] Introduce Shuffle::range (#1400) X-Git-Tag: nncc_backup~1892 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a692c05c9414d185470a04050d65ec3ec4d73ed0;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Introduce Shuffle::range (#1400) This commit extends Shuffle class with range method which returns the set of elements that will be updated by Shuffle. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/Shuffle.h b/contrib/coco/core/include/coco/IR/Shuffle.h index 759ced7..f5ad240 100644 --- a/contrib/coco/core/include/coco/IR/Shuffle.h +++ b/contrib/coco/core/include/coco/IR/Shuffle.h @@ -10,6 +10,7 @@ #include "coco/ADT/PtrLink.h" #include +#include namespace coco { @@ -46,6 +47,10 @@ public: void into(Bag *); public: + // @brief Return a set of elements in the destination bag that Shuffle will update + std::set range(void) const; + +public: /** * Let M be the return of at(N). This means that N-th element in the destination * bag will be filled with the value of M-th element in the source bag. diff --git a/contrib/coco/core/src/IR/Shuffle.cpp b/contrib/coco/core/src/IR/Shuffle.cpp index afa1926..3accd5e 100644 --- a/contrib/coco/core/src/IR/Shuffle.cpp +++ b/contrib/coco/core/src/IR/Shuffle.cpp @@ -15,6 +15,18 @@ std::set &operator+=(std::set &res, coco::Bag *b) namespace coco { +std::set Shuffle::range(void) const +{ + std::set res; + + for (auto it = _content.begin(); it != _content.end(); ++it) + { + res.insert(it->first); + } + + return res; +} + void Shuffle::insert(const ElemID &from, const ElemID &into) { _content[into] = from; } std::set Shuffle::reads(void) const diff --git a/contrib/coco/core/src/IR/Shuffle.test.cpp b/contrib/coco/core/src/IR/Shuffle.test.cpp index 768d82f..c637cf7 100644 --- a/contrib/coco/core/src/IR/Shuffle.test.cpp +++ b/contrib/coco/core/src/IR/Shuffle.test.cpp @@ -48,3 +48,17 @@ TEST_F(ShuffleTest, asShuffle) ASSERT_NE(mutable_ptr->asShuffle(), nullptr); ASSERT_EQ(mutable_ptr->asShuffle(), immutable_ptr->asShuffle()); } + +TEST_F(ShuffleTest, range) +{ + auto shuffle = allocate(); + + shuffle->insert(coco::ElemID{3}, coco::ElemID{2}); + shuffle->insert(coco::ElemID{3}, coco::ElemID{5}); + + auto range = shuffle->range(); + + EXPECT_EQ(range.size(), 2); + EXPECT_NE(range.count(coco::ElemID{2}), 0); + EXPECT_NE(range.count(coco::ElemID{5}), 0); +}