[Scipy-svn] r5062 - in trunk/scipy/io/matlab: . tests

scipy-svn@scip... scipy-svn@scip...
Wed Nov 12 01:26:06 CST 2008


Author: matthew.brett@gmail.com
Date: 2008-11-12 01:26:02 -0600 (Wed, 12 Nov 2008)
New Revision: 5062

Modified:
   trunk/scipy/io/matlab/mio.py
   trunk/scipy/io/matlab/mio4.py
   trunk/scipy/io/matlab/mio5.py
   trunk/scipy/io/matlab/miobase.py
   trunk/scipy/io/matlab/tests/test_mio.py
Log:
Removed checked for scipy.sparse and assume instead; change default save format to 5

Modified: trunk/scipy/io/matlab/mio.py
===================================================================
--- trunk/scipy/io/matlab/mio.py	2008-11-12 04:11:34 UTC (rev 5061)
+++ trunk/scipy/io/matlab/mio.py	2008-11-12 07:26:02 UTC (rev 5062)
@@ -116,7 +116,7 @@
     return mdict
 
 @filldoc
-def savemat(file_name, mdict, appendmat=True, format=None):
+def savemat(file_name, mdict, appendmat=True, format='5'):
     """Save a dictionary of names and arrays into the MATLAB-style .mat file.
 
     This saves the arrayobjects in the given dictionary to a matlab
@@ -128,15 +128,10 @@
     m_dict : dict
         dictionary from which to save matfile variables
     %(append_arg)s
-    format : {'4', '5'} string, optional
-        '4' for matlab 4 mat files, '5' for matlab 5 (up to matlab
-        7.2)
+    format : {'5', '4'} string, optional
+        '5' for matlab 5 (up to matlab 7.2)
+        '4' for matlab 4 mat files, 
     """
-    if format is None:
-        warnings.warn(
-            "Using default format '4'. Default will change to '5' in future versions of scipy",
-            FutureWarning, stacklevel=2)
-        format = '4'
     file_is_string = isinstance(file_name, basestring)
     if file_is_string:
         if appendmat and file_name[-4:] != ".mat":

Modified: trunk/scipy/io/matlab/mio4.py
===================================================================
--- trunk/scipy/io/matlab/mio4.py	2008-11-12 04:11:34 UTC (rev 5061)
+++ trunk/scipy/io/matlab/mio4.py	2008-11-12 07:26:02 UTC (rev 5062)
@@ -4,9 +4,12 @@
 
 import numpy as np
 
+import scipy.sparse
+
 from miobase import MatFileReader, MatArrayReader, MatMatrixGetter, \
-     MatFileWriter, MatStreamWriter, spsparse, filldoc
+     MatFileWriter, MatStreamWriter, filldoc
 
+
 SYS_LITTLE_ENDIAN = sys.byteorder == 'little'
 
 miDOUBLE = 0
@@ -179,9 +182,7 @@
         else:
             V = np.ascontiguousarray(tmp[:,2],dtype='complex')
             V.imag = tmp[:,3]
-        if spsparse:
-            return spsparse.coo_matrix((V,(I,J)), dims)
-        return (dims, I, J, V)
+        return scipy.sparse.coo_matrix((V,(I,J)), dims)
 
 
 class MatFile4Reader(MatFileReader):
