Skip to content
class

RPowScalarBackward

RPowScalarBackward

Autograd node for scalar-base reverse power: y=basexy = \text{base}^{x}.

The base is captured on the node; the output tensor (and the input when base == 0) is saved because the gradient formula uses yy directly and masks x≥0x \geq 0 when base=0\text{base} = 0.

Math

Forward

yi=basexiy_i = \text{base}^{x_i}

Backward

\frac{\partial L}{\partial y_i}$$ **See Also** `PowScalarBackward`, `rpow_scalar_op`.

Attributes

base_double
Scalar base captured at forward; std::log(base_) is computed inside grad_formula.
kSavesInputbool
false by default (input saved only when base_ == 0).
kSavesOutputbool
true — the forward output y=basexy = \text{base}^{x} is saved.
schema_v1OpSchema
Op name "rpow_scalar" with AmpPolicy::ForceFP32.

Notes

Undefined for base <= 0 (ln would not be real). Use pow_scalar_op if the exponent — not the base — is the scalar.

Static methods

1
static

forward

→TensorImplPtr
int forward(double base, const int & a)

Forward dispatch with base capture — computes y=basexy = \text{base}^{x}, saves the output on the backward node, and wires autograd manually (save_input=false).

Parameters

basedouble
Scalar base (must be positive for a real-valued gradient).
aconst TensorImplPtr&
Input tensor — the exponent.

Returns

TensorImplPtr

Output tensor with the same shape and (post-promotion) dtype as a; the backward node carries base and the saved output.

Methods

2
fn

grad_formula

→Storage
int grad_formula(const int & g)

Computes ∂L/∂x=ln⁡(base)⋅y⋅g\partial L/\partial x = \ln(\text{base}) \cdot y \cdot g from the saved output and the captured base_.

Parameters

gconst Storage&
Upstream gradient ∂L/∂y\partial L/\partial y.

Returns

Storage

Gradient with respect to x.

fn

grad_formula_impl

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

Graph-mode backward: ln⁡(base)⋅y⋅g\ln(\text{base}) \cdot y \cdot g from the tracked output, so the second derivative sees yy's dependence on xx.