]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Squeeze the dimensions of FullMatrix in initialize_container()
authorDaniel Garcia-Sanchez <daniel.garcia-sanchez@insp.upmc.fr>
Sat, 20 Oct 2018 12:26:59 +0000 (14:26 +0200)
committerDaniel Garcia-Sanchez <daniel.garcia-sanchez@insp.upmc.fr>
Wed, 9 Jan 2019 18:28:42 +0000 (19:28 +0100)
source/base/hdf5.cc

index 84343ec9c39a1c58e817ac31fca635264a29af7a..cc507af1c47cf332f68de8376c215083be697099 100644 (file)
@@ -328,8 +328,27 @@ namespace HDF5
       Container>::type
     initialize_container(std::vector<hsize_t> dimensions)
     {
-      AssertDimension(dimensions.size(), 2);
-      return Container(dimensions[0], dimensions[1]);
+      // If the rank is higher than 2, then remove single-dimensional entries
+      // from the shape defined by dimensions. This is equivalent to the squeeze
+      // function of python/numpy. For example the following code would convert
+      // the vector {1,3,1,2} to {3,2}
+      std::vector<hsize_t> squeezed_dimensions;
+
+      if (dimensions.size() > 2)
+        {
+          for (auto &&dimension : dimensions)
+            {
+              if (dimension > 1)
+                squeezed_dimensions.push_back(dimension);
+            }
+        }
+      else
+        {
+          squeezed_dimensions = dimensions;
+        }
+
+      AssertDimension(squeezed_dimensions.size(), 2);
+      return Container(squeezed_dimensions[0], squeezed_dimensions[1]);
     }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.