@@ -324,9 +325,8 @@
     arr         - array to write
     name        - name in matlab (TM) workspace
     '''
-    if spsparse:
-        if spsparse.issparse(arr):
-            return Mat4SparseWriter(stream, arr, name)
+    if scipy.sparse.issparse(arr):
+        return Mat4SparseWriter(stream, arr, name)
     arr = np.array(arr)
     dtt = arr.dtype.type
     if dtt is np.object_:

Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2008-11-12 04:11:34 UTC (rev 5061)
+++ trunk/scipy/io/matlab/mio5.py	2008-11-12 07:26:02 UTC (rev 5062)
@@ -12,8 +12,10 @@
 
 import numpy as np
 
+import scipy.sparse
+
 from miobase import MatFileReader, MatArrayReader, MatMatrixGetter, \
-     MatFileWriter, MatStreamWriter, spsparse, filldoc
+     MatFileWriter, MatStreamWriter, filldoc
 
 miINT8 = 1
 miUINT8 = 2
@@ -173,13 +175,8 @@
     pass
 
 
-class MatlabFunction(np.ndarray):
-    ''' class to signal this is a matlab function '''
-    def __new__(cls, input_array):
-        return np.asarray(input_array).view(cls)
-
-
 class MatlabObject(np.ndarray):
+    ''' ndarray Subclass to contain matlab object '''
     def __new__(cls, input_array, classname=None):
         # Input array is an already formed ndarray instance
         # We first cast to be our class type
@@ -195,6 +192,12 @@
         # We do not need to return anything
 
 
+class MatlabFunction(np.ndarray):
+    ''' Subclass to signal this is a matlab function '''
+    def __new__(cls, input_array):
+        obj = np.asarray(input_array).view(cls)
+    
+
 class Mat5ArrayReader(MatArrayReader):
     ''' Class to get Mat5 arrays
 
@@ -412,12 +415,10 @@
         nnz = indptr[-1]
         rowind = rowind[:nnz]
         data   = data[:nnz]
-        if spsparse:
-            return spsparse.csc_matrix((data,rowind,indptr), shape=(M,N))
-        else:
-            return ((M,N), data, rowind, indptr)
+        return scipy.sparse.csc_matrix(
+            (data,rowind,indptr),
+            shape=(M,N))
 
-
 class Mat5CharMatrixGetter(Mat5MatrixGetter):
     def get_raw_array(self):
         res = self.read_element()
@@ -850,9 +851,8 @@
             whether variable will be global on load into matlab
         '''
         # First check if these are sparse
-        if spsparse:
-            if spsparse.issparse(arr):
-                return Mat5SparseWriter(self.stream, arr, name, is_global)
+        if scipy.sparse.issparse(arr):
+            return Mat5SparseWriter(self.stream, arr, name, is_global)
         # Next try and convert to an array
         narr = np.asanyarray(arr)
         if narr.dtype.type in (np.object, np.object_) and \

Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py	2008-11-12 04:11:34 UTC (rev 5061)
+++ trunk/scipy/io/matlab/miobase.py	2008-11-12 07:26:02 UTC (rev 5062)
@@ -8,12 +8,6 @@
 
 import byteordercodes as boc
 
-# sparse module if available
-try:
-    import scipy.sparse as spsparse
-except ImportError:
-    spsparse = None
-
 def filldoc(func):
     ''' Decorator to put recurring doc elements into mio doc strings '''
     doc_dict = \

Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py	2008-11-12 04:11:34 UTC (rev 5061)
+++ trunk/scipy/io/matlab/tests/test_mio.py	2008-11-12 07:26:02 UTC (rev 5062)
@@ -267,6 +267,7 @@
         assert files, "No files for test %s using filter %s" % (name, filt)
         yield _load_check_case, name, files, expected
 
+
 # generator for round trip tests
 def test_round_trip():
     for case in case_table4 + case_table5_rt:
@@ -275,6 +276,7 @@
         format = case in case_table4 and '4' or '5'
         yield _rt_check_case, name, expected, format
 
+
 def test_gzip_simple():
     xdense = np.zeros((20,20))
     xdense[2,3]=2.3
@@ -329,13 +331,10 @@
     yield (lambda a, k: assert_raises(*a, **k), 
           (DeprecationWarning, loadmat, fname), 
           {'struct_as_record':True, 'basename':'raw'})
-    # Test warning for default format change
-    savemat(StringIO(), {}, False, '4')
-    savemat(StringIO(), {}, False, '5')
-    yield assert_raises, FutureWarning, savemat, StringIO(), {}
     warnings.resetwarnings()
 
 
 def test_regression_653():
     """Regression test for #653."""
     assert_raises(TypeError, savemat, StringIO(), {'d':{1:2}}, format='5')
+



More information about the Scipy-svn mailing list