[h5py] 32/455: Proxy stub

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:14 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 a3172107233d6a30d78ea4ff9f63baf908451a75
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Sun May 25 08:38:14 2008 +0000

    Proxy stub
---
 h5py/h5d.pyx      |   7 +++
 h5py/highlevel.py |   2 +-
 h5py/proxy.py     | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index 07840c8..0a30c9b 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -567,6 +567,13 @@ def py_dtype(hid_t dset_id):
             H5Tclose(type_id)
     return dtype_out
 
+def py_patch(hid_t ds_source, hid_t ds_sink, hid_t space_id):
+    """ (INT ds_source, INT ds_sink, INT space_id)
+
+        Transfer selected elements from one dataset to another.
+        Not yet implemented.
+    """
+    pass
 
 
 
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 4499787..955b38b 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -767,7 +767,7 @@ def slicer(shape, args):
         elif isinstance(arg, slice):
             checkdim(dim)
 
-            # Slice indices() method clips, so do it the hard way...
+            # slice.indices() method clips, so do it the hard way...
 
             # Start
             if arg.start is None:
diff --git a/h5py/proxy.py b/h5py/proxy.py
new file mode 100644
index 0000000..c06e1bb
--- /dev/null
+++ b/h5py/proxy.py
@@ -0,0 +1,161 @@
+import tempfile
+import os
+import numpy
+
+import h5d, h5s, h5t, h5f
+
+class ProxyError(StandardError):
+    pass
+
+class DatasetProxy(object):
+
+    """
+        Thin class which acts as an interface to an HDF5 dataset object.
+
+    """
+    def begin_proxy(self):
+
+        # todo: modify plist to enforce late allocation and no compression
+
+        if self.proxy_id is not None:
+            raise ProxyError("Already proxying.")
+
+        fid = 0
+        sid = 0
+        pid = 0
+        tid = 0
+        proxy_id = 0
+        fname = tempfile.mktemp('.hdf5')
+
+        try:
+            sid = h5d.get_space(self.id)
+            pid = h5g.get_create_plist(self.id)
+            tid = h5g.get_type(self.id)
+
+            fid = h5f.create(fname, h5f.ACC_RDWR)
+            proxy_id = h5d.create(fid, "PROXY", tid, sid, pid)
+        except:
+            if fid != 0:
+                h5f.close(fid)
+            if sid != 0:
+                h5s.close(sid)
+            raise
+        finally:
+            if pid != 0:
+                h5p.close(pid)
+            if tid != 0:
+                h5t.close(tid)
+
+        self.fid = fid
+        self.space_id = sid
+        self.proxy_id = proxy_id
+        self.fname = fname
+
+    def end_proxy(self):
+
+        if self.proxy_id is None:
+            raise ProxyError("Not proxying.")
+
+        h5s.close(self.space_id)
+        h5d.close(self.proxy_id)
+        h5f.close(self.fid)
+        os.unlink(self.fname)
+        self.proxy_id = None
+
+
+    def read(self, start, count, stride=None, **kwds):
+
+        # todo: argument validation
+
+        if self.proxy_id is None:
+            return h5d.py_read_slab(self.id, start, count, stride, **kwds)
+
+        else:
+            mem_space = 0
+            backing_space = 0
+            patch_space = 0
+            tid = 0
+            
+            try:
+                mem_space = h5s.create_simple(count)    
+
+                # Create Numpy array
+                tid = h5d.get_type(self.proxy_id)
+                dtype = h5t.py_h5t_to_dtype(tid, **kwds)
+                arr = numpy.ndarray(count, dtype=dtype)
+
+                patch_space = h5s.copy(self.space_id)
+                backing_space = h5s.copy(self.space_id)
+
+                # What needs to be read from the original dataset.
+                # This is all elements of the new selection which are not
+                # marked as modified.
+                h5s.select_hyperslab(backing_space, start, count, stride, op=h5s.SELECT_NOTA)
+
+                # What needs to be read from the proxy dataset.
+                # This is the intersection of the modified selection and the
+                # requested selection.
+                h5s.select_hyperslab(patch_space, start, count, stride, op=h5s.SELECT_AND)
+
+                # Read from the original dataset.
+                if h5s.get_select_npoints(backing_space) > 0:
+                    h5d.read(self.id, mem_space, backing_space, arr)
+
+                # Read the rest from the proxy dataset.
+                if h5s.get_select_npoints(patch_space) > 0:
+                    h5d.read(self.proxy_id, mem_space, patch_space, arr)
+
+            finally:
+                if mem_space != 0:
+                    h5s.close(mem_space)
+                if backing_space != 0:
+                    h5s.close(backing_space)
+                if patch_space != 0:
+                    h5s.close(patch_space)
+                if tid != 0:
+                    h5t.close(tid)
+
+            return arr
+
+    def write(self, arr, start, stride=None):
+        
+        if self.proxy_id is None:
+            h5d.py_write_slab(self.id, arr, start, stride)
+        
+        else:
+            # We get free argument validation courtesy of this function.
+            h5d.py_write_slab(self.proxy_id, arr, start, stride)
+
+            # Record this section of the dataspace as changed.
+            count = arr.shape
+            h5s.select_hyperslab(self.space_id, start, count, stride, op=h5s.SELECT_OR)
+
+    def commit(self):
+
+        # this will use the yet-unwritten h5d.py_patch function
+        pass
+
+    def rollback(self):
+
+        # fixme: this leaks file space
+        h5s.select_none(self.space_id)
+            
+        
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+            

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