zhiics commented on a change in pull request #5345:
URL: https://github.com/apache/incubator-tvm/pull/5345#discussion_r414572622



##########
File path: python/tvm/relay/frontend/tflite.py
##########
@@ -2219,6 +2218,20 @@ def get_expr(self, input_tensor_idx):
     def has_expr(self, input_tensor_idx):
         return self.exp_tab.has_expr(get_tensor_name(self.subgraph, 
input_tensor_idx))
 
+
+def get_scalar_from_constant(expr):
+    """ Returns scalar value from Relay constant scalar. """
+    assert isinstance(expr, _expr.Constant) and not expr.data.shape, \
+        "Expr is not a constant scalar."
+    value = expr.data.asnumpy()
+    if value.dtype == np.dtype(np.int32):
+        return int(value)
+    if value.dtype == np.dtype(np.float32):
+        return float(value)
+    assert False, "Constant expr must be float32/int32"
+    return None  # To suppress pylint

Review comment:
       I am okay with this type of minimal code duplication. 
   
   Can we just do for both case?
   
   ```python
   assert value.dtype == np.dtype(np.int32) or value.dtype == 
np.dtype(np.float32), "value must be float32/int32"
   return np. asscalar(value)
   ```




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to