From: 채성우/On-Device Lab(SR)/Engineer/삼성전자 Date: Wed, 16 Oct 2019 10:40:57 +0000 (+0900) Subject: [angkor] Overload operator== (#8233) X-Git-Tag: submit/tizen/20191205.083104~750 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0db46902d66552c51f3ee5a8b0aedbe72edfd8a6;p=platform%2Fcore%2Fml%2Fnnfw.git [angkor] Overload operator== (#8233) * [angkor] Overload operator== This commit overloads operator== to index class. Signed-off-by: seongwoo * apply commnet. --- diff --git a/compiler/angkor/include/nncc/core/ADT/tensor/Index.h b/compiler/angkor/include/nncc/core/ADT/tensor/Index.h index 56d7391..19beafa 100644 --- a/compiler/angkor/include/nncc/core/ADT/tensor/Index.h +++ b/compiler/angkor/include/nncc/core/ADT/tensor/Index.h @@ -55,6 +55,7 @@ private: // It throws an exception when rank of inputs does not match. Index operator+(const Index &lhs, const Index &rhs); +bool operator==(const Index &lhs, const Index &rhs); } // namespace tensor } // namespace ADT diff --git a/compiler/angkor/src/ADT/tensor/Index.cpp b/compiler/angkor/src/ADT/tensor/Index.cpp index e61fafb..61f0a71 100644 --- a/compiler/angkor/src/ADT/tensor/Index.cpp +++ b/compiler/angkor/src/ADT/tensor/Index.cpp @@ -63,6 +63,18 @@ Index operator+(const Index &lhs, const Index &rhs) return ret; } +bool operator==(const Index &lhs, const Index &rhs) +{ + if (lhs.rank() != rhs.rank()) + return false; + for (uint32_t axis = 0; axis < lhs.rank(); axis++) + { + if (lhs.at(axis) != rhs.at(axis)) + return false; + } + return true; +} + } // namespace tensor } // namespace ADT } // namespace core diff --git a/compiler/angkor/src/ADT/tensor/Index.test.cpp b/compiler/angkor/src/ADT/tensor/Index.test.cpp index 412c85e..2306028 100644 --- a/compiler/angkor/src/ADT/tensor/Index.test.cpp +++ b/compiler/angkor/src/ADT/tensor/Index.test.cpp @@ -49,6 +49,18 @@ TEST(ADT_TENSOR_INDEX, operator_add) ASSERT_EQ(result.at(3), 12); } +TEST(ADT_TENSOR_INDEX, operator_eqaul) +{ + nncc::core::ADT::tensor::Index index1{1, 2, 3, 4}; + nncc::core::ADT::tensor::Index index2{1, 2, 3, 4}; + nncc::core::ADT::tensor::Index index3{5, 6, 7, 8}; + nncc::core::ADT::tensor::Index index4{1, 2}; + + ASSERT_TRUE(index1 == index2); + ASSERT_FALSE(index1 == index3); + ASSERT_FALSE(index1 == index4); +} + TEST(ADT_TENSOR_INDEX, operator_add_different_size) { nncc::core::ADT::tensor::Index index1{1, 2, 3, 4};