From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 31 May 2018 23:46:32 +0000 (+0900) Subject: [core] Add 'num_elements' on feature shape (#252) X-Git-Tag: nncc_backup~2647 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=74c2ab05989fa607679d7e9f6cc64bc9c57e89a1;p=platform%2Fcore%2Fml%2Fnnfw.git [core] Add 'num_elements' on feature shape (#252) This commit adds 'num_elements' for feature shape similarly as 'num_elements' for tensor shape. Signed-off-by: Jonghyun Park --- diff --git a/libs/core/include/nncc/core/ADT/feature/Shape.h b/libs/core/include/nncc/core/ADT/feature/Shape.h index ec10345..38b7d22 100644 --- a/libs/core/include/nncc/core/ADT/feature/Shape.h +++ b/libs/core/include/nncc/core/ADT/feature/Shape.h @@ -35,6 +35,11 @@ private: uint32_t _width; }; +inline uint64_t num_elements(const Shape &shape) +{ + return shape.depth() * shape.height() * shape.width(); +} + } // namespace feature } // namespace ADT } // namespace core diff --git a/libs/core/src/ADT/feature/Shape.test.cpp b/libs/core/src/ADT/feature/Shape.test.cpp index 4d92581..8c4c080 100644 --- a/libs/core/src/ADT/feature/Shape.test.cpp +++ b/libs/core/src/ADT/feature/Shape.test.cpp @@ -14,3 +14,15 @@ TEST(ADT_FEATURE_SHAPE, ctor) ASSERT_EQ(shape.height(), H); ASSERT_EQ(shape.width(), W); } + +TEST(ADT_FEATURE_SHAPE, num_elements) +{ + const uint32_t C = 3; + const uint32_t H = 4; + const uint32_t W = 5; + + using nncc::core::ADT::feature::Shape; + using nncc::core::ADT::feature::num_elements; + + ASSERT_EQ(num_elements(Shape{C, H, W}), C * H * W); +}