From 64ada060127558e4a8f39f63b083945fb4b0d69f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 10 Jan 2019 09:28:07 +0900 Subject: [PATCH] [neurun] Remove `Index::asInt` (#4189) Remove `asInt` method from `Index` since it should return its underlying type. Calls to `asInt()` has been replaced with `value()`. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/Index.h | 1 - runtimes/neurun/src/model/operand/IndexSet.h | 2 +- runtimes/neurun/test/graph/operation/SetIO.cc | 22 +++++++++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/runtimes/neurun/src/graph/Index.h b/runtimes/neurun/src/graph/Index.h index 3263d12..517ab81 100644 --- a/runtimes/neurun/src/graph/Index.h +++ b/runtimes/neurun/src/graph/Index.h @@ -55,7 +55,6 @@ public: bool operator!=(const Index &o) const { return !(*this == o); } T value() const { return _index; } - int32_t asInt() const { return static_cast(_index); } // For legacy code compatibility private: T _index; diff --git a/runtimes/neurun/src/model/operand/IndexSet.h b/runtimes/neurun/src/model/operand/IndexSet.h index e8827de..bb679b7 100644 --- a/runtimes/neurun/src/model/operand/IndexSet.h +++ b/runtimes/neurun/src/model/operand/IndexSet.h @@ -42,7 +42,7 @@ public: public: uint32_t size() const { return static_cast(_set.size()); } - const Index &at(IO::Index set_index) const { return _set.at(set_index.asInt()); } + const Index &at(IO::Index set_index) const { return _set.at(set_index.value()); } const Index &at(uint32_t index) const { return _set.at(index); } bool contains(const Index &index) const; void replace(const Index &from, const Index &to); diff --git a/runtimes/neurun/test/graph/operation/SetIO.cc b/runtimes/neurun/test/graph/operation/SetIO.cc index a475bdc..4953745 100644 --- a/runtimes/neurun/test/graph/operation/SetIO.cc +++ b/runtimes/neurun/test/graph/operation/SetIO.cc @@ -41,18 +41,18 @@ TEST(graph_operation_setIO, operation_setIO_conv) std::vector params; for (int i = 0; i < 7; ++i) { - params.emplace_back(graph.addOperand(shape, type).asInt()); + params.emplace_back(graph.addOperand(shape, type).value()); } - uint32_t outoperand = graph.addOperand(shape, type).asInt(); + uint32_t outoperand = graph.addOperand(shape, type).value(); using GraphNode = neurun::model::operation::Conv2DNode; auto conv = nnfw::cpp14::make_unique(GraphNodeInitParam{7, params.data(), 1, &outoperand}); - ASSERT_EQ(conv->getInputs().at(Index{0}).asInt(), params[0]); + ASSERT_EQ(conv->getInputs().at(Index{0}).value(), params[0]); conv->setInputs({8, 9, 10}); - ASSERT_NE(conv->getInputs().at(Index{0}).asInt(), params[0]); - ASSERT_EQ(conv->getInputs().at(Index{0}).asInt(), 8); + ASSERT_NE(conv->getInputs().at(Index{0}).value(), params[0]); + ASSERT_EQ(conv->getInputs().at(Index{0}).value(), 8); } TEST(graph_operation_setIO, operation_setIO_concat) @@ -67,9 +67,9 @@ TEST(graph_operation_setIO, operation_setIO_concat) std::vector params; for (int i = 0; i < 7; ++i) { - params.emplace_back(graph.addOperand(shape, type).asInt()); + params.emplace_back(graph.addOperand(shape, type).value()); } - uint32_t outoperand = graph.addOperand(shape, type).asInt(); + uint32_t outoperand = graph.addOperand(shape, type).value(); using GraphNode = neurun::model::operation::ConcatNode; @@ -77,12 +77,12 @@ TEST(graph_operation_setIO, operation_setIO_concat) nnfw::cpp14::make_unique(GraphNodeInitParam{7, params.data(), 1, &outoperand}); ASSERT_EQ(concat->getInputs().size(), 6); - ASSERT_EQ(concat->getInputs().at(Index{0}).asInt(), params[0]); + ASSERT_EQ(concat->getInputs().at(Index{0}).value(), params[0]); concat->setInputs({80, 6, 9, 11}); ASSERT_EQ(concat->getInputs().size(), 4); - ASSERT_NE(concat->getInputs().at(Index{0}).asInt(), params[0]); - ASSERT_EQ(concat->getInputs().at(Index{0}).asInt(), 80); - ASSERT_EQ(concat->getInputs().at(Index{2}).asInt(), 9); + ASSERT_NE(concat->getInputs().at(Index{0}).value(), params[0]); + ASSERT_EQ(concat->getInputs().at(Index{0}).value(), 80); + ASSERT_EQ(concat->getInputs().at(Index{2}).value(), 9); ASSERT_THROW(concat->getInputs().at(Index{5}), std::out_of_range); } -- 2.7.4