[Scipy-svn] r2197 - trunk/Lib/sandbox/odr

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Sep 12 15:49:37 CDT 2006


Author: rkern
Date: 2006-09-12 15:49:35 -0500 (Tue, 12 Sep 2006)
New Revision: 2197

Modified:
   trunk/Lib/sandbox/odr/models.py
   trunk/Lib/sandbox/odr/odrpack.py
Log:
Fix odr for numpy.

Modified: trunk/Lib/sandbox/odr/models.py
===================================================================
--- trunk/Lib/sandbox/odr/models.py	2006-09-12 08:37:24 UTC (rev 2196)
+++ trunk/Lib/sandbox/odr/models.py	2006-09-12 20:49:35 UTC (rev 2197)
@@ -2,23 +2,23 @@
 """
 
 from scipy.sandbox.odr.odrpack import Model
-import numpy as sb
+import numpy as np
 from types import *
 
-def _lin_fcn(B, x, sum=sb.sum):
+def _lin_fcn(B, x, sum=np.sum):
     a, b = B[0], B[1:]
     b.shape = (b.shape[0], 1)
 
     return a + sum(x*b,axis=0)
 
-def _lin_fjb(B, x, concatenate=sb.concatenate, Float=sb.Float,
-             ones=sb.ones, ravel=sb.ravel):
-    a = ones((x.shape[-1],), Float)
+def _lin_fjb(B, x, concatenate=np.concatenate, 
+             ones=np.ones, ravel=np.ravel):
+    a = ones((x.shape[-1],), float)
     res = concatenate((a, ravel(x)))
     res.shape = (B.shape[-1], x.shape[-1])
     return res
 
-def _lin_fjd(B, x, repeat=sb.repeat):
+def _lin_fjd(B, x, repeat=np.repeat):
     b = B[1:]
     b = repeat(b, (x.shape[-1],)*b.shape[-1],axis=0)
     b.shape = x.shape
@@ -34,21 +34,21 @@
     else:
         m = 1
 
-    return ones((m + 1,), Float)
+    return np.ones((m + 1,), float)
 
-def _poly_fcn(B, x, powers, power=sb.power, sum=sb.sum):
+def _poly_fcn(B, x, powers, power=np.power, sum=np.sum):
     a, b = B[0], B[1:]
     b.shape = (b.shape[0], 1)
 
     return a + sum(b * power(x, powers),axis=0)
 
-def _poly_fjacb(B, x, powers, power=sb.power,
-                concatenate=sb.concatenate, Float=sb.Float, ones=sb.ones):
-    res = concatenate((ones((x.shape[-1],), Float), power(x, powers).flat))
+def _poly_fjacb(B, x, powers, power=np.power,
+                concatenate=np.concatenate, ones=np.ones):
+    res = concatenate((ones((x.shape[-1],), float), power(x, powers).flat))
     res.shape = (B.shape[-1], x.shape[-1])
     return res
 
-def _poly_fjacd(B, x, powers, power=sb.power, sum=sb.sum):
+def _poly_fjacd(B, x, powers, power=np.power, sum=np.sum):
     b = B[1:]
     b.shape = (b.shape[0], 1)
 
@@ -56,15 +56,14 @@
 
     return sum(b * power(x, powers-1),axis=0)
 
-def _exp_fcn(B, x, exp=sb.exp):
+def _exp_fcn(B, x, exp=np.exp):
     return B[0] + exp(B[1] * x)
 
-def _exp_fjd(B, x, exp=sb.exp):
+def _exp_fjd(B, x, exp=np.exp):
     return B[1] * exp(B[1] * x)
 
-def _exp_fjb(B, x, exp=sb.exp, concatenate=sb.concatenate, ones=sb.ones,
-             Float=sb.Float):
-    res = concatenate((ones((x.shape[-1],), sb.Float), x * exp(B[1] * x)))
+def _exp_fjb(B, x, exp=np.exp, concatenate=np.concatenate, ones=np.ones):
+    res = concatenate((ones((x.shape[-1],), float), x * exp(B[1] * x)))
     res.shape = (2, x.shape[-1])
     return res
 
@@ -94,7 +93,7 @@
     if type(order) is int:
         order = range(1, order+1)
 
-    powers = sb.asarray(order)
+    powers = np.asarray(order)
     powers.shape = (len(powers), 1)
 
     len_beta = len(powers) + 1
@@ -102,7 +101,7 @@
     def _poly_est(data, len_beta=len_beta):
         # Eh. Ignore data and return all ones.
 
-        return sb.ones((len_beta,), sb.Float)
+        return np.ones((len_beta,), float)
 
     return Model(_poly_fcn, fjacd=_poly_fjd, fjacb=_poly_fjb,
                  estimate=_poly_est, extra_args=(powers,),
@@ -120,10 +119,10 @@
     return x*B[0] + B[1]
 
 def _unilin_fjd(B, x):
-    return sb.ones(x.shape, sb.Float) * B[0]
+    return np.ones(x.shape, float) * B[0]
 
-def _unilin_fjb(B, x, cat=sb.concatenate):
-    _ret = cat((x,sb.ones(x.shape, sb.Float)))
+def _unilin_fjb(B, x, cat=np.concatenate):
+    _ret = cat((x,np.ones(x.shape, float)))
     _ret.shape = (2,) + x.shape
 
     return _ret
@@ -137,8 +136,8 @@
 def _quad_fjd(B, x):
     return 2*x*B[0] + B[1]
 
-def _quad_fjb(B,x,cat=sb.concatenate):
-    _ret = cat((x*x, x, sb.ones(x.shape, Float)))
+def _quad_fjb(B,x,cat=np.concatenate):
+    _ret = cat((x*x, x, np.ones(x.shape, float)))
     _ret.shape = (3,) + x.shape
 
     return _ret

Modified: trunk/Lib/sandbox/odr/odrpack.py
===================================================================
--- trunk/Lib/sandbox/odr/odrpack.py	2006-09-12 08:37:24 UTC (rev 2196)
+++ trunk/Lib/sandbox/odr/odrpack.py	2006-09-12 20:49:35 UTC (rev 2197)
@@ -110,6 +110,7 @@
 robert.kern at gmail.com
 """
 
+import numpy
 from scipy.sandbox.odr import __odrpack
 from types import NoneType
 
@@ -854,7 +855,7 @@
                      5*q + q*(p+m) + ldwe*ld2we*q)
 
         if isinstance(self.work, numpy.ndarray) and self.work.shape == (lwork,)\
-                and self.work.dtype == numpy.Float:
+                and self.work.dtype.str.endswith('f8'):
             # the existing array is fine
             return
         else:



More information about the Scipy-svn mailing list