MarisaKirisame commented on a change in pull request #6135:
URL: https://github.com/apache/incubator-tvm/pull/6135#discussion_r460211589



##########
File path: include/tvm/runtime/packed_func.h
##########
@@ -371,6 +371,20 @@ class TVMPODValue_ {
     TVM_CHECK_TYPE_CODE(type_code_, kDLFloat);
     return value_.v_float64;
   }
+  operator float() const {
+    double tmp_v = 0;
+    if (type_code_ == kDLInt) {
+      tmp_v = static_cast<double>(value_.v_int64);
+      CHECK_LE(tmp_v, std::numeric_limits<float>::max());
+      CHECK_GE(tmp_v, std::numeric_limits<float>::min());
+      return static_cast<float>(tmp_v);
+    }
+    TVM_CHECK_TYPE_CODE(type_code_, kDLFloat);
+    tmp_v = static_cast<double>(value_.v_float64);
+    CHECK_LE(tmp_v, std::numeric_limits<float>::max());
+    CHECK_GE(tmp_v, std::numeric_limits<float>::min());

Review comment:
       ```suggestion
       if (type_code_ == kDLInt) {
         tmp_v = static_cast<double>(value_.v_int64);
       } else {
         TVM_CHECK_TYPE_CODE(type_code_, kDLFloat);
         tmp_v = static_cast<double>(value_.v_float64);
       }
       CHECK_LE(tmp_v, std::numeric_limits<float>::max());
       CHECK_GE(tmp_v, std::numeric_limits<float>::min());
   ```

##########
File path: include/tvm/runtime/packed_func.h
##########
@@ -371,6 +371,20 @@ class TVMPODValue_ {
     TVM_CHECK_TYPE_CODE(type_code_, kDLFloat);
     return value_.v_float64;
   }
+  operator float() const {
+    double tmp_v = 0;
+    if (type_code_ == kDLInt) {
+      tmp_v = static_cast<double>(value_.v_int64);
+      CHECK_LE(tmp_v, std::numeric_limits<float>::max());
+      CHECK_GE(tmp_v, std::numeric_limits<float>::min());
+      return static_cast<float>(tmp_v);
+    }
+    TVM_CHECK_TYPE_CODE(type_code_, kDLFloat);
+    tmp_v = static_cast<double>(value_.v_float64);
+    CHECK_LE(tmp_v, std::numeric_limits<float>::max());
+    CHECK_GE(tmp_v, std::numeric_limits<float>::min());

Review comment:
       Just to be clear I mean like this. I think it is still semantically 
equivalent.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to