code: def test_individual_constraint_objects(self):
      fun = (
          lambda x: (x[0] - 1) ** 2
          + (x[1] - 2.5) ** 2
          + (x[2] - 0.75) ** 2
      )
      x0 = [2, 0, 1]
  
      cone = []  # with equality constraints (can't use cobyla)
      coni = []  # only inequality constraints (can use cobyla)
      methods = ["slsqp", "cobyla", "trust-constr"]
  
      # nonstandard data types for constraint equality bounds
      cone.append(NonlinearConstraint(lambda x: x[0] - x[1], 1, 1))
      cone.append(
          NonlinearConstraint(lambda x: x[0] - x[1], [1.21], [1.21])
      )
      cone.append(
          NonlinearConstraint(
              lambda x: x[0] - x[1], 1.21, np.array([1.21])
          )
      )
  
      # multiple equalities
      cone.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]], 1.21, 1.21
          )
      )  # two same equalities
      cone.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]],
              [1.21, 1.4],
              [1.21, 1.4],
          )
      )  # two different equalities
      cone.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]], [1.21, 1.21], 1.21
          )
      )  # equality specified two ways
      cone.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]],
              [1.21, -np.inf],
              [1.21, np.inf],
          )
      )  # equality + unbounded
  
      # nonstandard data types for constraint inequality bounds
      coni.append(
          NonlinearConstraint(lambda x: x[0] - x[1], 1.21, np.inf)
      )
      coni.append(
          NonlinearConstraint(lambda x: x[0] - x[1], [1.21], np.inf)
      )
      coni.append(
          NonlinearConstraint(
              lambda x: x[0] - x[1], 1.21, np.array([np.inf])
          )
      )
      coni.append(
          NonlinearConstraint(lambda x: x[0] - x[1], -np.inf, -3)
      )
      coni.append(
          NonlinearConstraint(
              lambda x: x[0] - x[1], np.array(-np.inf), -3
          )
      )
  
      # multiple inequalities/equalities
      coni.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]], 1.21, np.inf
          )
      )  # two same inequalities
      cone.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]],
              [1.21, -np.inf],
              [1.21, 1.4],
          )
      )  # mixed equality/inequality
      coni.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]],
              [1.1, 0.8],
              [1.2, 1.4],
          )
      )  # bounded above and below
      coni.append(
          NonlinearConstraint(
              lambda x: [x[0] - x[1], x[1] - x[2]],
              [-1.2, -1.4],
              [-1.1, -0.8],
          )
      )  # - bounded above and below
  
      # quick check of LinearConstraint class (very little new code to test)
      cone.append(LinearConstraint([1, -1, 0], 1.21, 1.21))
      cone.append(
          LinearConstraint([[1, -1, 0], [0, 1, -1]], 1.21, 1.21)
      )
      cone.append(
          LinearConstraint(
              [[1, -1, 0], [0, 1, -1]], [1.21, -np.inf], [1.21, 1.4]
          )
      )
  
      for con in coni:
          funs = {}
          for method in methods:
              with suppress_warnings() as sup:
                  sup.filter(UserWarning)
                  result = minimize(
                      fun, x0, method=method, constraints=con
                  )
                  funs[method] = result.fun
          assert_allclose(
              funs["slsqp"], funs["trust-constr"], rtol=1e-3
          )
          assert_allclose(
              funs["cobyla"], funs["trust-constr"], rtol=1e-3
          )
  
      for con in cone:
          funs = {}
          for method in methods[::2]:  # skip cobyla
              with suppress_warnings() as sup:
                  sup.filter(UserWarning)
                  result = minimize(
                      fun, x0, method=method, constraints=con
                  )
                  funs[method] = result.fun
          assert_allclose(
              funs["slsqp"], funs["trust-constr"], rtol=1e-3
          )
  
imports: from __future__ import division, print_function, absolute_import
  import numpy
  from numpy.testing import assert_, assert_array_almost_equal, assert_allclose, assert_equal, TestCase
  import pytest
  from scipy._lib._numpy_compat import suppress_warnings
  from scipy.optimize import NonlinearConstraint, LinearConstraint, Bounds, OptimizeWarning, minimize, BFGS
  from .test_minimize_constrained import Maratos, HyperbolicIneq, Rosenbrock, IneqRosenbrock, EqIneqRosenbrock, BoundedRosenbrock, Elec
  from scipy._lib._numpy_compat import _assert_warns, suppress_warnings
label_desc: Use image node_id 2 for calling the TestNewToOld obj's underlying member method code with example usage: obj.test_individual_constraint_objects() without return types