Skip to content
class

TanBackward

TanBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for element-wise tangent y=tan⁡(x)y = \tan(x).

Saves the input x so the backward pass can build cos⁡2(x)\cos^2(x) in the denominator. Defined for all real xx except the singular points x=(k+12)πx = (k + \tfrac{1}{2})\pi where cos⁡x=0\cos x = 0; behaviour at those points is undefined.

Math

\frac{\partial y}{\partial x} = \sec^2(x) = \frac{1}{\cos^2(x)}, \qquad \frac{\partial \mathcal{L}}{\partial x} = \frac{1}{\cos^2(x)}\,\frac{\partial \mathcal{L}}{\partial y}.$$

Attributes

schema_v1OpSchema
Registered as "tan" with AmpPolicy::Promote.

Notes

Dispatch: Accelerate vvtanf/vvtan (CPU) / MLX tan (GPU).

Static methods

1
static

dispatch

int dispatch(backend::IBackend & be, const int & a, const int & s, Dtype dt)

Forward — calls IBackend::tan to compute y=tan⁡xy = \tan x.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=sec⁡2x\partial y/\partial x = \sec^2 x, scaled by grad_out.

fn

grad_formula_impl

int grad_formula_impl(const int & g, const int & x, const int &)

Graph-mode backward: the same derivative built from composable ops, so the gradient itself stays differentiable.