From 97216bd5718b0307903eef1f033548da984c9786 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/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 27 Jun 2018 11:43:46 +0900 Subject: [PATCH] [core.ADT] Simplify tensor view construction (#383) The current implementation of tensor::View takes an owned pointer of Layout (std::unique_ptr) as its argument. This design was enforced by the constraint that Layout is a pure virtual class. Recently, this constraint is gone. Layout class is now a simple class which is copyable and movable. This commit revises tensor view constructor to take Layout instead of std::unique_ptr to make it easy to build tensor view. Signed-off-by: Jonghyun Park --- libs/core/include/nncc/core/ADT/tensor/View.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libs/core/include/nncc/core/ADT/tensor/View.h b/libs/core/include/nncc/core/ADT/tensor/View.h index 96ef5ab..c4a1458 100644 --- a/libs/core/include/nncc/core/ADT/tensor/View.h +++ b/libs/core/include/nncc/core/ADT/tensor/View.h @@ -23,7 +23,7 @@ namespace tensor template class View final : public Reader, public Accessor { public: - explicit View(const Shape &shape, std::unique_ptr &&layout, + explicit View(const Shape &shape, const Layout &layout, std::unique_ptr> &®ion) : _shape{shape}, _layout{std::move(layout)}, _region{std::move(region)} { @@ -33,18 +33,18 @@ public: public: T at(const Index &index) const override { - return *(_region->base() + _layout->offset(_shape, index)); + return *(_region->base() + _layout.offset(_shape, index)); } public: - T &at(const Index &index) override { return *(_region->base() + _layout->offset(_shape, index)); } + T &at(const Index &index) override { return *(_region->base() + _layout.offset(_shape, index)); } public: const Shape &shape(void) const { return _shape; } private: const Shape _shape; - std::unique_ptr _layout; + const Layout _layout; private: std::unique_ptr> _region; @@ -53,8 +53,7 @@ private: template View make_view(const Shape &shape, std::unique_ptr> &®ion) { - std::unique_ptr layout(new LayoutImpl{}); - return View{shape, std::move(layout), std::move(region)}; + return View{shape, LayoutImpl{}, std::move(region)}; } } // namespace tensor -- 2.7.4