code: def new_constraint_to_old(con, x0):
      """
      Converts new-style constraint objects to old-style constraint dictionaries.
      """
      if isinstance(con, NonlinearConstraint):
          if (
              con.finite_diff_jac_sparsity is not None
              or con.finite_diff_rel_step is not None
              or not isinstance(con.hess, BFGS)
              or con.keep_feasible  # misses user specified BFGS
          ):
              warn(
                  "Constraint options `finite_diff_jac_sparsity`, "
                  "`finite_diff_rel_step`, `keep_feasible`, and `hess`"
                  "are ignored by this method.",
                  OptimizeWarning,
              )
  
          fun = con.fun
          if callable(con.jac):
              jac = con.jac
          else:
              jac = None
  
      else:  # LinearConstraint
          if con.keep_feasible:
              warn(
                  "Constraint option `keep_feasible` is ignored by this "
                  "method.",
                  OptimizeWarning,
              )
  
          A = con.A
          if issparse(A):
              A = A.todense()
          fun = lambda x: np.dot(A, x)
          jac = lambda x: A
  
      # FIXME: when bugs in VectorFunction/LinearVectorFunction are worked out,
      # use pcon.fun.fun and pcon.fun.jac. Until then, get fun/jac above.
      pcon = PreparedConstraint(con, x0)
      lb, ub = pcon.bounds
  
      i_eq = lb == ub
      i_bound_below = np.logical_xor(lb != -np.inf, i_eq)
      i_bound_above = np.logical_xor(ub != np.inf, i_eq)
      i_unbounded = np.logical_and(lb == -np.inf, ub == np.inf)
  
      if np.any(i_unbounded):
          warn(
              "At least one constraint is unbounded above and below. Such "
              "constraints are ignored.",
              OptimizeWarning,
          )
  
      ceq = []
      if np.any(i_eq):
  
          def f_eq(x):
              y = np.array(fun(x)).flatten()
              return y[i_eq] - lb[i_eq]
  
          ceq = [{"type": "eq", "fun": f_eq}]
  
          if jac is not None:
  
              def j_eq(x):
                  dy = jac(x)
                  if issparse(dy):
                      dy = dy.todense()
                  dy = np.atleast_2d(dy)
                  return dy[i_eq, :]
  
              ceq[0]["jac"] = j_eq
  
      cineq = []
      n_bound_below = np.sum(i_bound_below)
      n_bound_above = np.sum(i_bound_above)
      if n_bound_below + n_bound_above:
  
          def f_ineq(x):
              y = np.zeros(n_bound_below + n_bound_above)
              y_all = np.array(fun(x)).flatten()
              y[:n_bound_below] = (
                  y_all[i_bound_below] - lb[i_bound_below]
              )
              y[n_bound_below:] = -(
                  y_all[i_bound_above] - ub[i_bound_above]
              )
              return y
  
          cineq = [{"type": "ineq", "fun": f_ineq}]
  
          if jac is not None:
  
              def j_ineq(x):
                  dy = np.zeros(
                      (n_bound_below + n_bound_above, len(x0))
                  )
                  dy_all = jac(x)
                  if issparse(dy_all):
                      dy_all = dy_all.todense()
                  dy_all = np.atleast_2d(dy_all)
                  dy[:n_bound_below, :] = dy_all[i_bound_below]
                  dy[n_bound_below:, :] = -dy_all[i_bound_above]
                  return dy
  
              cineq[0]["jac"] = j_ineq
  
      old_constraints = ceq + cineq
  
      if len(old_constraints) > 1:
          warn(
              "Equality and inequality constraints are specified in the same "
              "element of the constraint list. For efficient use with this "
              "method, equality and inequality constraints should be specified "
              "in separate elements of the constraint list. ",
              OptimizeWarning,
          )
      return old_constraints
  
imports: from __future__ import division, print_function, absolute_import
  import numpy
  from ._hessian_update_strategy import BFGS
  from ._differentiable_functions import VectorFunction, LinearVectorFunction, IdentityVectorFunction
  from .optimize import OptimizeWarning
  from warnings import warn
  from scipy.sparse import issparse
label_desc: Use image node_id 4 for calling a global function with example usage: new_constraint_to_old(con, x0) and returns: old_constraints, unknown, y, dy, dy