[python-hdf5storage] 60/152: Fixed bug of scalar numpy complex types being turned into arrays when doing write readback.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:24:34 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 0923f91a0c062a8643a636d2d399b8b778fbf69c
Author: Freja Nordsiek <fnordsie at gmail.com>
Date:   Wed Jan 29 23:56:29 2014 -0500

    Fixed bug of scalar numpy complex types being turned into arrays when doing write readback.
---
 hdf5storage/Marshallers.py | 10 +++++-----
 hdf5storage/utilities.py   | 14 +++++---------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/hdf5storage/Marshallers.py b/hdf5storage/Marshallers.py
index 5cd012f..6019177 100644
--- a/hdf5storage/Marshallers.py
+++ b/hdf5storage/Marshallers.py
@@ -638,6 +638,11 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
                         options.reverse_dimension_order:
                     data = data.T
 
+            # If it is a complex type, then it needs to be decoded
+            # properly.
+            if underlying_type.startswith('complex'):
+                data = decode_complex(data)
+
             # If MATLAB attributes are present or the reverse dimension
             # order option was given, the dimension order needs to be
             # reversed. This needs to be done before any reshaping as
@@ -653,11 +658,6 @@ class NumpyScalarArrayMarshaller(TypeMarshaller):
                     and np.prod(shape) == np.prod(data.shape):
                 data = data.reshape(tuple(shape))
 
-            # If it is a complex type, then it needs to be decoded
-            # properly.
-            if underlying_type.startswith('complex'):
-                data = decode_complex(data)
-
             # If its underlying type is 'bool' but it is something else,
             # then it needs to be converted (means it was written with
             # the convert_bools_to_uint8 option).
diff --git a/hdf5storage/utilities.py b/hdf5storage/utilities.py
index 5a880f6..7894fe6 100644
--- a/hdf5storage/utilities.py
+++ b/hdf5storage/utilities.py
@@ -322,15 +322,11 @@ def encode_complex(data, complex_names):
         dtype_name = 'float' + str(int(float(dtype_name[7:])/2))
 
     # Create the new version of the data with the right field names for
-    # the real and complex parts and the right shape.
-    new_data = np.ndarray(shape=data.shape,
-                          dtype=[(complex_names[0], dtype_name),
-                          (complex_names[1], dtype_name)])
-
-    # Set the real and complex parts and return it.
-    new_data[complex_names[0]] = np.real(data)
-    new_data[complex_names[1]] = np.imag(data)
-    return new_data
+    # the real and complex parts. This is easy to do with putting the
+    # right detype in the view function.
+    dt = np.dtype([(complex_names[0], dtype_name),
+                   (complex_names[1], dtype_name)])
+    return data.view(dt).copy()
 
 
 def get_attribute(target, name):

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