code: def grad(fun, x):
      """
      Returns a function which computes the gradient of `fun` with respect to
      positional argument number `argnum`. The returned function takes the same
      arguments as `fun`, but returns the gradient instead. The function `fun`
      should be scalar-valued. The gradient has the same type as the argument.
      """
      vjp, ans = _make_vjp(fun, x)
      if not vspace(ans).size == 1:
          raise TypeError(
              "Grad only applies to real scalar-output functions. "
              "Try jacobian, elementwise_grad or holomorphic_grad."
          )
      return vjp(vspace(ans).ones())
  
imports: from __future__ import absolute_import
  from functools import partial
  from collections import OrderedDict
  import warnings
  from .wrap_util import unary_to_nary
  from .builtins import tuple
  from .core import make_vjp, make_jvp
  from .extend import primitive, defvjp_argnum, vspace
  import autograd.numpy
label_desc: Use image node_id 1 for calling a global function with example usage: grad(fun, x) and returns: vjp