code: def test_bounds_cases():
      # Test 1: no constraints.
      user_constraint = Bounds(-np.inf, np.inf)
      x0 = np.array([-1, 2])
      prepared_constraint = PreparedConstraint(
          user_constraint, x0, False
      )
      c = CanonicalConstraint.from_PreparedConstraint(
          prepared_constraint
      )
  
      assert_equal(c.n_eq, 0)
      assert_equal(c.n_ineq, 0)
  
      c_eq, c_ineq = c.fun(x0)
      assert_array_equal(c_eq, [])
      assert_array_equal(c_ineq, [])
  
      J_eq, J_ineq = c.jac(x0)
      assert_array_equal(J_eq, np.empty((0, 2)))
      assert_array_equal(J_ineq, np.empty((0, 2)))
  
      assert_array_equal(c.keep_feasible, [])
  
      # Test 2: infinite lower bound.
      user_constraint = Bounds(
          -np.inf, [0, np.inf, 1], [False, True, True]
      )
      x0 = np.array([-1, -2, -3], dtype=float)
      prepared_constraint = PreparedConstraint(
          user_constraint, x0, False
      )
      c = CanonicalConstraint.from_PreparedConstraint(
          prepared_constraint
      )
  
      assert_equal(c.n_eq, 0)
      assert_equal(c.n_ineq, 2)
  
      c_eq, c_ineq = c.fun(x0)
      assert_array_equal(c_eq, [])
      assert_array_equal(c_ineq, [-1, -4])
  
      J_eq, J_ineq = c.jac(x0)
      assert_array_equal(J_eq, np.empty((0, 3)))
      assert_array_equal(J_ineq, np.array([[1, 0, 0], [0, 0, 1]]))
  
      assert_array_equal(c.keep_feasible, [False, True])
  
      # Test 3: infinite upper bound.
      user_constraint = Bounds(
          [0, 1, -np.inf], np.inf, [True, False, True]
      )
      x0 = np.array([1, 2, 3], dtype=float)
      prepared_constraint = PreparedConstraint(
          user_constraint, x0, False
      )
      c = CanonicalConstraint.from_PreparedConstraint(
          prepared_constraint
      )
  
      assert_equal(c.n_eq, 0)
      assert_equal(c.n_ineq, 2)
  
      c_eq, c_ineq = c.fun(x0)
      assert_array_equal(c_eq, [])
      assert_array_equal(c_ineq, [-1, -1])
  
      J_eq, J_ineq = c.jac(x0)
      assert_array_equal(J_eq, np.empty((0, 3)))
      assert_array_equal(J_ineq, np.array([[-1, 0, 0], [0, -1, 0]]))
  
      assert_array_equal(c.keep_feasible, [True, False])
  
      # Test 4: interval constraint.
      user_constraint = Bounds(
          [-1, -np.inf, 2, 3],
          [1, np.inf, 10, 3],
          [False, True, True, True],
      )
      x0 = np.array([0, 10, 8, 5])
      prepared_constraint = PreparedConstraint(
          user_constraint, x0, False
      )
      c = CanonicalConstraint.from_PreparedConstraint(
          prepared_constraint
      )
  
      assert_equal(c.n_eq, 1)
      assert_equal(c.n_ineq, 4)
  
      c_eq, c_ineq = c.fun(x0)
      assert_array_equal(c_eq, [2])
      assert_array_equal(c_ineq, [-1, -2, -1, -6])
  
      J_eq, J_ineq = c.jac(x0)
      assert_array_equal(J_eq, [[0, 0, 0, 1]])
      assert_array_equal(
          J_ineq,
          [[1, 0, 0, 0], [0, 0, 1, 0], [-1, 0, 0, 0], [0, 0, -1, 0]],
      )
  
      assert_array_equal(c.keep_feasible, [False, True, False, True])
  
file_path: scipy/scipy/optimize/_trustregion_constr/tests/test_canonical_constraint.py
imports: import numpy
  from numpy.testing import assert_array_equal, assert_equal
  from scipy.optimize._constraints import NonlinearConstraint, Bounds, PreparedConstraint
  from scipy.optimize._trustregion_constr.canonical_constraint import CanonicalConstraint, initial_constraints_as_canonical
label_desc: Use image node_id 2 for calling a global function with example usage: test_bounds_cases() without return types