megengine.functional.atan2¶
- atan2(y, x)[source]¶
Element-wise \(\arctan(\frac{y}{x})\) function.
Calculates an approximation to the inverse tangent for each element \(x_i\) of the input tensor \(x\) with the respective element \(y_i\) of the input tensor \(y\).
- Parameters
y – first input tensor whose elements correspond to the dividend. Should have a numeric data type.
x – second input tensor whose elements correspond to the divisor. Must be compatible with x (see Broadcasting mechanism and rules ). Should have a numeric data type.
- Returns
a tensor containing the inverse tangent of each element in \(y/x\).
Special cases
atan2
is identical to theatan2
function of the underlying C library. The following special values are defined in the C standard:For floating-point operands,
if \(y\) is +/-0` and \(x\) is
+0
, the result is+/-0
.if \(y\) is
+/-0
and \(x\) is-0
, the result is+/-π
.if \(y\) is greater than
0
and \(x\) is+/-infinity
, the result is+0/+π
.if \(y\) is less than
0
and \(x\) is+/-infinity
, the result is-0/-π
.if \(y\) is
+/-infinity`and :math:`x` is ``+infinity
, tge result is+/-(π/4)
.if \(y\) is
+/-infinity`and :math:`x` is ``-infinity
, tge result is+/-(3π/4)
.
Note that
+0
and-0
are distinct floating point numbers, as are+inf
and-inf
.Examples
>>> F.atan2(0, 1) # equals to atan(0) Tensor(0.0, device=xpux:0)
Element-wise inverse tangent:
>>> y = Tensor([0, 1, -1]) >>> x = Tensor([1, 1, 1]) >>> F.atan2(y, x) Tensor([ 0. 0.7854 -0.7854], device=xpux:0)