From db5ce998354716cf5b2d1cfeba25277642118087 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Senior=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 9 May 2018 14:40:36 +0900 Subject: [PATCH] [core] Add 'fill' method to ADT::tensor::Index (#198) This commit adds 'fill' method (to ADT::tensor::Index class) which sets all the indices as the given value. Signed-off-by: Jonghyun Park --- libs/core/include/nncc/core/ADT/tensor/Index.h | 3 +++ libs/core/src/nncc/core/ADT/tensor/Index.cpp | 8 ++++++++ libs/core/src/nncc/core/ADT/tensor/Index.test.cpp | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/libs/core/include/nncc/core/ADT/tensor/Index.h b/libs/core/include/nncc/core/ADT/tensor/Index.h index ed68720..75b354b 100644 --- a/libs/core/include/nncc/core/ADT/tensor/Index.h +++ b/libs/core/include/nncc/core/ADT/tensor/Index.h @@ -27,6 +27,9 @@ public: Index &resize(uint32_t size); public: + Index &fill(uint32_t index); + +public: uint32_t &at(uint32_t axis); uint32_t at(uint32_t axis) const; diff --git a/libs/core/src/nncc/core/ADT/tensor/Index.cpp b/libs/core/src/nncc/core/ADT/tensor/Index.cpp index c2acde7..4433f1c 100644 --- a/libs/core/src/nncc/core/ADT/tensor/Index.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/Index.cpp @@ -1,5 +1,7 @@ #include "nncc/core/ADT/tensor/Index.h" +#include + namespace nncc { namespace core @@ -17,6 +19,12 @@ Index::Index(std::initializer_list &&l) : _indices{l} uint32_t Index::rank(void) const { return _indices.size(); } Index &Index::resize(uint32_t size) { _indices.resize(size); } +Index &Index::fill(uint32_t index) +{ + std::fill(_indices.begin(), _indices.end(), index); + return (*this); +} + uint32_t &Index::at(uint32_t axis) { return _indices.at(axis); } uint32_t Index::at(uint32_t axis) const { return _indices.at(axis); } diff --git a/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp b/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp index d50def0..aec0791 100644 --- a/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp +++ b/libs/core/src/nncc/core/ADT/tensor/Index.test.cpp @@ -57,3 +57,15 @@ TEST(ADT_TENSOR_INDEX, copy) ASSERT_EQ(original.at(axis), copied.at(axis)); } } + +TEST(ADT_TENSOR_INDEX, fill) +{ + nncc::core::ADT::tensor::Index index{1, 6}; + + index.fill(3); + + ASSERT_EQ(index.rank(), 2); + + ASSERT_EQ(index.at(0), 3); + ASSERT_EQ(index.at(1), 3); +} -- 2.7.4