You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "as4230 (via GitHub)" <gi...@apache.org> on 2026/04/30 22:35:02 UTC

[PR] [Relax][Frontend][TFLite] Add ATAN2 op and TFLite mapping [tvm]

as4230 opened a new pull request, #19485:
URL: https://github.com/apache/tvm/pull/19485

   This PR adds the ATAN2 operator to the Relax TFLite frontend.
   
   Introduces relax.op.atan2 as a new binary elementwise primitive (TOPI broadcast op, Relax registration, legalization to topi.atan2, script parser support) and registers ATAN2 in the TFLite convert_map. It reuses the TIR primitive tvm::atan2 so this PR is the higher-layer plumbing.
   
   Validation:
       python -m pytest tests/python/relax/test_op_binary.py
       python -m pytest tests/python/relax/test_frontend_tflite.py -k binary
   
   Addresses the ATAN2 item under #19412.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add ATAN2 op and TFLite mapping [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19485:
URL: https://github.com/apache/tvm/pull/19485#discussion_r3171238981


##########
python/tvm/relax/op/binary.py:
##########
@@ -141,6 +141,24 @@ def power(x1: Expr, x2: Expr):
     return _ffi_api.power(x1, x2)  # type: ignore
 
 
+def atan2(x1: Expr, x2: Expr) -> Expr:
+    """Atan2 with numpy-style broadcasting.
+
+    Parameters
+    ----------
+    x1 : relax.Expr
+        The first input tensor.
+    x2 : relax.Expr
+        The second input tensor.

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The docstring for `atan2` could be more explicit about the meaning of `x1` and `x2` to align with the standard `atan2(y, x)` convention and prevent confusion. Following the style of numpy's documentation would be beneficial here.
   
   ```suggestion
       """Element-wise arc tangent of x1/x2 choosing the quadrant correctly.
       Follows numpy's `arctan2` convention.
   
       Parameters
       ----------
       x1 : relax.Expr
           The y-coordinates.
       x2 : relax.Expr
           The x-coordinates.
   ```



##########
include/tvm/topi/broadcast.h:
##########
@@ -384,6 +384,19 @@ TOPI_DEFINE_BCAST_OP(minimum, { return tvm::min(a, b); });
  */
 TOPI_DEFINE_BCAST_OP(power, { return tvm::pow(a, b); });
 
+/*!
+ * \fn atan2
+ * \brief Compute atan2(A, B) with auto-broadcasting.
+ *
+ * \param A The first tensor, or Expr
+ * \param B The second tensor, or Expr

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The standard convention for `atan2` is `atan2(y, x)`. The current documentation is a bit ambiguous. To improve clarity and prevent potential misuse, I suggest explicitly mentioning which parameter corresponds to the y-coordinates and which to the x-coordinates.
   
   ```suggestion
    * n atan2
    * rief Compute atan2(y, x) with auto-broadcasting.
    *
    * rief The y-coordinates. The first tensor, or Expr.
    * rief The x-coordinates. The second tensor, or Expr.
   ```



##########
python/tvm/topi/broadcast.py:
##########
@@ -249,6 +249,25 @@ def power(lhs, rhs):
     return _cpp.power(lhs, rhs)
 
 
+def atan2(lhs, rhs):
+    """Atan2 with auto-broadcasting.
+
+    Parameters
+    ----------
+    lhs : tvm.te.Tensor or Expr
+        The left operand
+    rhs : tvm.te.Tensor or Expr
+        The right operand

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   To improve clarity and prevent potential misuse of `atan2`, it's helpful to be explicit about which parameter corresponds to the y-coordinates and which to the x-coordinates, following the standard `atan2(y, x)` convention.
   
   ```suggestion
       """Element-wise arc tangent of lhs/rhs choosing the quadrant correctly.
   
       Parameters
       ----------
       lhs : tvm.te.Tensor or Expr
           The y-coordinates.
       rhs : tvm.te.Tensor or Expr
           The x-coordinates.
   ```



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add ATAN2 op and TFLite mapping [tvm]

Posted by "as4230 (via GitHub)" <gi...@apache.org>.
as4230 commented on PR #19485:
URL: https://github.com/apache/tvm/pull/19485#issuecomment-4357513257

   > Overalll LGTM! Please add legalize tests for atan2 in `tests/python/relax/test_transform_legalize_ops_binary.py` as well
   
   Done. I added test_atan2, test_atan2_symbolic, and test_atan2_primvalue in test_transform_legalize_ops_binary.py. 


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add ATAN2 op and TFLite mapping [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19485:
URL: https://github.com/apache/tvm/pull/19485


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org