def backward_impl(self, inputs, outputs, prop_down, accum): # inputs: [inputs_fwd_graph] + [inputs_bwd_graph] or # [inputs_fwd_graph] + [outputs_fwd_graph] + [inputs_bwd_graph] # Inputs x0 = inputs[0].data dy = inputs[1].data # Outputs dx0 = outputs[0].data # Grads of inputs g_x0 = inputs[0].grad g_dy = inputs[1].grad # Grads of outputs g_dx0 = outputs[0].grad # Compute val = self.forward_func.info.args["val"] if prop_down[0] or prop_down[1]: cv = F.constant(val, x0.shape) if not nn.get_auto_forward(): cv.forward() log_v = F.log(cv.data) if prop_down[0]: if accum[0]: g_x0 += g_dx0 * dy * F.r_pow_scalar(x0, val) * log_v**2.0 else: g_x0.copy_from(g_dx0 * dy * F.r_pow_scalar(x0, val) * log_v**2.0) if prop_down[1]: if accum[1]: g_dy += g_dx0 * F.r_pow_scalar(x0, val) * log_v else: g_dy.copy_from(g_dx0 * F.r_pow_scalar(x0, val) * log_v)
def __rpow__(self, other): """ Element-wise power function. Part of the implementation of the power operator expression. Args: other (float or ~nnabla.Variable): Internally calling :func:`~nnabla.functions.pow2` or :func:`~nnabla.functions.r_pow_scalar` according to the type. Returns: :class:`nnabla.Variable` """ import nnabla.functions as F if isinstance(other, Variable): return F.pow2(other, self) return F.r_pow_scalar(self, other)