This commit adds 'asConv2D' method to Op class, which allows users to
safely downcast 'Op' as 'Conv2D'.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
namespace coco
{
+class Conv2D;
+
/***
* @brief Base interface on all supported NN operations
*/
struct Op
{
virtual ~Op() = default;
+
+ virtual Conv2D *asConv2D(void) { return nullptr; }
+ virtual const Conv2D *asConv2D(void) const { return nullptr; }
};
} // namespace coco
public:
explicit Conv2D(const Param &);
+public:
+ Conv2D *asConv2D(void) override { return this; }
+ const Conv2D *asConv2D(void) const override { return this; }
+
private:
KernelObject *_ker;
ASSERT_EQ(op.ker(), nullptr);
}
+TEST(IR_OP_CONV2D, asConv2D)
+{
+ coco::Conv2D op{coco::Conv2D::Param{}};
+
+ coco::Op *mutable_base = &op;
+ const coco::Op *immutable_base = &op;
+
+ ASSERT_EQ(mutable_base->asConv2D(), &op);
+ ASSERT_EQ(mutable_base->asConv2D(), immutable_base->asConv2D());
+}
+
TEST(IR_OP_CONV2D, ker_update)
{
const coco::Conv2D::Param param{};