Issue 1:
Describe your issue.

"scipy.optimize.shgo" bug in handling multi-dimensional variables.

My obj is a function of a two-dimensional variable. As the error message shows below, 'shgo' seems can't handle (m,) shape variables.

However, even after I have changed "if g(self.x_a, *args) < 0.0:" to "if any(g(self.x_a, *args) < 0.0):", there is still an error which leads to a failure result with the msg:

'Failed to find a feasible minimizer point. Lowest sampling point = None'

My obj and constraint functions work well with other solvers such as opt.minimize, opt.differential_evolution.

Besides, if I reduce the dimension of my variable to a scalar, it also works fine.

Reproducing Code Example

obj=lambda x: ObjL(np.block([ np.ones([PKzM.shape[0],1])*x[0],
np.ones([PKzM.shape[0],1])*x[1],
PKzM ]), # shape: (n,3)
PCM, VKM, VCM, rM)

...

res = opt.shgo(obj, bounds, constraints=cons, options={'f_tol':1e-3},
callback=print_xk)

Error message

Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py", line 631, in __getitem__
return self.cache[x]
KeyError: (0, 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo.py", line 426, in shgo
shc.construct_complex()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo.py", line 751, in construct_complex
self.iterate()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo.py", line 894, in iterate
self.iterate_complex()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo.py", line 916, in iterate_hypercube
self.HC = Complex(self.dim, self._raw_func, self.args,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py", line 25, in __init__
self.n_cube(dim, symmetry=symmetry)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py", line 76, in n_cube
self.C0.add_vertex(self.V[origintuple])
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py", line 635, in __getitem__
xval = Vertex(x, bounds=self.bounds,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py", line 552, in __init__
if g(self.x_a, *args) < 0.0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

SciPy/NumPy/Python version and system information

scipy version: '1.10.0'

Issue 2:
The documentation seems to impy that constraints can be vector function. However, when I tried to modify the basic example given there to work with one inequaity constraint that returns a 2-dimensional vector instead of two scalar constraints, I got an error.

Here is my code:

def f(x): # (cattle-feed)
return 24.55*x[0] + 26.75*x[1] + 39*x[2] + 40.50*x[3]

def g1(x):
return 2.3*x[0] + 5.6*x[1] + 11.1*x[2] + 1.3*x[3] - 5 # >=0

def g2(x):
return (12*x[0] + 11.9*x[1] +41.8*x[2] + 52.1*x[3] - 21
- 1.645 * np.sqrt(0.28*x[0]**2 + 0.19*x[1]**2
+ 20.5*x[2]**2 + 0.62*x[3]**2)
) # >=0

def h1(x):
return x[0] + x[1] + x[2] + x[3] - 1 # == 0

cons = ({'type': 'ineq', 'fun': g1},
{'type': 'ineq', 'fun': g2},
{'type': 'eq', 'fun': h1})
bounds = [(0, 1.0),]*4
res = shgo(f, bounds, iters=3, constraints=cons)

def double_g_fun(x):
return np.array([g1(x), g2(x)])

new_cons = ({'type': 'ineq', 'fun':double_g_fun},
{'type': 'eq', 'fun': h1})

new_res = shgo(f, bounds, iters=3, constraints=new_cons)`

And here is the error message:

KeyError Traceback (most recent call last)
~\anaconda3\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py in __getitem__(self, x, indexed)
629 try:
--> 630 return self.cache[x]
631 except KeyError:

KeyError: (0, 0, 0, 0)

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16320/2455765945.py in <module>
9 # {'type': 'eq', 'fun': h1})
10 # bounds = [(0, 1.0),]*4
---> 11 new_res = shgo(f, bounds, iters=3, constraints=new_cons)

~\anaconda3\lib\site-packages\scipy\optimize\_shgo.py in shgo(func, bounds, args, constraints, n, iters, callback, minimizer_kwargs, options, sampling_method)
417
418 # Run the algorithm, process results and test success
--> 419 shc.construct_complex()
420
421 if not shc.break_routine:

~\anaconda3\lib\site-packages\scipy\optimize\_shgo.py in construct_complex(self)
731 break
732 # Iterate complex, process minimisers
--> 733 self.iterate()
734 self.stopping_criteria()
735

~\anaconda3\lib\site-packages\scipy\optimize\_shgo.py in iterate(self)
874
875 def iterate(self):
--> 876 self.iterate_complex()
877
878 # Build minimizer pool

~\anaconda3\lib\site-packages\scipy\optimize\_shgo.py in iterate_hypercube(self)
893 if self.n_sampled == 0:
894 # Initial triangulation of the hyper-rectangle
--> 895 self.HC = Complex(self.dim, self.func, self.args,
896 self.symmetry, self.bounds, self.g_cons,
897 self.g_args)

~\anaconda3\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py in __init__(self, dim, func, func_args, symmetry, bounds, g_cons, g_args)
23
24 # Generate n-cube here:
---> 25 self.n_cube(dim, symmetry=symmetry)
26
27 # TODO: Assign functions to a the complex instead

~\anaconda3\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py in n_cube(self, dim, symmetry, printout)
74 else:
75 self.C0 = Cell(0, 0, origin, supremum) # Initial cell object
---> 76 self.C0.add_vertex(self.V[origintuple])
77 self.C0.add_vertex(self.V[supremumtuple])
78

~\anaconda3\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py in __getitem__(self, x, indexed)
632 if indexed:
633 self.index += 1
--> 634 xval = Vertex(x, bounds=self.bounds,
635 func=self.func, func_args=self.func_args,
636 g_cons=self.g_cons,

~\anaconda3\lib\site-packages\scipy\optimize\_shgo_lib\triangulation.py in __init__(self, x, bounds, func, func_args, g_cons, g_cons_args, nn, index)
550 if g_cons is not None:
551 for g, args in zip(g_cons, g_cons_args):
--> 552 if g(self.x_a, *args) < 0.0:
553 self.f = np.inf
554 self.feasible = False

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()