[python-hdf5storage] 82/84: Made savemat and loadmat use writes and reads instead of write and read to improve performance.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:25:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 0.1.10
in repository python-hdf5storage.

commit f020ad0bb7d287ede631a90126dee4b98e956efe
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Sun Nov 29 16:19:15 2015 +0100

    Made savemat and loadmat use writes and reads instead of write and read to improve performance.
---
 hdf5storage/__init__.py | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/hdf5storage/__init__.py b/hdf5storage/__init__.py
index 7d1c910..d2fb2f8 100644
--- a/hdf5storage/__init__.py
+++ b/hdf5storage/__init__.py
@@ -1646,7 +1646,7 @@ def savemat(file_name, mdict, appendmat=True, format='7.3',
     scipy.io.savemat : SciPy function this one models after and
         dispatches to.
     Options
-    write : Function used to do the actual writing.
+    writes : Function used to do the actual writing.
 
     """
     # If format is a number less than 7.3, the call needs to be
@@ -1669,24 +1669,11 @@ def savemat(file_name, mdict, appendmat=True, format='7.3',
         action_for_matlab_incompatible=action_for_matlab_incompatible, \
         marshaller_collection=marshaller_collection)
 
-    # Write the variables in the dictionary to file one at a time. For
-    # the first one, the file needs to be truncated or truncated if not
-    # valid in a matlab sense if the option/s are given, while not for
-    # the other ones (using a flag for when the first variable has been
-    # added to do this).
-    added_first_variable = False
-    for name in mdict:
-        if not added_first_variable:
-            write(mdict[name], path=name, filename=file_name,
-                  truncate_existing=truncate_existing,
-                  truncate_invalid_matlab=truncate_invalid_matlab,
-                  options=options)
-            added_first_variable = True
-        else:
-            write(mdict[name], path=name, filename=file_name,
-                  truncate_existing=False,
-                  truncate_invalid_matlab=False,
-                  options=options)
+    # Write the variables in the dictionary to file.
+    writes(mdict=mdict, filename=file_name,
+           truncate_existing=truncate_existing,
+           truncate_invalid_matlab=truncate_invalid_matlab,
+           options=options)
 
 
 def loadmat(file_name, mdict=None, appendmat=True,
@@ -1752,7 +1739,7 @@ def loadmat(file_name, mdict=None, appendmat=True,
     scipy.io.loadmat : SciPy function this one models after and
         dispatches to.
     Options
-    read : Function used to do the actual reading.
+    reads : Function used to do the actual reading.
 
     """
     # Will first assume that it is the HDF5 based 7.3 format. If an
@@ -1788,11 +1775,13 @@ def loadmat(file_name, mdict=None, appendmat=True,
                             pass
 
         else:
-            # Extract the desired fields into a dictionary one by one.
+            # Extract the desired fields all together and then pack them
+            # into a dictionary one by one.
+            values = reads(paths=variable_names, filename=filename,
+                           options=options)
             data = dict()
-            for name in variable_names:
-                data[name] = read(path=name, filename=filename,
-                                  options=options)
+            for i, name in enumerate(variable_names):
+                data[name] = values[i]
 
         # Read all the variables, stuff them into mdict, and return it.
         if mdict is None:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-hdf5storage.git



More information about the debian-science-commits mailing list