--- scipy/optimize/optimize.py.orig 2009-07-11 17:56:37.000000000 +1200 +++ scipy/optimize/optimize.py 2010-05-17 21:36:07.605336495 +1200 @@ -41,6 +41,12 @@ m = asarray(m) return numpy.minimum.reduce(m,axis) +def is_array_scalar(x): + """Test whether `x` is either a scalar or an array scalar. + + """ + return len(atleast_1d(x) == 1) + abs = absolute import __builtin__ pymin = __builtin__.min @@ -1177,13 +1183,12 @@ """ # Test bounds are of correct form - x1 = atleast_1d(x1) - x2 = atleast_1d(x2) - if len(x1) != 1 or len(x2) != 1: - raise ValueError, "Optimisation bounds must be scalars" \ - " or length 1 arrays" + + if not (is_array_scalar(x1) and is_array_scalar(x2)): + raise ValueError("Optimisation bounds must be scalars" + " or array scalars.") if x1 > x2: - raise ValueError, "The lower bound exceeds the upper bound." + raise ValueError("The lower bound exceeds the upper bound.") flag = 0 header = ' Func-count x f(x) Procedure' --- scipy/optimize/tests/test_optimize.py.orig 2009-07-11 17:56:37.000000000 +1200 +++ scipy/optimize/tests/test_optimize.py 2010-05-18 21:31:39.000000000 +1200 @@ -159,10 +160,17 @@ assert abs(x - 1.5) < 1e-6 assert_raises(ValueError, optimize.fminbound, lambda x: (x - 1.5)**2 - 0.8, 5, 1) + + def test_fminbound_scalar(self): assert_raises(ValueError, - optimize.fminbound, lambda x: (x - 1.5)**2 - 0.8, + optimize.fminbound, lambda x: (x - 1.5)**2 - 0.8, np.zeros(2), 1) + assert_almost_equal( + optimize.fminbound(lambda x: (x - 1.5)**2 - 0.8, 1, np.array(5)), + 1.5) + + class TestTnc(TestCase): """TNC non-linear optimization.