[h5py] 111/455: __init__.py imports and CoordsList unit tests
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:23 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 59c6c4aaea589a31934118f3dcbad1080fcc1911
Author: andrewcollette <andrew.collette at gmail.com>
Date: Wed Aug 27 19:45:00 2008 +0000
__init__.py imports and CoordsList unit tests
---
h5py/__init__.py | 4 ++--
h5py/tests/test_highlevel.py | 27 +++++++++++++++++++++++++++
h5py/utils_hl.py | 12 +++++++++++-
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/h5py/__init__.py b/h5py/__init__.py
index 08030b2..4dd6890 100644
--- a/h5py/__init__.py
+++ b/h5py/__init__.py
@@ -26,10 +26,10 @@ from h5 import _config as config
import utils, h5, h5a, h5d, h5f, h5g, h5i, h5p, h5r, h5s, h5t, h5z, highlevel
import extras
-from highlevel import File, Group, Dataset, Datatype, AttributeManager
+from highlevel import File, Group, Dataset, Datatype, AttributeManager, CoordsList
__doc__ = __doc__ % (h5.version, h5.hdf5_version, h5.api_version)
__all__ = ['h5', 'h5f', 'h5g', 'h5s', 'h5t', 'h5d', 'h5a', 'h5p',
'h5z', 'h5i', 'File', 'Group', 'Dataset',
- 'Datatype', 'AttributeManager']
+ 'Datatype', 'AttributeManager', 'CoordsList']
diff --git a/h5py/tests/test_highlevel.py b/h5py/tests/test_highlevel.py
index e942d05..96bc3e9 100644
--- a/h5py/tests/test_highlevel.py
+++ b/h5py/tests/test_highlevel.py
@@ -332,6 +332,33 @@ class TestDataset(unittest.TestCase):
f.close()
os.unlink(fname)
+ def test_Dataset_coords(self):
+
+ space = (100,100)
+
+ # These need to be increasing to make it easy to compare to the
+ # NumPy reference array, which uses a boolean mask.
+ selections = [0,1,15,101,102, 557, 664, 1024,9999]
+
+ arr = numpy.arange(10000).reshape(space)
+
+ dset = self.f.create_dataset('dset', data=arr)
+
+ # Scalar selections
+ for x in selections:
+ sel = CoordsList(numpy.unravel_index(x,space))
+ self.assertEqual(dset[sel], arr.flat[x])
+ self.assert_(not isinstance(dset[sel], numpy.ndarray))
+
+ # Coordinate list selection
+ sel = CoordsList([numpy.unravel_index(x,space) for x in selections])
+
+ npy_sel = numpy.zeros(space, dtype='bool')
+ for x in selections:
+ npy_sel.flat[x] = True
+
+ self.assert_(numpy.all(dset[sel] == arr[npy_sel]))
+ self.assert_(isinstance(dset[sel], numpy.ndarray))
def test_Dataset_exceptions(self):
# These trigger exceptions in H5Dread
diff --git a/h5py/utils_hl.py b/h5py/utils_hl.py
index 9659d96..269d85a 100644
--- a/h5py/utils_hl.py
+++ b/h5py/utils_hl.py
@@ -68,11 +68,17 @@ class CoordsList(object):
Wrapper class for efficient access to sequences of sparse or
irregular coordinates. Construct from either a single index
(a rank-length sequence of numbers), or a sequence of such
- indices.
+ indices:
+
+ CoordsList( (0,1,4) ) # Single index
+ CoordsList( [ (1,2,3), (7,8,9) ] ) # Multiple indices
"""
def __init__(self, points):
""" Create a new list of explicitly selected points.
+
+ CoordsList( (0,1,4) ) # Single index
+ CoordsList( [ (1,2,3), (7,8,9) ] ) # Multiple indices
"""
try:
@@ -80,6 +86,8 @@ class CoordsList(object):
except ValueError:
raise ValueError("Selection should be an index or a sequence of equal-rank indices")
+ if len(self.coords) == 0:
+ raise ValueError("Selection may not be empty")
def slice_select(space, args):
""" Perform a selection on the given HDF5 dataspace, using a tuple
@@ -119,6 +127,8 @@ def slice_select(space, args):
# Boolean array indexing is handled by discrete element selection
# It never results in a scalar value
indices = numpy.transpose(argval.nonzero())
+ if len(indices) == 0:
+ raise ValueError("Selection may not be empty")
space.select_elements(indices)
return h5s.create_simple((len(indices),)), False
--
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