[enco] Throw an exception on unknown operand type (#1606)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 20 Sep 2018 23:51:50 +0000 (08:51 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 20 Sep 2018 23:51:50 +0000 (08:51 +0900)
The current implementation assumes that operand is either scalar or
tensor and validates it through assert.

This commit explicitly validates dynamic casted pointer, which allows us
to detect such an abnormal case even for release build.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/CppGen/Subnet.cpp

index 95213f3..121e4c0 100644 (file)
@@ -328,12 +328,14 @@ std::unique_ptr<SubnetStruct> SubnetStructBuilder::build(const ANNBinder *binder
     {
       res->ctor() << ScalarOperandDecl{mname, scalar->dtype()};
     }
-    else
+    else if (auto tensor = dynamic_cast<const ann::TensorOperand *>(info))
     {
-      auto tensor = dynamic_cast<const ann::TensorOperand *>(info);
-      assert(tensor != nullptr);
       res->ctor() << TensorOperandDecl{mname, tensor->dtype(), tensor->shape()};
     }
+    else
+    {
+      throw std::runtime_error{"Unsupported"};
+    }
 
     if (info->weight())
     {