[Scipy-svn] r6926 - in trunk/scipy/optimize: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Nov 20 02:27:43 CST 2010


Author: warren.weckesser
Date: 2010-11-20 02:27:43 -0600 (Sat, 20 Nov 2010)
New Revision: 6926

Modified:
   trunk/scipy/optimize/nnls.py
   trunk/scipy/optimize/optimize.py
   trunk/scipy/optimize/slsqp.py
   trunk/scipy/optimize/tests/test_optimize.py
Log:
ENH: optimize: update 'raise' statements

Modified: trunk/scipy/optimize/nnls.py
===================================================================
--- trunk/scipy/optimize/nnls.py	2010-11-20 08:12:18 UTC (rev 6925)
+++ trunk/scipy/optimize/nnls.py	2010-11-20 08:27:43 UTC (rev 6926)
@@ -28,21 +28,22 @@
     A,b = map(asarray_chkfinite, (A,b))
 
     if len(A.shape)!=2:
-        raise ValueError, "expected matrix"
+        raise ValueError("expected matrix")
     if len(b.shape)!=1:
-        raise ValueError, "expected vector"
+        raise ValueError("expected vector")
 
     m,n = A.shape
 
     if m != b.shape[0]:
-        raise ValueError, "incompatible dimensions"
+        raise ValueError("incompatible dimensions")
 
     w   = zeros((n,), dtype=double)
     zz  = zeros((m,), dtype=double)
     index=zeros((n,), dtype=int)
 
     x,rnorm,mode = _nnls.nnls(A,m,n,b,w,zz,index)
-    if mode != 1: raise RuntimeError, "too many iterations"
+    if mode != 1:
+        raise RuntimeError("too many iterations")
 
     return x, rnorm
 

Modified: trunk/scipy/optimize/optimize.py
===================================================================
--- trunk/scipy/optimize/optimize.py	2010-11-20 08:12:18 UTC (rev 6925)
+++ trunk/scipy/optimize/optimize.py	2010-11-20 08:27:43 UTC (rev 6926)
@@ -237,7 +237,7 @@
     N = len(x0)
     rank = len(x0.shape)
     if not -1 < rank < 2:
-        raise ValueError, "Initial guess must be a scalar or rank-1 sequence."
+        raise ValueError("Initial guess must be a scalar or rank-1 sequence.")
     if maxiter is None:
         maxiter = N * 200
     if maxfun is None:
@@ -1285,7 +1285,7 @@
         assert ((fb<fa) and (fb < fc)), "Not a bracketing interval."
         funcalls = 3
     else:
-        raise ValueError, "Bracketing interval must be length 2 or 3 sequence."
+        raise ValueError("Bracketing interval must be length 2 or 3 sequence.")
 
     _gR = 0.61803399
     _gC = 1.0-_gR
@@ -1372,7 +1372,7 @@
         w = xb - ((xb-xc)*tmp2-(xb-xa)*tmp1)/denom
         wlim = xb + grow_limit*(xc-xb)
         if iter > maxiter:
-            raise RuntimeError, "Too many iterations."
+            raise RuntimeError("Too many iterations.")
         iter += 1
         if (w-xc)*(xb-w) > 0.0:
             fw = func(*((w,)+args))
@@ -1493,7 +1493,7 @@
     N = len(x)
     rank = len(x.shape)
     if not -1 < rank < 2:
-        raise ValueError, "Initial guess must be a scalar or rank-1 sequence."
+        raise ValueError("Initial guess must be a scalar or rank-1 sequence.")
     if maxiter is None:
         maxiter = N * 1000
     if maxfun is None:
@@ -1629,8 +1629,8 @@
     """
     N = len(ranges)
     if N > 40:
-        raise ValueError, "Brute Force not possible with more " \
-              "than 40 variables."
+        raise ValueError("Brute Force not possible with more " \
+              "than 40 variables.")
     lrange = list(ranges)
     for k in range(N):
         if type(lrange[k]) is not type(slice(None)):

Modified: trunk/scipy/optimize/slsqp.py
===================================================================
--- trunk/scipy/optimize/slsqp.py	2010-11-20 08:12:18 UTC (rev 6925)
+++ trunk/scipy/optimize/slsqp.py	2010-11-20 08:27:43 UTC (rev 6926)
@@ -256,13 +256,13 @@
     if len(bounds) == 0:
         bounds = [(-1.0E12, 1.0E12) for i in range(n)]
     elif len(bounds) != n:
-        raise IndexError, \
-        'SLSQP Error:  If bounds is specified, len(bounds) == len(x0)'
+        raise IndexError('SLSQP Error:  If bounds is specified, '
+                            'len(bounds) == len(x0)')
     else:
         for i in range(len(bounds)):
             if bounds[i][0] > bounds[i][1]:
-                raise ValueError, \
-                'SLSQP Error: lb > ub in bounds[' + str(i) +']  ' + str(bounds[4])
+                raise ValueError('SLSQP Error: lb > ub in bounds[' + str(i)
+                                    + ']  ' + str(bounds[4]))
 
     xl = array( [ b[0] for b in bounds ] )
     xu = array( [ b[1] for b in bounds ] )

Modified: trunk/scipy/optimize/tests/test_optimize.py
===================================================================
--- trunk/scipy/optimize/tests/test_optimize.py	2010-11-20 08:12:18 UTC (rev 6925)
+++ trunk/scipy/optimize/tests/test_optimize.py	2010-11-20 08:27:43 UTC (rev 6926)
@@ -39,7 +39,7 @@
     def func(self, x):
         self.funccalls += 1
         if self.funccalls > 6000:
-            raise RuntimeError, "too many iterations in optimization routine"
+            raise RuntimeError("too many iterations in optimization routine")
         log_pdot = dot(self.F, x)
         logZ = log(sum(exp(log_pdot)))
         f = logZ - dot(self.K, x)



More information about the Scipy-svn mailing list