gemini-code-assist[bot] commented on code in PR #19626:
URL: https://github.com/apache/tvm/pull/19626#discussion_r3312057314


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -1104,6 +1104,20 @@ def _impl_v13(cls, bb, inputs, attr, params):
             return relax.const(output, to_type)
         if isinstance(inputs[0], relax.PrimValue):
             return relax.PrimValue(inputs[0].value.astype(to_type))
+
+        try:
+            np_dst = _np.dtype(str(to_type))
+        except Exception:
+            return relax.op.astype(inputs[0], to_type)
+
+        if np_dst.kind in ("i", "u"):
+            src = inputs[0]
+            src_dtype = getattr(getattr(src, "struct_info", None), "dtype", 
None) or getattr(src, "dtype", None)
+            if src_dtype is not None and 
_relax_dtype_is_floating_point(src_dtype):
+                bad = relax.op.logical_or(relax.op.isnan(src), 
relax.op.isinf(src))

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify the check for non-finite values (NaN and Inf) by using 
`relax.op.logical_not(relax.op.isfinite(src))`. This avoids one extra operator 
call (`logical_or` of `isnan` and `isinf`) and simplifies the generated Relax 
graph.
   
   ```suggestion
                   bad = relax.op.logical_not(relax.op.isfinite(src))
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to