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


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2287,17 +2292,45 @@ def _impl_v18(cls, bb, inputs, attr, params):
             else:
                 assert f"Type {type(size)} for size is currently unsupported."
 
-        return relax.op.image.resize2d(
+        if ndims == 3:
+            return bb.emit_te(
+                topi.image.resize1d,
+                x,
+                roi,
+                sizes,
+                "NCW",
+                topi_mode,
+                coord_mode,
+                rounding_method,
+                cubic_coeff_a,
+                exclude_outside,
+                extrapolation_value,
+            )
+        if ndims == 4:
+            return relax.op.image.resize2d(
+                x,
+                size=relax.ShapeExpr(sizes),
+                roi=roi,
+                layout="NCHW",
+                method=relax_mode,
+                coordinate_transformation_mode=coord_mode,
+                rounding_method=rounding_method,
+                cubic_alpha=cubic_coeff_a,
+                cubic_exclude=exclude_outside,
+                extrapolation_value=extrapolation_value,
+            )
+        return bb.emit_te(
+            topi.image.resize3d,
             x,
-            size=relax.ShapeExpr(sizes),
-            roi=roi,
-            layout="NCHW",
-            method=mode,
-            coordinate_transformation_mode=coord_mode,
-            rounding_method=rounding_method,
-            cubic_alpha=cubic_coeff_a,
-            cubic_exclude=exclude_outside,
-            extrapolation_value=extrapolation_value,
+            roi,
+            sizes,
+            "NCDHW",
+            topi_mode,
+            coord_mode,
+            rounding_method,
+            cubic_coeff_a,
+            exclude_outside,
+            extrapolation_value,
         )

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For better readability and to make the logic more explicit, consider using 
an `if/elif/else` structure to handle the different `ndims` cases. This also 
makes the code more robust in case the assertion on `ndims` is changed in the 
future.
   
   ```python
           if ndims == 3:
               return bb.emit_te(
                   topi.image.resize1d,
                   x,
                   roi,
                   sizes,
                   "NCW",
                   topi_mode,
                   coord_mode,
                   rounding_method,
                   cubic_coeff_a,
                   exclude_outside,
                   extrapolation_value,
               )
           elif ndims == 4:
               return relax.op.image.resize2d(
                   x,
                   size=relax.ShapeExpr(sizes),
                   roi=roi,
                   layout="NCHW",
                   method=relax_mode,
                   coordinate_transformation_mode=coord_mode,
                   rounding_method=rounding_method,
                   cubic_alpha=cubic_coeff_a,
                   cubic_exclude=exclude_outside,
                   extrapolation_value=extrapolation_value,
               )
           else:  # ndims == 5
               return bb.emit_te(
                   topi.image.resize3d,
                   x,
                   roi,
                   sizes,
                   "NCDHW",
                   topi_mode,
                   coord_mode,
                   rounding_method,
                   cubic_coeff_a,
                   exclude_outside,
                   extrapolation_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.

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