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

Function cos

imperative/python/megengine/functional/elemwise.py:1088–1114  ·  view source on GitHub ↗

r"""Element-wise :math:`\cos(x)` function. Calculates an approximation to the cosine for each element :math:`x_i` of the input tensor :math:`x`. Each element :math:`x_i` is assumed to be expressed in radians. This function has domain ``(-infinity, +infinity)`` and codomain ``[-1, +

(x)

Source from the content-addressed store, hash-verified

1086
1087
1088def cos(x):
1089 r"""Element-wise :math:`\cos(x)` function.
1090
1091 Calculates an approximation to the cosine for each element :math:`x_i` of the input tensor :math:`x`.
1092 Each element :math:`x_i` is assumed to be expressed in radians.
1093
1094 This function has domain ``(-infinity, +infinity)`` and codomain ``[-1, +1]``.
1095
1096 Args:
1097 x: input tensor whose elements are each expressed in radians. Should have a floating-point data type.
1098
1099 Returns:
1100 a tensor containing the cosine of each element in :math:`x`.
1101 The returned tensor must have a floating-point data type determined by :ref:`dtype-promotion`.
1102
1103 Examples:
1104 >>> F.cos(0)
1105 Tensor(1.0, device=xpux:0)
1106
1107 Element-wise cosine:
1108
1109 >>> import math
1110 >>> x = Tensor([0, math.pi/2, math.pi])
1111 >>> F.cos(x)
1112 Tensor([ 1. -0. -1.], device=xpux:0)
1113 """
1114 return _elwise(x, mode=Elemwise.Mode.COS)
1115
1116
1117def sin(x):

Callers 4

rotateFunction · 0.70
polarFunction · 0.70
test_gradFunction · 0.50
test_2nd_gradFunction · 0.50

Calls 1

_elwiseFunction · 0.50

Tested by 2

test_gradFunction · 0.40
test_2nd_gradFunction · 0.40