[core] Add 'num_elements' on feature shape (#252)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 31 May 2018 23:46:32 +0000 (08:46 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 31 May 2018 23:46:32 +0000 (08:46 +0900)
This commit adds 'num_elements' for feature shape similarly as 'num_elements'
for tensor shape.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
libs/core/include/nncc/core/ADT/feature/Shape.h
libs/core/src/ADT/feature/Shape.test.cpp

index ec10345..38b7d22 100644 (file)
@@ -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
index 4d92581..8c4c080 100644 (file)
@@ -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);
+}