original_docstring: Generate a function to evaluate the gradient of a scalar-valued function.
  
      The passed function should take as arguments symbolic arrays and return a
      symbolic scalar, and likewise the returned function will take symbolic array
      arguments.
  
      Args:
          func (Callable[..., Scalar]): Function which takes one or more arrays as
              arguments and returns a scalar.
          wrt (int): Index of argument to take derivatives with respect to.
          return_aux (bool): Whether the generated gradient function returns both
              the gradient and value of `func` as a 2-tuple (True) or just the
              gradient (False).
  
      Returns:
          Callable[..., Union[Array, Tuple[Array, Scalar]]]: Generated gradient
              function.
      
docstring: Generate a function to evaluate the gradient of a scalar-valued function.
  The passed function should take as arguments symbolic arrays and return a
  symbolic scalar, and likewise the returned function will take symbolic array
  arguments.
docstring_tokens: Generate a function to evaluate the gradient of a scalar - valued function . The passed function should take as arguments symbolic arrays and return a symbolic scalar and likewise the returned function will take symbolic array arguments .
code: def gradient(func, wrt=0, return_aux=False):
      """Generate a function to evaluate the gradient of a scalar-valued function.
  
      The passed function should take as arguments symbolic arrays and return a
      symbolic scalar, and likewise the returned function will take symbolic array
      arguments.
  
      Args:
          func (Callable[..., Scalar]): Function which takes one or more arrays as
              arguments and returns a scalar.
          wrt (int): Index of argument to take derivatives with respect to.
          return_aux (bool): Whether the generated gradient function returns both
              the gradient and value of `func` as a 2-tuple (True) or just the
              gradient (False).
  
      Returns:
          Callable[..., Union[Array, Tuple[Array, Scalar]]]: Generated gradient
              function.
      """
  
      @_wrap_derived(func, 'grad', 'gradient')
      def grad_func(*args):
          val = _get_sympy_func(func)(*args)
          if not _is_scalar(val) or (hasattr(val, 'shape') and val.shape != ()):
              raise ValueError(
                  'gradient should only be used with scalar valued functions.')
          grad = sym.diff(val, args[wrt])
          return (grad, val) if return_aux else grad
  
      return grad_func
code_tokens: def gradient ( func , wrt = 0 , return_aux = False ) : @ _wrap_derived ( func , 'grad' , 'gradient' ) def grad_func ( * args ) : val = _get_sympy_func ( func ) ( * args ) if not _is_scalar ( val ) or ( hasattr ( val , 'shape' ) and val . shape != ( ) ) : raise ValueError ( 'gradient should only be used with scalar valued functions.' ) grad = sym . diff ( val , args [ wrt ] ) return ( grad , val ) if return_aux else grad return grad_func
short_docstring: Generate a function to evaluate the gradient of a scalar-valued function.
short_docstring_tokens: Generate a function to evaluate the gradient of a scalar - valued function .
comment: """Generate a function to evaluate the gradient of a scalar-valued function.
  
      The passed function should take as arguments symbolic arrays and return a
      symbolic scalar, and likewise the returned function will take symbolic array
      arguments.
  
      Args:
          func (Callable[..., Scalar]): Function which takes one or more arrays as
              arguments and returns a scalar.
          wrt (int): Index of argument to take derivatives with respect to.
          return_aux (bool): Whether the generated gradient function returns both
              the gradient and value of `func` as a 2-tuple (True) or just the
              gradient (False).
  
      Returns:
          Callable[..., Union[Array, Tuple[Array, Scalar]]]: Generated gradient
              function.
      """