[Scipy-svn] r2148 - in trunk/Lib: io sandbox/odr sandbox/xplt stats/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Aug 4 05:13:26 CDT 2006


Author: edschofield
Date: 2006-08-04 05:13:12 -0500 (Fri, 04 Aug 2006)
New Revision: 2148

Modified:
   trunk/Lib/io/mio.py
   trunk/Lib/io/mmio.py
   trunk/Lib/sandbox/odr/odrpack.py
   trunk/Lib/sandbox/xplt/ezplot.py
   trunk/Lib/sandbox/xplt/graph.py
   trunk/Lib/sandbox/xplt/shapetest.py
   trunk/Lib/stats/tests/test_distributions.py
Log:
Some conversions ArrayType -> ndarray


Modified: trunk/Lib/io/mio.py
===================================================================
--- trunk/Lib/io/mio.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/io/mio.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -3,7 +3,7 @@
 # Author: Travis Oliphant
 
 from numpy import squeeze
-from numpy import ndarray as ArrayType
+from numpy import ndarray
 from numpy import *
 import numpyio
 import struct, os, sys
@@ -857,7 +857,7 @@
     O = 0
     for variable in dict.keys():
         var = dict[variable]
-        if not isinstance(var, ArrayType):
+        if not isinstance(var, ndarray):
             continue
         if var.dtype.char == 'S1':
             T = 1

Modified: trunk/Lib/io/mmio.py
===================================================================
--- trunk/Lib/io/mmio.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/io/mmio.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -13,9 +13,7 @@
 # TODO: support for sparse matrices, need spmatrix.tocoo().
 
 import os
-from types import ListType, TupleType
-from numpy import asarray, real,imag,conj,zeros
-from numpy import ndarray as ArrayType
+from numpy import asarray, real, imag, conj, zeros, ndarray
 
 __all__ = ['mminfo','mmread','mmwrite']
 
@@ -239,7 +237,7 @@
         target = open(target,'w')
         close_it = 1
 
-    if type(a) in [ListType,ArrayType,TupleType] or hasattr(a,'__array__'):
+    if isinstance(a, list) or isinstance(a, ndarray) or isinstance(a, tuple) or hasattr(a,'__array__'):
         rep = 'array'
         a = asarray(a)
         if len(a.shape) != 2:

Modified: trunk/Lib/sandbox/odr/odrpack.py
===================================================================
--- trunk/Lib/sandbox/odr/odrpack.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/sandbox/odr/odrpack.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -378,7 +378,7 @@
         if len(cov.shape) == 2:
             return linalg.inverse(cov)
         else:
-            weights = numpy.zeros(cov.shape, Float)
+            weights = numpy.zeros(cov.shape, float)
 
             for i in range(cov.shape[-1]):  # n
                 weights[:,:,i] = linalg.inv(cov[:,:,i])
@@ -740,7 +740,7 @@
 
         x_s = list(self.data.x.shape)
 
-        if type(self.data.y) is numpy.ArrayType:
+        if isinstance(self.data.y, numpy.ndarray):
             y_s = list(self.data.y.shape)
             if self.model.implicit:
                 raise odr_error, "an implicit model cannot use response data"
@@ -853,12 +853,12 @@
             lwork = (18 + 11*p + p*p + m + m*m + 4*n*q + 2*n*m + 2*n*q*p +
                      5*q + q*(p+m) + ldwe*ld2we*q)
 
-        if type(self.work) is numpy.ArrayType and self.work.shape == (lwork,)\
-           and self.work.dtype == numpy.Float:
+        if isinstance(self.work, numpy.ndarray) and self.work.shape == (lwork,)\
+                and self.work.dtype == numpy.Float:
             # the existing array is fine
             return
         else:
-            self.work = numpy.zeros((lwork,), numpy.Float)
+            self.work = numpy.zeros((lwork,), float)
 
     def set_job(self, fit_type=None, deriv=None, var_calc=None,
                 del_init=None, restart=None):

Modified: trunk/Lib/sandbox/xplt/ezplot.py
===================================================================
--- trunk/Lib/sandbox/xplt/ezplot.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/sandbox/xplt/ezplot.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -158,6 +158,7 @@
 
 import shapetest
 from scipy import *
