[nncc.core] Set tensor::Shape values via constructor (#181)
author박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 2 May 2018 01:15:32 +0000 (10:15 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 2 May 2018 01:15:32 +0000 (10:15 +0900)
This commit introduces a constructor for tensor::Shape which takes an
initializer list as its argument.

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

index 288f046..230a8a6 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __NNCC_CORE_ADT_TENSOR_SHAPE_H__
 #define __NNCC_CORE_ADT_TENSOR_SHAPE_H__
 
+#include <initializer_list>
 #include <vector>
 #include <cstdint>
 
@@ -16,6 +17,10 @@ namespace tensor
 class Shape
 {
 public:
+  Shape() = default;
+  Shape(std::initializer_list<uint32_t> &&l);
+
+public:
   uint32_t rank(void) const;
 
 public:
index 38610a8..d48eca1 100644 (file)
@@ -9,6 +9,11 @@ namespace ADT
 namespace tensor
 {
 
+Shape::Shape(std::initializer_list<uint32_t> &&l) : _dims{l}
+{
+  // DO NOTHING
+}
+
 uint32_t Shape::rank(void) const { return _dims.size(); }
 Shape &Shape::resize(uint32_t size) { _dims.resize(size); }
 
index dfe204c..610c49b 100644 (file)
@@ -9,6 +9,18 @@ TEST(ADT_TENSOR_SHAPE, ctor)
   ASSERT_EQ(shape.rank(), 0);
 }
 
+TEST(ADT_TENSOR_SHAPE, ctor_initializer_list)
+{
+  nncc::core::ADT::tensor::Shape shape{1, 3, 5, 7};
+
+  ASSERT_EQ(shape.rank(), 4);
+
+  ASSERT_EQ(shape.dim(0), 1);
+  ASSERT_EQ(shape.dim(1), 3);
+  ASSERT_EQ(shape.dim(2), 5);
+  ASSERT_EQ(shape.dim(3), 7);
+}
+
 TEST(ADT_TENSOR_SHAPE, resize)
 {
   nncc::core::ADT::tensor::Shape shape;