[h5py] 200/455: Selections fixes & tests

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:32 UTC 2015


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

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit 7e1fabd485cdfa3c78adba4b6d2b010ee5b77adb
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Wed Jan 28 01:49:30 2009 +0000

    Selections fixes & tests
---
 h5py/selections.py           | 24 ++++++++++++---------
 h5py/tests/test_highlevel.py | 51 --------------------------------------------
 2 files changed, 14 insertions(+), 61 deletions(-)

diff --git a/h5py/selections.py b/h5py/selections.py
index 4665edb..0743814 100644
--- a/h5py/selections.py
+++ b/h5py/selections.py
@@ -28,7 +28,7 @@ def select(shape, args):
             return sel
 
     for a in args:
-        if not isinstance(a, slice) or a is not Ellipsis:
+        if not isinstance(a, slice) and a != Ellipsis:
             try:
                 int(a)
             except Exception:
@@ -233,18 +233,17 @@ class SimpleSelection(Selection):
         self.mshape = self.shape
 
     def __getitem__(self, args):
+
         if not isinstance(args, tuple):
             args = (args,)
   
-        start, count, step, scalar = _handle_simple(self.shape,args)
-
-        # HDF5 hyperslabs freak out with scalar selections
         if self.shape == ():
-            if count == ():
-                self._id.select_all()
-                return self._id
-            else:
-                raise TypeError("Invalid scalar selection")
+            if len(args) > 0 and args[0] not in (Ellipsis, ()):
+                raise TypeError("Invalid index for scalar dataset (only ..., () allowed)")
+            self._id.select_all()
+            return self
+
+        start, count, step, scalar = _handle_simple(self.shape,args)
 
         self._id.select_hyperslab(start, count, step)
 
@@ -261,6 +260,12 @@ class SimpleSelection(Selection):
         Follows the standard NumPy broadcasting rules against the current
         selection shape (self.mshape).
         """
+        if self.shape == ():
+            if np.product(target_shape) != 1:
+                raise TypeError("Can't broadcast %s to scalar" % target_shape)
+            self._id.select_all()
+            yield self._id
+            return
 
         start, count, step, scalar = self._sel
 
@@ -281,7 +286,6 @@ class SimpleSelection(Selection):
         tshape = tuple(tshape)
 
         chunks = tuple(x/y for x, y in zip(count, tshape))
-
         nchunks = np.product(chunks)
 
         sid = self._id.copy()
diff --git a/h5py/tests/test_highlevel.py b/h5py/tests/test_highlevel.py
index 1e14898..c14df98 100644
--- a/h5py/tests/test_highlevel.py
+++ b/h5py/tests/test_highlevel.py
@@ -411,57 +411,6 @@ class TestDataset(HDF5TestCase):
                 arr = dset[slc]
                 self.assert_(numpy.all(arr == data), "%r \n\n %r" % (arr, data))
 
-    def test_slice_simple(self):
-        """ Test Numpy-style slices """
-
-        srcarr = numpy.arange(10*10*50, dtype='<f4').reshape(10,10,50)
-        srcarr = srcarr + numpy.sin(srcarr)
-
-        def verify_read(dset, data, argtpl):
-            """ Make sure dset and data have identical contents under selection
-            """
-            hresult = dset[argtpl]
-            nresult = data[argtpl]
-
-            if isinstance(nresult, numpy.ndarray):
-                # If the canonical result is an array, compare shapes, dtypes
-                self.assertEqual(hresult.shape, nresult.shape)
-                self.assertEqual(hresult.dtype, nresult.dtype)
-            else:
-                # If it's a scalar, make sure the HDF5 result is also
-                self.assert_(not isinstance(hresult, numpy.ndarray), argtpl)
-
-            # Must be an exact match
-            self.assert_(numpy.all(hresult == nresult))
-
-        def verify(argtpl):
-            """ Test read/write for the given selection """
-
-            dset = self.f.create_dataset('TEST', data=srcarr)
-            verify_read(dset, srcarr, argtpl)
-
-            srcarr[argtpl] = numpy.cos(srcarr[argtpl])
-            dset[argtpl] = srcarr[argtpl]
-            
-            verify_read(dset, srcarr, argtpl)
-        
-            del self.f['TEST']
-
-        s = SliceFreezer()
-        slices = [s[0,0,0], s[0,0,:], s[0,:,0], s[0,:,:]]
-        slices += [s[0:1,:,4:5], s[2:3,0,4:5], s[:,0,0:1], s[0,:,0:1]]
-        slices += [ s[9,9,49], s[9,:,49], s[9,:,:] ]
-        slices += [ s[0, ..., 49], s[...], s[..., 49], s[9,...] ]
-        slices += [ s[0:7:2,0:9:3,15:43:5], s[2:8:2,...] ]
-        slices += [ s[0], s[1], s[9], s[0,0], s[4,5], s[:] ]
-        slices += [ s[3,...], s[3,2,...] ]
-        slices += [ numpy.random.random((10,10,50)) > 0.5 ]  # Truth array
-        slices += [ numpy.zeros((10,10,50), dtype='bool') ]
-        slices += [ s[0, 1, [2,3,6,7]], s[:,[1,2]], s[[1,2]], s[3:7,[1]]]
-
-        for slc in slices:
-            print "    Checking %s on %s" % ((slc,) if not isinstance(slc, numpy.ndarray) else 'ARRAY', srcarr.shape)
-            verify(slc)
 
     def test_slice_names(self):
         """ Test slicing with named fields """

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



More information about the debian-science-commits mailing list