[h5py] 21/455: h5g and h5i additions
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:13 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 680e3ca9fdd6fb97904a3ea9c66cdf6c37023823
Author: andrewcollette <andrew.collette at gmail.com>
Date: Fri May 16 02:56:13 2008 +0000
h5g and h5i additions
---
h5py/errors.py | 2 ++
h5py/h5.pxd | 1 +
h5py/h5d.pxd | 25 ++++++++++++++++----
h5py/h5d.pyx | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
h5py/h5f.pyx | 2 +-
h5py/h5g.pxd | 4 ++++
h5py/h5g.pyx | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-
h5py/h5i.pxd | 9 +++++---
h5py/h5i.pyx | 50 +++++++++++++++++++++++++++++++++++++++-
9 files changed, 216 insertions(+), 12 deletions(-)
diff --git a/h5py/errors.py b/h5py/errors.py
index ba3655e..e2547c6 100644
--- a/h5py/errors.py
+++ b/h5py/errors.py
@@ -55,6 +55,8 @@ class FilterError(H5LibraryError):
class H5TypeError(H5LibraryError):
pass
+class IdentifierError(H5LibraryError):
+ pass
diff --git a/h5py/h5.pxd b/h5py/h5.pxd
index 008da98..ff5f95f 100644
--- a/h5py/h5.pxd
+++ b/h5py/h5.pxd
@@ -27,6 +27,7 @@ cdef extern from "hdf5.h":
# such an unsigned long long type.
ctypedef long long hsize_t
ctypedef signed long long hssize_t
+ ctypedef signed long long haddr_t # I suppose this must be signed as well...
ctypedef struct hvl_t:
size_t len # Length of VL data (in base type units)
diff --git a/h5py/h5d.pxd b/h5py/h5d.pxd
index 46aca3d..a19f91f 100644
--- a/h5py/h5d.pxd
+++ b/h5py/h5d.pxd
@@ -15,7 +15,7 @@
# directory.
from defs_c cimport size_t, time_t
-from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t
+from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t, haddr_t
cdef extern from "hdf5.h":
@@ -59,13 +59,30 @@ cdef extern from "hdf5.h":
herr_t H5Dclose(hid_t dset_id)
hid_t H5Dget_space(hid_t dset_id)
+ herr_t H5Dget_space_status(hid_t dset_id, H5D_space_status_t *status)
hid_t H5Dget_type(hid_t dset_id)
hid_t H5Dget_create_plist(hid_t dataset_id)
+
+ haddr_t H5Dget_offset(hid_t dset_id)
+ hsize_t H5Dget_storage_size(hid_t dset_id)
herr_t H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, void *buf)
- herr_t H5Dwrite(hid_t dset_id, hid_t mem_type, hid_t mem_space, hid_t file_space, hid_t xfer_plist, void* buf)
+ herr_t H5Dwrite(hid_t dset_id, hid_t mem_type, hid_t mem_space, hid_t
+ file_space, hid_t xfer_plist, void* buf)
+
+ herr_t H5Dextend(hid_t dataset_id, hsize_t *size)
+
+ # These are not for the external API
+ herr_t H5Dfill(void *fill, hid_t fill_type_id, void *buf,
+ hid_t buf_type_id, hid_t space_id )
+ herr_t H5Dvlen_get_buf_size(hid_t dset_id, hid_t type_id, hid_t space_id, hsize_t *size)
+ herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist, void *buf)
+ ctypedef herr_t (*H5D_operator_t)(void *elem, hid_t type_id, unsigned ndim,
+ hsize_t *point, void *operator_data)
+ herr_t H5Diterate(void *buf, hid_t type_id, hid_t space_id,
+ H5D_operator_t operator, void* operator_data)
+
+
- herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id,
- void *buf)
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index d87cf6e..2a0861a 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -24,12 +24,12 @@
# Pyrex compile-time imports
from defs_c cimport malloc, free
-from h5 cimport herr_t, hid_t, size_t, hsize_t, htri_t
+from h5 cimport herr_t, hid_t, size_t, hsize_t, htri_t, haddr_t
from h5s cimport H5Sclose, H5S_ALL, H5S_UNLIMITED
from h5t cimport H5Tclose
from h5p cimport H5P_DEFAULT
from numpy cimport ndarray, import_array, PyArray_DATA
-from utils cimport check_numpy_read, check_numpy_write
+from utils cimport check_numpy_read, check_numpy_write, tuple_to_dims
# Runtime imports
import h5
@@ -188,6 +188,40 @@ def write(hid_t dset_id, hid_t mspace_id, hid_t fspace_id, ndarray arr_obj, hid_
if mtype_id:
H5Tclose(mtype_id)
+def extend(hid_t dset_id, object shape):
+ """ (INT dset_id, TUPLE shape)
+
+ Extend the given dataset so it's at least as big as "shape". Note that
+ the ability to extend a dataset depends on how its maximum dimensions
+ were set up when it was created. See the docstring for the API function
+ h5s.create_simple for more information.
+ """
+ cdef hsize_t* dims
+ cdef int rank
+ cdef hid_t space_id
+ cdef herr_t retval
+ space_id = 0
+ dims = NULL
+
+ try:
+ space_id = get_space(dset_id)
+ rank = h5s.get_simple_extent_ndims(space_id)
+ if len(shape) != rank:
+ raise ValueError("Tuple rank must match dataspace rank %d; got %s" % (rank, repr(shape)))
+
+ dims = tuple_to_dims(shape)
+ if dims == NULL:
+ raise ValueError("Invalid tuple supplied: %s" % repr(shape))
+
+ retval = H5Dextend(dset_id, dims)
+ if retval < 0:
+ raise DatasetError("Failed to extend dataset %d" % dset_id)
+ finally:
+ if space_id != 0:
+ H5Sclose(space_id)
+ if dims != NULL:
+ free(dims)
+
# === Dataset inspection ======================================================
def get_space(hid_t dset_id):
@@ -202,6 +236,19 @@ def get_space(hid_t dset_id):
raise DatasetError("Error retrieving space of dataset %d" % dset_id)
return space_id
+def get_space_status(hid_t dset_id):
+ """ (INT dset_id) => INT space_status_code
+
+ Determine if space has been allocated for a dataset. Return value is
+ one of SPACE_STATUS_*.
+ """
+ cdef H5D_space_status_t status
+ cdef herr_t retval
+ retval = H5Dget_space_status(dset_id, &status)
+ if retval < 0:
+ raise DatasetError("Error determining allocation status of dataset %d" % dset_id)
+ return <int>status
+
def get_type(hid_t dset_id):
""" (INT dset_id) => INT type_id
@@ -226,6 +273,28 @@ def get_create_plist(hid_t dset_id):
raise DatasetError("Error retrieving creation property list for dataset %d" % dset_id)
return plist
+def get_offset(hid_t dset_id):
+ """ (INT dset_id) => LONG offset
+
+ Get the offset of this dataset in the file, in bytes.
+ """
+ cdef haddr_t retval
+ retval = H5Dget_offset(dset_id)
+ if retval < 0:
+ raise DatasetError("Error determining file offset of dataset %d" % dset_id)
+ return <long long>retval
+
+def get_storage_size(hid_t dset_id):
+ """ (INT dset_id) => LONG storage_size
+
+ Determine the amount of file space required for a dataset. Note this
+ only counts the space which has actually been allocated; it may even
+ be zero. Because of this, this function will never raise an exception.
+ """
+ cdef hsize_t retval
+ retval = H5Dget_storage_size(dset_id)
+ return retval
+
# === Python extensions =======================================================
def py_create(hid_t parent_id, char* name, object data=None, object dtype=None,
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index 1050c7d..071fe42 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -152,7 +152,7 @@ def mount(hid_t loc_id, char* name, hid_t file_id, hid_t plist_id=H5P_DEFAULT):
def unmount(hid_t loc_id, char* name):
""" (INT loc_id, STRING name)
- Unmount a file, mounted as "name" under group loc_id
+ Unmount a file, mounted as "name" under group loc_id.
"""
cdef herr_t retval
retval = H5Funmount(loc_id, name)
diff --git a/h5py/h5g.pxd b/h5py/h5g.pxd
index 5c3bd96..df9c0fa 100644
--- a/h5py/h5g.pxd
+++ b/h5py/h5g.pxd
@@ -61,4 +61,8 @@ cdef extern from "hdf5.h":
herr_t H5Giterate(hid_t loc_id, char *name, int *idx, H5G_iterate_t operator, operator_data )
herr_t H5Gget_objinfo(hid_t loc_id, char* name, int follow_link, H5G_stat_t *statbuf)
+ herr_t H5Gget_linkval(hid_t loc_id, char *name, size_t size, char *value)
+ herr_t H5Gset_comment(hid_t loc_id, char *name, char *comment )
+ int H5Gget_comment(hid_t loc_id, char *name, size_t bufsize, char *comment )
+
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index e4eb476..233f39a 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -150,7 +150,7 @@ def move(hid_t loc_id, char* current_name, char* new_name, hid_t remote_id=-1):
if retval < 0:
raise GroupError('Failed to move %d=>"%s" to %d=>"%s"' % (loc_id, current_name, remote_id, new_name))
-# === Member inspection and iteration =========================================
+# === Member inspection =======================================================
def get_num_objs(hid_t loc_id):
""" (INT loc_id) => INT number_of_objects
@@ -281,6 +281,66 @@ def iterate(hid_t loc_id, char* name, object func, object data=None, int startid
raise int_tpl[2][0]
raise GroupError("Error occured during iteration")
+def get_linkval(hid_t loc_id, char* name):
+ """ (INT loc_id, STRING name) => STRING link_value
+
+ Retrieve the value of the given symbolic link.
+ """
+ cdef char* value
+ cdef herr_t retval
+ cdef H5G_stat_t statbuf
+ value = NULL
+
+ retval = H5Gget_objinfo(loc_id, name, 0, &statbuf)
+ if retval < 0:
+ raise GroupError('Can\'t stat "%s" under group %d' % (name, loc_id))
+
+ if statbuf.type != H5G_LINK:
+ raise GroupError('"%s" is not a symbolic link (type is %s)' % (name, OBJ_MAPPER[statbuf.type]))
+
+ value = <char*>malloc(statbuf.linklen+1)
+ retval = H5Gget_linkval(loc_id, name, statbuf.linklen+1, value)
+ if retval < 0:
+ free(value)
+ raise GroupError('Failed to determine link value for "%s"' % name)
+
+ pvalue = value
+ free(value)
+ return pvalue
+
+def set_comment(hid_t loc_id, char* name, char* comment):
+ """ (INT loc_id, STRING name, STRING comment)
+
+ Set the comment on a group member.
+ """
+ cdef herr_t retval
+ retval = H5Gset_comment(loc_id, name, comment)
+ if retval < 0:
+ raise GroupError('Failed to set comment on member "%s" of group %d' % (name, loc_id))
+
+def get_comment(hid_t loc_id, char* name):
+ """ (INT loc_id, STRING name) => STRING comment
+
+ Retrieve the comment for a group member.
+ """
+ cdef int cmnt_len
+ cdef char* cmnt
+ cmnt = NULL
+
+ cmnt_len = H5Gget_comment(loc_id, name, 0, NULL)
+ if cmnt_len < 0:
+ raise GroupError('Failed to get comment for member "%s" of group %d' % (name, loc_id))
+
+ cmnt = <char*>malloc(cmnt_len+1)
+ cmnt_len = H5Gget_comment(loc_id, name, cmnt_len+1, cmnt)
+ if cmnt_len < 0:
+ free(cmnt)
+ raise GroupError('Failed to get comment for member "%s" of group %d' % (name, loc_id))
+
+ p_cmnt = cmnt
+ free(cmnt)
+ return p_cmnt
+
# === Custom extensions =======================================================
def py_listnames(hid_t group_id):
diff --git a/h5py/h5i.pxd b/h5py/h5i.pxd
index cb01e1e..6e337c0 100644
--- a/h5py/h5i.pxd
+++ b/h5py/h5i.pxd
@@ -14,7 +14,7 @@
# license is available in the file licenses/hdf5.txt in the distribution
# root directory.
-from defs_c cimport size_t, time_t
+from defs_c cimport size_t, time_t, ssize_t
from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t
cdef extern from "hdf5.h":
@@ -36,5 +36,8 @@ cdef extern from "hdf5.h":
# --- Reflection ------------------------------------------------------------
H5I_type_t H5Iget_type(hid_t obj_id)
- size_t H5Iget_name( hid_t obj_id, char *name, size_t size )
-
+ ssize_t H5Iget_name( hid_t obj_id, char *name, size_t size)
+ hid_t H5Iget_file_id(hid_t obj_id)
+ int H5Idec_ref(hid_t obj_id)
+ int H5Iget_ref(hid_t obj_id)
+ int H5Iinc_ref(hid_t obj_id)
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index 1a80af9..56c78ef 100644
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -18,8 +18,10 @@
from defs_c cimport size_t, malloc, free
from h5 cimport hid_t
+# Runtime imports
import h5
from h5 import DDict
+from errors import IdentifierError
# === Public constants and data structures ====================================
@@ -40,7 +42,7 @@ TYPE_MAPPER = { H5I_BADID: 'BAD ID', H5I_FILE: 'FILE', H5I_GROUP: 'GROUP',
H5I_GENPROP_LST: 'PROPERTY LIST', H5I_DATATYPE: 'DATATYPE' }
TYPE_MAPPER = DDict(TYPE_MAPPER)
-# === Introspection API =======================================================
+# === Identifier API ==========================================================
def get_type(hid_t obj_id):
""" (INT obj_id) => INT type_code
@@ -75,6 +77,52 @@ def get_name(hid_t obj_id):
return retstring
+def get_file_id(hid_t obj_id):
+ """ (INT obj_id) => INT file_id
+
+ Obtain an identifier for the file in which this object resides,
+ re-opening the file if necessary.
+ """
+ cdef hid_t fid
+ fid = H5Iget_file_id(obj_id)
+ if fid < 0:
+ raise IdentifierError("Failed to determine file id for object %d" % obj_id)
+ return fid
+
+def inc_ref(hid_t obj_id):
+ """ (INT obj_id)
+
+ Increment the reference count for the given object.
+ """
+ cdef int retval
+ retval = H5Iinc_ref(obj_id)
+ if retval < 0:
+ raise IdentifierError("Failed to increment reference count of object %d" % obj_id)
+
+def get_ref(hid_t obj_id):
+ """ (INT obj_id)
+
+ Retrieve the reference count for the given object.
+ """
+ cdef int retval
+ retval = H5Iget_ref(obj_id)
+ if retval < 0:
+ raise IdentifierError("Failed to determine reference count of object %d" % obj_id)
+ return retval
+
+def dec_ref(hid_t obj_id):
+ """ (INT obj_id)
+
+ Decrement the reference count for the given object.
+ """
+ cdef int retval
+ retval = H5Idec_ref(obj_id)
+ if retval < 0:
+ raise IdentifierError("Failed to decrement reference count of object %d" % obj_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