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

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

index 6376aae..18d3dcb 100644 (file)
@@ -37,6 +37,11 @@ private:
   uint32_t _width;
 };
 
+inline uint64_t num_elements(const Shape &shape)
+{
+  return shape.count() * shape.depth() * shape.height() * shape.width();
+}
+
 } // namespace kernel
 } // namespace ADT
 } // namespace core
index f050964..59cf69f 100644 (file)
@@ -16,3 +16,16 @@ TEST(ADT_KERNEL_SHAPE, ctor)
   ASSERT_EQ(shape.height(), H);
   ASSERT_EQ(shape.width(), W);
 }
+
+TEST(ADT_KERNEL_SHAPE, num_elements)
+{
+  const uint32_t N = 1;
+  const uint32_t C = 3;
+  const uint32_t H = 4;
+  const uint32_t W = 5;
+
+  using nncc::core::ADT::kernel::Shape;
+  using nncc::core::ADT::kernel::num_elements;
+
+  ASSERT_EQ(num_elements(Shape{N, C, H, W}), N * C * H * W);
+}