code: def select_step(x, A_h, g_h, c_h, p, p_h, d, lb, ub, theta):
      """Select the best step according to Trust Region Reflective algorithm."""
      if in_bounds(x + p, lb, ub):
          return p
  
      p_stride, hits = step_size_to_bound(x, p, lb, ub)
      r_h = np.copy(p_h)
      r_h[hits.astype(bool)] *= -1
      r = d * r_h
  
      # Restrict step, such that it hits the bound.
      p *= p_stride
      p_h *= p_stride
      x_on_bound = x + p
  
      # Find the step size along reflected direction.
      r_stride_u, _ = step_size_to_bound(x_on_bound, r, lb, ub)
  
      # Stay interior.
      r_stride_l = (1 - theta) * r_stride_u
      r_stride_u *= theta
  
      if r_stride_u > 0:
          a, b, c = build_quadratic_1d(A_h, g_h, r_h, s0=p_h, diag=c_h)
          r_stride, r_value = minimize_quadratic_1d(
              a, b, r_stride_l, r_stride_u, c=c
          )
          r_h = p_h + r_h * r_stride
          r = d * r_h
      else:
          r_value = np.inf
  
      # Now correct p_h to make it strictly interior.
      p_h *= theta
      p *= theta
      p_value = evaluate_quadratic(A_h, g_h, p_h, diag=c_h)
  
      ag_h = -g_h
      ag = d * ag_h
      ag_stride_u, _ = step_size_to_bound(x, ag, lb, ub)
      ag_stride_u *= theta
      a, b = build_quadratic_1d(A_h, g_h, ag_h, diag=c_h)
      ag_stride, ag_value = minimize_quadratic_1d(a, b, 0, ag_stride_u)
      ag *= ag_stride
  
      if p_value < r_value and p_value < ag_value:
          return p
      elif r_value < p_value and r_value < ag_value:
          return r
      else:
          return ag
  
file_path: catboost/contrib/python/scipy/py2/scipy/optimize/_lsq/trf_linear.py
imports: from __future__ import division, print_function, absolute_import
  import numpy
  from numpy.linalg import norm
  from scipy.linalg import qr, solve_triangular
  from scipy.sparse.linalg import lsmr
  from scipy.optimize import OptimizeResult
  from .givens_elimination import givens_elimination
  from .common import EPS, step_size_to_bound, find_active_constraints, in_bounds, make_strictly_feasible, build_quadratic_1d, evaluate_quadratic, minimize_quadratic_1d, CL_scaling_vector, reflective_transformation, print_header_linear, print_iteration_linear, compute_grad, regularized_lsq_operator, right_multiplied_operator
label_desc: Use image node_id 3 for calling a global function with example usage: select_step(x, A_h, g_h, c_h, p, p_h, d, lb, ub, theta) and returns: p, p, r, ag