+from numpy import ndarray
 from numpy.core.umath import *
 
 _ezdict_ = {'t': 'true' , 'T': 'true', 'y': 'true', 'Y': 'true',
@@ -934,7 +935,7 @@
             col = [col] * no_of_coords
         elif len (col) < no_of_coords :
             col = col + [_color_] * (no_of_coords - len (col))
-        if x is None or type (x) == ArrayType and len (shape (x)) == 1 :
+        if x is None or isinstance(x, ndarray) and x.ndim == 1:
             x = [x] * no_of_coords
         elif shape (x) [0] < no_of_coords :
             x = x + [None] * no_of_coords - shape (x) [0]

Modified: trunk/Lib/sandbox/xplt/graph.py
===================================================================
--- trunk/Lib/sandbox/xplt/graph.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/sandbox/xplt/graph.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -1,5 +1,3 @@
-## Automatically adapted for scipy Oct 31, 2005 by
-
 # Copyright (c) 1996, 1997, The Regents of the University of California.
 # All rights reserved.  See Legal.htm for full text and disclaimer.
 
@@ -31,6 +29,7 @@
 from scipy import *
 from numpy.core.umath import *
 from shapetest import *
+from numpy import ndarray
 
 class Graph :
 
@@ -197,7 +196,7 @@
             elif is_scalar (axl) :
                 raise self._AxisSpecError , \
                    "Axis limits must be a point."
-            elif type (axl) == ListType or type (axl) == ArrayType :
+            elif isinstance(axl, list) or isinstance(axl, ndarray):
                 if type (axl [0]) != ListType and type (axl [0]) != ArrayType :
                     self._axis_limits [0] = axl
                 else :

Modified: trunk/Lib/sandbox/xplt/shapetest.py
===================================================================
--- trunk/Lib/sandbox/xplt/shapetest.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/sandbox/xplt/shapetest.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -1,11 +1,10 @@
-## Automatically adapted for scipy Oct 31, 2005 by
-
 # Copyright (c) 1996, 1997, The Regents of the University of California.
 # All rights reserved.  See Legal.htm for full text and disclaimer.
 # I've felt the need for such a test for a long time;
 # this tells you whether an item is a scalar or not.
 
 from types import *
+from numpy import ndarray
 from scipy import *
 
 def is_scalar (x) :
@@ -19,8 +18,8 @@
 # This routine should be able to tell you the size of any object:
 def no_of_dims (x) :
     if x == None : return 0
-    if (type (x) == ArrayType) : return len (x.shape)
-    if (type (x) == ListType or type (x) == TupleType) : return 1
+    if (isinstance(x, ndarray)) : return len (x.shape)
+    if (isinstance(x, list) or isinstance(x, tuple) : return 1
     # I don't know if there are any other possibilities.
     for i in range (10) :
         if is_scalar (x) : return i

Modified: trunk/Lib/stats/tests/test_distributions.py
===================================================================
--- trunk/Lib/stats/tests/test_distributions.py	2006-08-03 23:44:12 UTC (rev 2147)
+++ trunk/Lib/stats/tests/test_distributions.py	2006-08-04 10:13:12 UTC (rev 2148)
@@ -103,7 +103,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.binom.rvs(10, 0.75)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 
@@ -114,7 +114,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.bernoulli.rvs(0.75)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_nbinom(ScipyTestCase):
@@ -124,7 +124,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.nbinom.rvs(10, 0.75)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_geom(ScipyTestCase):
@@ -134,7 +134,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.geom.rvs(0.75)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_hypergeom(ScipyTestCase):
@@ -145,7 +145,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.hypergeom.rvs(20, 3, 10)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_logser(ScipyTestCase):
@@ -155,7 +155,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.logser.rvs(0.75)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_poisson(ScipyTestCase):
@@ -165,7 +165,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.poisson.rvs(0.5)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_zipf(ScipyTestCase):
@@ -175,7 +175,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.zipf.rvs(1.5)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 class test_dlaplace(ScipyTestCase):
@@ -184,7 +184,7 @@
         assert(numpy.shape(vals) == (2, 50))
         assert(vals.dtype.char in numpy.typecodes['AllInteger'])
         val = stats.dlaplace.rvs(1.5)
-        assert(isinstance(val, numpy.ArrayType))
+        assert(isinstance(val, numpy.ndarray))
         assert(val.dtype.char in numpy.typecodes['AllInteger'])
 
 if __name__ == "__main__":



More information about the Scipy-svn mailing list