code: def fmin_ncg(
      f,
      x0,
      fprime,
      fhess_p=None,
      fhess=None,
      args=(),
      avextol=1e-5,
      epsilon=_epsilon,
      maxiter=None,
      full_output=0,
      disp=1,
      retall=0,
      callback=None,
  ):
      """
      Unconstrained minimization of a function using the Newton-CG method.
  
      Parameters
      ----------
      f : callable ``f(x, *args)``
          Objective function to be minimized.
      x0 : ndarray
          Initial guess.
      fprime : callable ``f'(x, *args)``
          Gradient of f.
      fhess_p : callable ``fhess_p(x, p, *args)``, optional
          Function which computes the Hessian of f times an
          arbitrary vector, p.
      fhess : callable ``fhess(x, *args)``, optional
          Function to compute the Hessian matrix of f.
      args : tuple, optional
          Extra arguments passed to f, fprime, fhess_p, and fhess
          (the same set of extra arguments is supplied to all of
          these functions).
      epsilon : float or ndarray, optional
          If fhess is approximated, use this value for the step size.
      callback : callable, optional
          An optional user-supplied function which is called after
          each iteration. Called as callback(xk), where xk is the
          current parameter vector.
      avextol : float, optional
          Convergence is assumed when the average relative error in
          the minimizer falls below this amount.
      maxiter : int, optional
          Maximum number of iterations to perform.
      full_output : bool, optional
          If True, return the optional outputs.
      disp : bool, optional
          If True, print convergence message.
      retall : bool, optional
          If True, return a list of results at each iteration.
  
      Returns
      -------
      xopt : ndarray
          Parameters which minimize f, i.e., ``f(xopt) == fopt``.
      fopt : float
          Value of the function at xopt, i.e., ``fopt = f(xopt)``.
      fcalls : int
          Number of function calls made.
      gcalls : int
          Number of gradient calls made.
      hcalls : int
          Number of Hessian calls made.
      warnflag : int
          Warnings generated by the algorithm.
          1 : Maximum number of iterations exceeded.
          2 : Line search failure (precision loss).
          3 : NaN result encountered.
      allvecs : list
          The result at each iteration, if retall is True (see below).
  
      See also
      --------
      minimize: Interface to minimization algorithms for multivariate
          functions. See the 'Newton-CG' `method` in particular.
  
      Notes
      -----
      Only one of `fhess_p` or `fhess` need to be given.  If `fhess`
      is provided, then `fhess_p` will be ignored. If neither `fhess`
      nor `fhess_p` is provided, then the hessian product will be
      approximated using finite differences on `fprime`. `fhess_p`
      must compute the hessian times an arbitrary vector. If it is not
      given, finite-differences on `fprime` are used to compute
      it.
  
      Newton-CG methods are also called truncated Newton methods. This
      function differs from scipy.optimize.fmin_tnc because
  
      1. scipy.optimize.fmin_ncg is written purely in Python using NumPy
          and scipy while scipy.optimize.fmin_tnc calls a C function.
      2. scipy.optimize.fmin_ncg is only for unconstrained minimization
          while scipy.optimize.fmin_tnc is for unconstrained minimization
          or box constrained minimization. (Box constraints give
          lower and upper bounds for each variable separately.)
  
      References
      ----------
      Wright & Nocedal, 'Numerical Optimization', 1999, p. 140.
  
      """
      opts = {
          "xtol": avextol,
          "eps": epsilon,
          "maxiter": maxiter,
          "disp": disp,
          "return_all": retall,
      }
  
      res = _minimize_newtoncg(
          f, x0, args, fprime, fhess, fhess_p, callback=callback, **opts
      )
  
      if full_output:
          retlist = (
              res["x"],
              res["fun"],
              res["nfev"],
              res["njev"],
              res["nhev"],
              res["status"],
          )
          if retall:
              retlist += (res["allvecs"],)
          return retlist
      else:
          if retall:
              return res["x"], res["allvecs"]
          else:
              return res["x"]
  
imports: import warnings
  import sys
  from numpy import atleast_1d, eye, argmin, zeros, shape, squeeze, asarray, sqrt, Inf, asfarray, isinf
  import numpy
  from .linesearch import line_search_wolfe1, line_search_wolfe2, line_search_wolfe2, LineSearchWarning
  from ._numdiff import approx_derivative
  from scipy._lib._util import getfullargspec_no_self
  from scipy._lib._util import MapWrapper
  from scipy.optimize._differentiable_functions import ScalarFunction, FD_METHODS
label_desc: Use image node_id 22 for calling a global function with example usage: fmin_ncg(f, x0, fprime, fhess_p, fhess, args, avextol, epsilon, maxiter, full_output, disp, retall, callback) and returns: retlist, res,  res, res