Skip to content
class

ReciprocalBackward

ReciprocalBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise reciprocal y=1/xy = 1/x.

Saves the input x so the backward pass can form x2x^2 in the denominator without recomputing the forward result. The forward and backward are both undefined at x=0x = 0 and the caller is responsible for avoiding that domain point.

Math

\frac{\partial y}{\partial x} = -\frac{1}{x^2}, \qquad \frac{\partial \mathcal{L}}{\partial x} = -\frac{1}{x^2}\,\frac{\partial \mathcal{L}}{\partial y}.$$

Attributes

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

Notes

Dispatch: a correctly rounded 1 / x on CPU (vvrec for F64, a plain loop for F32 because vvrecf is not exact — backend/cpu/Vforce.cpp) / MLX element-wise reciprocal (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::reciprocal to compute y=1/xy = 1/x.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=−1/x2\partial y/\partial x = -1/x^2, scaled by grad_out.

fn

grad_formula_impl

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

Graph-mode backward: ∂x=−g/x2\partial x = -g / x^2 kept inside the autograd graph.