Skip to content

Commit 4b9c442

Browse files
_aten_to_core: expand replace_atan2 docstring
1 parent a79f21e commit 4b9c442

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

coreai_torch/_aten_to_core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,15 @@ def replace_argmax(values_map: dict[str, Value], node: fx.Node, loc: Location) -
15231523

15241524

15251525
def replace_atan2(values_map: dict[str, Value], node: fx.Node, loc: Location) -> Value:
1526-
"""atan2(y, x) via atan(y/x) with quadrant correction.
1526+
"""Lower atan2(y, x) using atan(y/x) with quadrant correction.
15271527
1528-
atan2 is undefined for (y=0, x=0); follows the convention atan2(0, 0) = 0.
1528+
CoreAI has no native atan2, so it is decomposed as:
1529+
- x != 0: atan(y/x) adjusted by ±π to place the result in the correct quadrant.
1530+
- x == 0: ±π/2 or 0 based on sign of y.
1531+
1532+
When x=0, x is replaced with 1 before the divide solely to avoid NaN/inf; that
1533+
intermediate result is discarded by the final where-select in favour of the x=0 branch.
1534+
atan2(0, 0) = 0 by convention.
15291535
"""
15301536
y, x = _get_operands(values_map, node, [0, 1])
15311537
ele_type = x.type.element_type

0 commit comments

Comments
 (0)