[python-hdf5storage] 92/152: Added oned_as option to control whether 1D arrays become row or column vectors when converted to 2D.

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


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

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

commit 4c75ef1fbdd05c5bb48b3da955532f958f304361
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Mon Feb 3 00:15:15 2014 -0500

    Added oned_as option to control whether 1D arrays become row or column vectors when converted to 2D.
---
 hdf5storage/Marshallers.py | 10 ++++++++--
 hdf5storage/__init__.py    | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 2fee50d..86234e6 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -418,10 +418,16 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
             else:
                 data_to_store = new_data
 
-        # Convert scalars to arrays if that option is set.
+        # Convert scalars to arrays if that option is set. For 1d
+        # arrays, an option determines whether they become row or column
+        # vectors.
 
         if options.convert_scalars_to_arrays:
-            data_to_store = np.atleast_2d(data_to_store)
+            new_data = np.atleast_2d(data_to_store)
+            if len(data_to_store.shape) == 1 \
+                    and options.oned_as == 'column':
+                new_data = new_data.T
+            data_to_store = new_data
 
         # Reverse the dimension order if that option is set.
 
diff --git a/hdf5storage/__init__.py b/hdf5storage/__init__.py
index 8b3cec5..81576a4 100644
--- a/hdf5storage/__init__.py
+++ b/hdf5storage/__init__.py
@@ -239,6 +239,8 @@ class Options(object):
         See Attributes.
     group_for_references : str, optional
         See Attributes.
+    oned_as : str, optional
+        See Attributes.
     marshaller_collection : MarshallerCollection, optional
         See Attributes.
 
@@ -255,6 +257,7 @@ class Options(object):
     store_shape_for_empty : bool
     complex_names : tuple of two str
     group_for_references : str
+    oned_as : {'row', 'column'}
     scalar_options : dict
         ``h5py.Group.create_dataset`` options for writing scalars.
     array_options : dict
@@ -274,6 +277,7 @@ class Options(object):
                  store_shape_for_empty=False,
                  complex_names=('r', 'i'),
                  group_for_references="/#refs#",
+                 oned_as='row',
                  marshaller_collection=None):
         # Set the defaults.
 
@@ -287,6 +291,7 @@ class Options(object):
         self._store_shape_for_empty = False
         self._complex_names = ('r', 'i')
         self._group_for_references = "/#refs#"
+        self._oned_as = 'row'
         self._matlab_compatible = True
 
         # Apply all the given options using the setters, making sure to
@@ -303,6 +308,7 @@ class Options(object):
         self.store_shape_for_empty = store_shape_for_empty
         self.complex_names = complex_names
         self.group_for_references = group_for_references
+        self.oned_as = oned_as
         self.matlab_compatible = matlab_compatible
 
         # Set the h5py options to use for writing scalars and arrays to
@@ -426,11 +432,16 @@ class Options(object):
 
         If ``True`` (defaults to ``False`` unless MATLAB compatibility
         is being done), all scalar types are converted to 2D arrays when
-        written to file.
+        written to file. ``oned_as`` determines whether 1D arrays are
+        turned into row or column vectors.
 
         Must be ``True`` if doing MATLAB compatibility. MATLAB can only
         import 2D and higher dimensional arrays.
 
+        See Also
+        --------
+        oned_as
+
         """
         return self._convert_scalars_to_arrays
 
@@ -649,6 +660,29 @@ class Options(object):
         if self._group_for_references != "/#refs#":
             self._matlab_compatible = False
 
+    @property
+    def oned_as(self):
+        """ Vector that 1D arrays become when making everything >= 2D.
+
+        {'row', 'column'}
+
+        When the ``convert_scalars_to_arrays`` option is set (set
+        implicitly by doing MATLAB compatibility), this option controls
+        whether 1D arrays become row vectors or column vectors.
+
+        See Also
+        --------
+        convert_scalars_to_arrays
+
+        """
+        return self._oned_as
+
+    @oned_as.setter
+    def oned_as(self, value):
+        # Check that it is one of the valid values before setting it.
+        if value in ('row', 'column'):
+            self._oned_as = value
+
 
 class MarshallerCollection(object):
     """ Represents, maintains, and retreives a set of marshallers.

-- 
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