code: def _opt_1d(
      func, grad, hess, model, start, L1_wt, tol, check_step=True
  ):
      """
      One-dimensional helper for elastic net.
  
      Parameters
      ----------
      func : function
          A smooth function of a single variable to be optimized
          with L1 penaty.
      grad : function
          The gradient of `func`.
      hess : function
          The Hessian of `func`.
      model : statsmodels model
          The model being fit.
      start : real
          A starting value for the function argument
      L1_wt : non-negative real
          The weight for the L1 penalty function.
      tol : non-negative real
          A convergence threshold.
      check_step : bool
          If True, check that the first step is an improvement and
          use bisection if it is not.  If False, return after the
          first step regardless.
  
      Notes
      -----
      ``func``, ``grad``, and ``hess`` have argument signature (x,
      model), where ``x`` is a point in the parameter space and
      ``model`` is the model being fit.
  
      If the log-likelihood for the model is exactly quadratic, the
      global minimum is returned in one step.  Otherwise numerical
      bisection is used.
  
      Returns
      -------
      The argmin of the objective function.
      """
  
      # Overview:
      # We want to minimize L(x) + L1_wt*abs(x), where L() is a smooth
      # loss function that includes the log-likelihood and L2 penalty.
      # This is a 1-dimensional optimization.  If L(x) is exactly
      # quadratic we can solve for the argmin exactly.  Otherwise we
      # approximate L(x) with a quadratic function Q(x) and try to use
      # the minimizer of Q(x) + L1_wt*abs(x).  But if this yields an
      # uphill step for the actual target function L(x) + L1_wt*abs(x),
      # then we fall back to a expensive line search.  The line search
      # is never needed for OLS.
  
      x = start
      f = func(x, model)
      b = grad(x, model)
      c = hess(x, model)
      d = b - c * x
  
      # The optimum is achieved by hard thresholding to zero
      if L1_wt > np.abs(d):
          return 0.0
  
      # x + h is the minimizer of the Q(x) + L1_wt*abs(x)
      if d >= 0:
          h = (L1_wt - b) / c
      elif d < 0:
          h = -(L1_wt + b) / c
      else:
          return np.nan
  
      # If the new point is not uphill for the target function, take it
      # and return.  This check is a bit expensive and un-necessary for
      # OLS
      if not check_step:
          return x + h
      f1 = func(x + h, model) + L1_wt * np.abs(x + h)
      if f1 <= f + L1_wt * np.abs(x) + 1e-10:
          return x + h
  
      # Fallback for models where the loss is not quadratic
      from scipy.optimize import brent
  
      x_opt = brent(func, args=(model,), brack=(x - 1, x + 1), tol=tol)
      return x_opt
  
file_path: statsmodels/statsmodels/base/elastic_net.py
imports: import numpy
  from statsmodels.base.model import Results
  import statsmodels.base.wrapper
  from statsmodels.tools.decorators import cache_readonly
label_desc: Use image node_id 3 for calling a global function with example usage: _opt_1d(func, grad, hess, model, start, L1_wt, tol, check_step) and returns: x_opt, int, unknown, unknown, np