mygrad.arctan2#

class mygrad.arctan2(x1: ArrayLike, x2: ArrayLike, out: Tensor | ndarray | None = None, *, where: Mask = True, dtype: DTypeLikeReals = None, constant: bool | None = None)#

Element-wise arc tangent of x1/x2 choosing the quadrant correctly.

This docstring was adapted from that of numpy.arctan [1]

Parameters:
x1ArrayLike

y-coordinates.

x2ArrayLike

x-coordinates.

outOptional[Union[Tensor, ndarray]]

A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated tensor is returned.

constantOptional[bool]

If True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e. constant.grad will always return None).

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

whereMask

This condition is broadcast over the input. At locations where the condition is True, the out tensor will be set to the ufunc result. Elsewhere, the out tensor will retain its original value. Note that if an uninitialized out tensor is created via the default out=None, locations within it where the condition is False will remain uninitialized.

dtypeOptional[DTypeLikeReals]

The dtype of the resulting tensor.

Returns:
angleTensor

Tensor of angles in radians, in the range [-pi, pi].

See also

arctan, tan

Notes

arctan2 is identical to the atan2 function of the underlying C library. The following special values are defined in the C standard: [2]

x1

x2

arctan2(x1,x2)

+/- 0

+0

+/- 0

+/- 0

-0

+/- pi

> 0

+/-inf

+0 / +pi

< 0

+/-inf

-0 / -pi

+/-inf

+inf

+/- (pi/4)

+/-inf

-inf

+/- (3*pi/4)

Note that +0 and -0 are distinct floating point numbers, as are +inf and -inf.

References

[2]

ISO/IEC standard 9899:1999, “Programming language C.”

Examples

Consider four points in different quadrants:

>>> import mygrad as mg
>>> x = mg.tensor([-1.0, +1.0, +1.0, -1.0])
>>> y = mg.tensor([-1.0, -1.0, +1.0, +1.0])
>>> mg.arctan2(y, x) * 180 / mg.pi
Tensor([-135.,  -45.,   45.,  135.])

Note the order of the parameters. arctan2 is defined also when x2 = 0 and at several other special points, obtaining values in the range [-pi, pi]:

>>> mg.arctan2([1., -1.], [0., 0.])
Tenor([ 1.57079633, -1.57079633])
>>> mg.arctan2([0., 0., mg.inf], [+0., -0., mg.inf])
Tenor([ 0.        ,  3.14159265,  0.78539816])
Attributes:
identity
signature

Methods

accumulate([axis, dtype, out, constant])

Not implemented

at(indices[, b, constant])

Not implemented

outer(b, *[, dtype, out])

Not Implemented

reduce([axis, dtype, out, keepdims, ...])

Not Implemented

reduceat(indices[, axis, dtype, out])

Not Implemented

resolve_dtypes(dtypes, *[, signature, ...])

Find the dtypes NumPy will use for the operation.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

accumulate([axis, dtype, out, constant])

Not implemented

at(indices[, b, constant])

Not implemented

outer(b, *[, dtype, out])

Not Implemented

reduce([axis, dtype, out, keepdims, ...])

Not Implemented

reduceat(indices[, axis, dtype, out])

Not Implemented

resolve_dtypes(dtypes, *[, signature, ...])

Find the dtypes NumPy will use for the operation.

Attributes

identity

nargs

nin

nout

ntypes

signature

types