code: def logsumexp_vjp(ans, x):
      # If you want to be able to take higher-order derivatives, then all the
      # code inside this function must be itself differentiable by Autograd.
      # This closure multiplies g with the Jacobian of logsumexp (d_ans/d_x).
      # Because Autograd uses reverse-mode differentiation, g contains
      # the gradient of the objective w.r.t. ans, the output of logsumexp.
      # This returned VJP function doesn't close over `x`, so Python can
      # garbage-collect `x` if there are no references to it elsewhere.
      x_shape = x.shape
      return lambda g: np.full(x_shape, g) * np.exp(
          x - np.full(x_shape, ans)
      )
  
file_path: autograd/examples/define_gradient.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  import autograd.numpy
  import autograd.numpy.random
  from autograd import grad
  from autograd.extend import primitive, defvjp
  from autograd.test_util import check_grads
label_desc: Use image node_id 2 for calling a global function with example usage: logsumexp_vjp(ans, x) and returns: function