Skip to content
class

CosBackward

CosBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for element-wise cosine y=cos⁡(x)y = \cos(x).

Saves the input x so the backward pass can compute −sin⁡(x)-\sin(x) and scale the upstream gradient by it. The input is interpreted in radians.

Math

\frac{\partial y}{\partial x} = -\sin(x), \qquad \frac{\partial \mathcal{L}}{\partial x} = -\sin(x)\,\frac{\partial \mathcal{L}}{\partial y}.$$

Attributes

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

Notes

Dispatch: Accelerate vvcosf/vvcos (CPU) / MLX cos (GPU).

Static methods

1
static

dispatch

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

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

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=−sin⁡x\partial y/\partial x = -\sin 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.