MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / polar

Function polar

imperative/python/megengine/functional/tensor.py:428–446  ·  view source on GitHub ↗

r"""Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value abs and angle angle. Args: abs(Tensor): the absolute value the complex tensor. Must be float. angle(Tensor): the angle of the complex tensor. M

(abs: Tensor, angle: Tensor)

Source from the content-addressed store, hash-verified

426
427
428def polar(abs: Tensor, angle: Tensor) -> Tensor:
429 r"""Constructs a complex tensor whose elements are Cartesian coordinates
430 corresponding to the polar coordinates with absolute value abs and angle angle.
431
432 Args:
433 abs(Tensor): the absolute value the complex tensor. Must be float.
434 angle(Tensor): the angle of the complex tensor. Must be float.
435
436 Returns:
437 the complex tensor
438
439 Examples:
440 >>> abs = Tensor([1, 2], dtype=np.float32)
441 >>> angle = Tensor([np.pi / 2, 5 * np.pi / 4], dtype=np.float32)
442 >>> z = F.polar(abs, angle)
443 >>> z
444 Tensor([-4.3711e-08+1.j -1.4142e+00-1.4142j], dtype=complex64, device=xpux:0)
445 """
446 return create_complex(abs * cos(angle), abs * sin(angle))
447
448
449def complex(real: Tensor, imag: Tensor) -> Tensor:

Callers

nothing calls this directly

Calls 2

cosFunction · 0.70
sinFunction · 0.70

Tested by

no test coverage detected