From ab386f0df1546eb20bde215c3bbee09c02f264d5 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: Tue, 21 Aug 2018 08:33:19 +0900 Subject: [PATCH] [nncc.core.ADT] Overload == over kernel shape (#1053) This commit introduces '==' operator overloading for kernel shape instances. Signed-off-by: Jonghyun Park --- libs/core/include/nncc/core/ADT/kernel/Shape.h | 2 ++ libs/core/src/ADT/kernel/Shape.cpp | 21 +++++++++++++++++++++ libs/core/src/ADT/kernel/Shape.test.cpp | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 libs/core/src/ADT/kernel/Shape.cpp diff --git a/libs/core/include/nncc/core/ADT/kernel/Shape.h b/libs/core/include/nncc/core/ADT/kernel/Shape.h index 18d3dcb..f00ad4e 100644 --- a/libs/core/include/nncc/core/ADT/kernel/Shape.h +++ b/libs/core/include/nncc/core/ADT/kernel/Shape.h @@ -42,6 +42,8 @@ inline uint64_t num_elements(const Shape &shape) return shape.count() * shape.depth() * shape.height() * shape.width(); } +bool operator==(const Shape &lhs, const Shape &rhs); + } // namespace kernel } // namespace ADT } // namespace core diff --git a/libs/core/src/ADT/kernel/Shape.cpp b/libs/core/src/ADT/kernel/Shape.cpp new file mode 100644 index 0000000..169c49f --- /dev/null +++ b/libs/core/src/ADT/kernel/Shape.cpp @@ -0,0 +1,21 @@ +#include "nncc/core/ADT/kernel/Shape.h" + +namespace nncc +{ +namespace core +{ +namespace ADT +{ +namespace kernel +{ + +bool operator==(const Shape &l, const Shape &r) +{ + return (l.count() == r.count()) && (l.depth() == r.depth()) && (l.height() == r.height()) && + (l.width() == r.width()); +} + +} // namespace kernel +} // namespace ADT +} // namespace core +} // namespace nncc diff --git a/libs/core/src/ADT/kernel/Shape.test.cpp b/libs/core/src/ADT/kernel/Shape.test.cpp index 59cf69f..51b862d 100644 --- a/libs/core/src/ADT/kernel/Shape.test.cpp +++ b/libs/core/src/ADT/kernel/Shape.test.cpp @@ -29,3 +29,14 @@ TEST(ADT_KERNEL_SHAPE, num_elements) ASSERT_EQ(num_elements(Shape{N, C, H, W}), N * C * H * W); } + +TEST(ADT_KERNEL_SHAPE, operator_eq) +{ + using nncc::core::ADT::kernel::Shape; + + EXPECT_TRUE(Shape(1, 1, 1, 1) == Shape(1, 1, 1, 1)); + EXPECT_FALSE(Shape(1, 1, 1, 1) == Shape(1, 1, 1, 2)); + EXPECT_FALSE(Shape(1, 1, 1, 1) == Shape(1, 1, 2, 1)); + EXPECT_FALSE(Shape(1, 1, 1, 1) == Shape(1, 2, 1, 1)); + EXPECT_FALSE(Shape(1, 1, 1, 1) == Shape(2, 1, 1, 1)); +} -- 2.7.4