lucid.tan

lucid.tan(a: Tensor, /) Tensor

The tan function computes the element-wise tangent of each element in the input tensor.

Function Signature

def tan(a: Tensor) -> Tensor

Parameters

  • a (Tensor): The input tensor for which the tangent is computed.

Returns

  • Tensor:

    A new tensor containing the element-wise tangent of the input tensor. If a requires gradients, the resulting tensor will also require gradients.

Forward Calculation

\[\mathbf{out}_i = \tan(\mathbf{a}_i)\]

Backward Gradient Calculation

\[\frac{\partial \mathbf{out}_i}{\partial \mathbf{a}_i} = 1 + \tan^2(\mathbf{a}_i)\]

Example

>>> import lucid
>>> a = Tensor([0, math.pi / 4, math.pi / 2], requires_grad=True)
>>> out = lucid.tan(a)
>>> print(out)
Tensor([0. 1. inf], grad=None)