From: 박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Tue, 8 May 2018 01:09:13 +0000 (+0900) Subject: [core.ADT.tensor] Add 'range' function (#205) X-Git-Tag: nncc_backup~2707 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0d8d0727de03c08a8a95c566fbc468ac3791e59;p=platform%2Fcore%2Fml%2Fnnfw.git [core.ADT.tensor] Add 'range' function (#205) This commit adds 'range' function which creates a 'IndexRange' object from a 'Shape' object. Signed-off-by: Jonghyun Park --- diff --git a/libs/core/include/nncc/core/ADT/tensor/IndexRange.h b/libs/core/include/nncc/core/ADT/tensor/IndexRange.h index df0bf7f..e592cc4 100644 --- a/libs/core/include/nncc/core/ADT/tensor/IndexRange.h +++ b/libs/core/include/nncc/core/ADT/tensor/IndexRange.h @@ -35,6 +35,8 @@ private: const Shape _shape; }; +IndexRange range(const Shape &shape); + } // namespace tensor } // namespace ADT } // namespace core diff --git a/libs/core/src/nncc/core/ADT/tensor/IndexRange.cpp b/libs/core/src/nncc/core/ADT/tensor/IndexRange.cpp index 5636c25..9d10e1b 100644 --- a/libs/core/src/nncc/core/ADT/tensor/IndexRange.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/IndexRange.cpp @@ -86,6 +86,8 @@ void IndexRange::iterate(const std::function &f) const } } +IndexRange range(const Shape &shape) { return IndexRange{shape}; } + } // namespace tensor } // namespace ADT } // namespace core diff --git a/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp b/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp index 5537af4..bcf3cfb 100644 --- a/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/IndexRange.test.cpp @@ -61,3 +61,22 @@ TEST(ADT_TENSOR_INDEX_RANGE, iterate_full_range) ASSERT_TRUE(std::all_of(count.begin(), count.end(), [](uint32_t n) { return n == 1; })); } + +TEST(ADT_TENSOR_INDEX_RANGE, range) +{ + const nncc::core::ADT::tensor::Shape shape{3, 4}; + + std::array count; + + count.fill(0); + + using nncc::core::ADT::tensor::Index; + using nncc::core::ADT::tensor::range; + + range(shape).iterate() << [&count](const Index &i) { + ASSERT_EQ(i.rank(), 2); + count.at(i.at(0) * 4 + i.at(1)) += 1; + }; + + ASSERT_TRUE(std::all_of(count.begin(), count.end(), [](uint32_t n) { return n == 1; })); +}