[h5py] 53/455: More OO work; stupid new Pyrex auto-imports fail due to circular references.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:16 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 8e85709f91d3d9fdfc61a780d75d847ffe5662b3
Author: andrewcollette <andrew.collette at gmail.com>
Date: Tue Jun 17 04:11:14 2008 +0000
More OO work; stupid new Pyrex auto-imports fail due to circular references.
---
h5py/h5.pxd | 25 ++-
h5py/h5.pyx | 18 +-
h5py/h5a.pxd | 2 +-
h5py/h5a.pyx | 3 +-
h5py/h5d.pxd | 9 +-
h5py/h5d.pyx | 11 +-
h5py/h5f.pxd | 2 +-
h5py/h5f.pyx | 2 +-
h5py/h5g.pxd | 2 +-
h5py/h5g.pyx | 2 +-
h5py/h5i.pxd | 2 +
h5py/h5i.pyx | 2 -
h5py/h5p.pxd | 72 ++++++-
h5py/h5p.pyx | 73 ++++---
h5py/h5r.pxd | 3 +-
h5py/h5r.pyx | 3 +-
h5py/h5s.pxd | 2 +-
h5py/h5s.pyx | 6 +-
h5py/h5t.pxd | 5 +-
h5py/h5t.pyx | 571 ++++++++----------------------------------------------
h5py/std_defs.pxi | 1 -
21 files changed, 251 insertions(+), 565 deletions(-)
diff --git a/h5py/h5.pxd b/h5py/h5.pxd
index 2477896..1526609 100644
--- a/h5py/h5.pxd
+++ b/h5py/h5.pxd
@@ -14,7 +14,7 @@
# license is available at licenses/pytables.txt, in the distribution root
# directory.
-from defs_c cimport size_t
+from defs_c cimport size_t, ssize_t
# Common structs and types from HDF5
cdef extern from "hdf5.h":
@@ -38,6 +38,29 @@ cdef extern from "hdf5.h":
herr_t H5open() except *
herr_t H5close() except *
+ # reflection
+ ctypedef enum H5I_type_t:
+ H5I_BADID = -1, # /*invalid Group */
+ H5I_FILE = 1, # /*group ID for File objects */
+ H5I_GROUP, # /*group ID for Group objects */
+ H5I_DATATYPE, # /*group ID for Datatype objects */
+ H5I_DATASPACE, # /*group ID for Dataspace objects */
+ H5I_DATASET, # /*group ID for Dataset objects */
+ H5I_ATTR, # /*group ID for Attribute objects */
+ H5I_REFERENCE, # /*group ID for Reference objects */
+ H5I_VFL, # /*group ID for virtual file layer */
+ H5I_GENPROP_CLS, # /*group ID for generic property list classes */
+ H5I_GENPROP_LST, # /*group ID for generic property lists */
+ H5I_NGROUPS # /*number of valid groups, MUST BE LAST! */
+
+ # --- Reflection ------------------------------------------------------------
+ H5I_type_t H5Iget_type(hid_t obj_id) except *
+ ssize_t H5Iget_name( hid_t obj_id, char *name, size_t size) except *
+ hid_t H5Iget_file_id(hid_t obj_id) except *
+ int H5Idec_ref(hid_t obj_id) except *
+ int H5Iget_ref(hid_t obj_id) except *
+ int H5Iinc_ref(hid_t obj_id) except *
+
# --- Version functions -----------------------------------------------------
herr_t H5get_libversion(unsigned *majnum, unsigned *minnum,
unsigned *relnum ) except *
diff --git a/h5py/h5.pyx b/h5py/h5.pyx
index 14cbd4d..a0aa1ca 100644
--- a/h5py/h5.pyx
+++ b/h5py/h5.pyx
@@ -19,18 +19,7 @@
- API_VERS, API_VERS_TPL: API version (1.6 or 1.8) used to compile h5py.
"""
-from h5e cimport _enable_exceptions
-from h5i cimport H5Iinc_ref, H5Idec_ref, H5Iget_ref, H5Iget_type, H5I_BADID
-# === Library init ============================================================
-
-cdef int import_hdf5() except -1:
- if H5open() < 0:
- raise RuntimeError("Failed to initialize the HDF5 library.")
- _enable_exceptions()
- return 0
-
-import_hdf5()
# === API =====================================================================
@@ -116,6 +105,13 @@ cdef class LockableID(ObjectID):
return "%d [%s] (%s) %s" % (self.id, ref, lstr, self.__class__.__name__)
+# === Library init ============================================================
+
+cdef int import_hdf5() except -1:
+ if H5open() < 0:
+ raise RuntimeError("Failed to initialize the HDF5 library.")
+ _enable_exceptions()
+ return 0
diff --git a/h5py/h5a.pxd b/h5py/h5a.pxd
index 20961e8..5c90aab 100644
--- a/h5py/h5a.pxd
+++ b/h5py/h5a.pxd
@@ -16,9 +16,9 @@
include "std_defs.pxi"
from h5 cimport ObjectID
-
cdef class AttrID(ObjectID):
pass
+from numpy cimport class ndarray
cdef extern from "hdf5.h":
diff --git a/h5py/h5a.pyx b/h5py/h5a.pyx
index fe79636..32f623c 100644
--- a/h5py/h5a.pyx
+++ b/h5py/h5a.pyx
@@ -38,8 +38,7 @@ def create(ObjectID loc_id not None, char* name, TypeID type_id not None,
=> INT attr_id
Create a new attribute attached to a parent object, specifiying an
- HDF5 datatype and dataspace. For a friendlier version of this function
- try py_create().
+ HDF5 datatype and dataspace.
"""
return AttrID(H5Acreate(loc_id.id, name, type_id.id, space_id.id, H5P_DEFAULT))
diff --git a/h5py/h5d.pxd b/h5py/h5d.pxd
index 55e9db6..1647ca9 100644
--- a/h5py/h5d.pxd
+++ b/h5py/h5d.pxd
@@ -15,11 +15,18 @@
# directory.
include "std_defs.pxi"
-from h5 cimport ObjectID
+from h5 cimport class ObjectID
cdef class DatasetID(ObjectID):
pass
+from h5t cimport class TypeID
+from h5s cimport class SpaceID
+from h5p cimport class PropID, pdefault
+from numpy cimport class ndarray
+
+
+
cdef extern from "hdf5.h":
# HDF5 layouts
diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index aeae3ed..fa80b19 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -23,15 +23,12 @@
"""
# Pyrex compile-time imports
-from h5t cimport TypeID
-from h5s cimport SpaceID
-from h5p cimport PropID, pdefault
from h5s cimport H5S_ALL, H5S_UNLIMITED, H5S_SCALAR, H5S_SIMPLE, \
H5Sget_simple_extent_type, H5Sclose, H5Sselect_all, \
H5Sget_simple_extent_ndims, H5Sget_select_npoints
from h5t cimport PY_H5Tclose, H5Tget_size
from h5p cimport H5P_DEFAULT, H5Pclose
-from numpy cimport import_array, ndarray, PyArray_DATA
+from numpy cimport import_array, PyArray_DATA
from utils cimport check_numpy_read, check_numpy_write, \
convert_tuple, \
emalloc, efree
@@ -72,7 +69,7 @@ FILL_VALUE_USER_DEFINED = H5D_FILL_VALUE_USER_DEFINED
def create(ObjectID loc_id not None, char* name, TypeID type_id not None,
SpaceID space_id not None, PropID plist=None):
""" (ObjectID loc_id, STRING name, TypeID type_id, SpaceID space_id,
- PropID plist=None )
+ PropID plist=None )
=> DatasetID
Create a new dataset under an HDF5 file or group id. Keyword plist
@@ -146,7 +143,7 @@ cdef class DatasetID(ObjectID):
For a friendlier version of this function, try py_read_slab().
"""
- cdef hid_t mtype_id
+ cdef TypeID mtype_id
cdef hid_t plist_id
plist_id = pdefault(plist)
mtype_id = 0
@@ -174,7 +171,7 @@ cdef class DatasetID(ObjectID):
For a friendlier version of this function, try py_write_slab()
"""
- cdef hid_t mtype_id
+ cdef TypeID mtype_id
cdef hid_t plist_id
plist_id = pdefault(plist)
mtype_id = 0
diff --git a/h5py/h5f.pxd b/h5py/h5f.pxd
index 9e3606d..2d88423 100644
--- a/h5py/h5f.pxd
+++ b/h5py/h5f.pxd
@@ -15,7 +15,7 @@
# directory.
include "std_defs.pxi"
-from h5 cimport ObjectID
+from h5 cimport class ObjectID
cdef class FileID(ObjectID):
pass
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index 85d9740..123b112 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -91,7 +91,7 @@ def is_hdf5(char* name):
return pybool(H5Fis_hdf5(name))
def mount(ObjectID loc_id not None, char* name, FileID file_id not None,
- PropID mountlist=None)
+ PropID mountlist=None):
""" (ObjectID loc_id, STRING name, FileID file_id, PropID mountlist=None)
Mount an open file as "name" under group loc_id. If present, mountlist
diff --git a/h5py/h5g.pxd b/h5py/h5g.pxd
index dd736a2..6392348 100644
--- a/h5py/h5g.pxd
+++ b/h5py/h5g.pxd
@@ -15,7 +15,7 @@
# directory.
include "std_defs.pxi"
-from h5 cimport ObjectID
+from h5 cimport class ObjectID
cdef class GroupID(ObjectID):
pass
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index ff3f745..082d135 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -285,7 +285,7 @@ cdef class GroupID(ObjectID):
Set the comment on a group member.
"""
- H5Gset_comment(self.id name, comment)
+ H5Gset_comment(self.id, name, comment)
def get_comment(self, char* name):
diff --git a/h5py/h5i.pxd b/h5py/h5i.pxd
index 024641b..ad142d7 100644
--- a/h5py/h5i.pxd
+++ b/h5py/h5i.pxd
@@ -15,6 +15,8 @@
# root directory.
include "std_defs.pxi"
+from h5 cimport class ObjectID
+from h5f cimport class FileID
cdef extern from "hdf5.h":
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index 854d006..a10f03d 100644
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -15,8 +15,6 @@
"""
# Pyrex compile-time imports
-from h5 cimport ObjectID
-from h5f cimport FileID
from utils cimport emalloc, efree
# Runtime imports
diff --git a/h5py/h5p.pxd b/h5py/h5p.pxd
index e6d6712..445ccf5 100644
--- a/h5py/h5p.pxd
+++ b/h5py/h5p.pxd
@@ -15,40 +15,102 @@
# directory.
include "std_defs.pxi"
-from h5 cimport ObjectID
+from h5 cimport class ObjectID
cdef class PropID(ObjectID):
+ """ Base class for all property lists """
pass
cdef class PropClassID(PropID):
+ """ Represents an HDF5 property list class """
+ pass
+
+cdef class PropImmutableClassID(PropClassID):
+ """ Special case of an HDF5 property list class, which isn't
+ automatically closed. These are used for the built-in
+ classes.
+ """
pass
cdef class PropInstanceID(PropID):
+ """ Represents an instance of a property list class (i.e. an actual list
+ which can be passed on to other API functions).
+ """
pass
cdef class PropDCID(PropInstanceID):
+ """ Dataset creation property list """
pass
cdef class PropDXID(PropInstanceID):
+ """ Dataset transfer property list """
pass
cdef class PropFCID(PropInstanceID):
+ """ File creation property list """
pass
cdef class PropFAID(PropInstanceID):
+ """ File access property list """
pass
cdef class PropMID(PropInstanceID):
+ """ Mount property list """
pass
-from h5d cimport H5D_layout_t, H5D_fill_value_t, H5D_fill_time_t, H5D_alloc_time_t
-from h5z cimport H5Z_filter_t, H5Z_EDC_t
-from h5f cimport H5F_close_degree_t
+cdef hid_t pdefault(PropID pid)
cdef extern from "hdf5.h":
int H5P_DEFAULT
+ ctypedef int H5Z_filter_t
+
+ # HDF5 layouts
+ ctypedef enum H5D_layout_t:
+ H5D_LAYOUT_ERROR = -1,
+ H5D_COMPACT = 0, # raw data is very small
+ H5D_CONTIGUOUS = 1, # the default
+ H5D_CHUNKED = 2, # slow and fancy
+ H5D_NLAYOUTS = 3 # this one must be last!
+
+ ctypedef enum H5D_alloc_time_t:
+ H5D_ALLOC_TIME_ERROR =-1,
+ H5D_ALLOC_TIME_DEFAULT =0,
+ H5D_ALLOC_TIME_EARLY =1,
+ H5D_ALLOC_TIME_LATE =2,
+ H5D_ALLOC_TIME_INCR =3
+
+ ctypedef enum H5D_space_status_t:
+ H5D_SPACE_STATUS_ERROR =-1,
+ H5D_SPACE_STATUS_NOT_ALLOCATED =0,
+ H5D_SPACE_STATUS_PART_ALLOCATED =1,
+ H5D_SPACE_STATUS_ALLOCATED =2
+
+ ctypedef enum H5D_fill_time_t:
+ H5D_FILL_TIME_ERROR =-1,
+ H5D_FILL_TIME_ALLOC =0,
+ H5D_FILL_TIME_NEVER =1,
+ H5D_FILL_TIME_IFSET =2
+
+ ctypedef enum H5D_fill_value_t:
+ H5D_FILL_VALUE_ERROR =-1,
+ H5D_FILL_VALUE_UNDEFINED =0,
+ H5D_FILL_VALUE_DEFAULT =1,
+ H5D_FILL_VALUE_USER_DEFINED =2
+
+ cdef enum H5Z_EDC_t:
+ H5Z_ERROR_EDC = -1,
+ H5Z_DISABLE_EDC = 0,
+ H5Z_ENABLE_EDC = 1,
+ H5Z_NO_EDC = 2
+
+ cdef enum H5F_close_degree_t:
+ H5F_CLOSE_WEAK = 0,
+ H5F_CLOSE_SEMI = 1,
+ H5F_CLOSE_STRONG = 2,
+ H5F_CLOSE_DEFAULT = 3
+
# Property list classes
hid_t H5P_NO_CLASS
hid_t H5P_FILE_CREATE
@@ -89,7 +151,7 @@ cdef extern from "hdf5.h":
herr_t H5Pset_fapl_log(hid_t fapl_id, char *logfile, unsigned int flags, size_t buf_size) except *
# Dataset creation properties
- herr_t H5Pset_layout(hid_t plist, H5D_layout_t layout) except *
+ herr_t H5Pset_layout(hid_t plist, int layout) except *
H5D_layout_t H5Pget_layout(hid_t plist) except *
herr_t H5Pset_chunk(hid_t plist, int ndims, hsize_t * dim) except *
int H5Pget_chunk(hid_t plist, int max_ndims, hsize_t * dims ) except *
diff --git a/h5py/h5p.pyx b/h5py/h5p.pyx
index 2faf9fa..f69244c 100644
--- a/h5py/h5p.pyx
+++ b/h5py/h5p.pyx
@@ -30,12 +30,12 @@ from h5 import DDict
# === Public constants and data structures ====================================
# Property list classes
-NO_CLASS = PropClassID(H5P_NO_CLASS)
-FILE_CREATE = PropClassID(H5P_FILE_CREATE)
-FILE_ACCESS = PropClassID(H5P_FILE_ACCESS)
-DATASET_CREATE = PropClassID(H5P_DATASET_CREATE)
-DATASET_XFER = PropClassID(H5P_DATASET_XFER)
-MOUNT = PropClassID(H5P_MOUNT)
+NO_CLASS = PropImmutableClassID(H5P_NO_CLASS)
+FILE_CREATE = PropImmutableClassID(H5P_FILE_CREATE)
+FILE_ACCESS = PropImmutableClassID(H5P_FILE_ACCESS)
+DATASET_CREATE = PropImmutableClassID(H5P_DATASET_CREATE)
+DATASET_XFER = PropImmutableClassID(H5P_DATASET_XFER)
+MOUNT = PropImmutableClassID(H5P_MOUNT)
DEFAULT = PropID(H5P_DEFAULT)
@@ -45,7 +45,39 @@ _classmapper = { H5P_FILE_CREATE: PropFCID,
H5P_DATASET_XFER: PropDXID,
H5P_MOUNT: PropMID }
-# === Generic property list operations ========================================
+# === C API and extension types ===============================================
+
+cdef hid_t pdefault(PropID pid):
+
+ if pid is None:
+ return <hid_t>H5P_DEFAULT
+
+ return pid.id
+
+cdef class PropID(ObjectID):
+
+ """ Base class for all operations which are valid on both property list
+ instances and classes.
+ """
+ pass
+
+# === Property list HDF5 classes ==============================================
+
+cdef class PropClassID(PropID):
+ pass
+
+cdef class PropImmutableClassID(PropClassID):
+
+ """
+ Represents property list class objects.
+ These are not automatically closed.
+ This is a hack until custom classes can be implemented.
+ """
+
+ def __dealloc__(self):
+ pass
+
+# === Property list HDF5 instances ============================================
def create(PropClassID cls not None):
""" (PropClassID cls) => PropID
@@ -64,21 +96,10 @@ def create(PropClassID cls not None):
return type_(H5Pcreate(cls.id))
-cdef class PropClassID(PropID):
-
- """
- Represents property list class objects.
- These are not automatically closed.
- This is a hack until custom classes can be implemented.
- """
-
- def __dealloc__(self):
- pass
-
-cdef class PropInstanceID(ObjectID):
+cdef class PropInstanceID(PropID):
"""
- Base class for property list objects
+ Base class for property list instance objects
"""
def copy(self):
@@ -91,7 +112,7 @@ cdef class PropInstanceID(ObjectID):
def close(self):
H5Pclose(self.id)
- def get_class():
+ def get_class(self):
""" () => PropClassID
Determine the class of a property list object.
@@ -113,7 +134,7 @@ cdef class PropFCID(PropInstanceID):
Represents a file creation property list
"""
- def get_version():
+ def get_version(self):
""" () => TUPLE version_info
Determine version information of various file attributes.
@@ -152,7 +173,7 @@ cdef class PropFCID(PropInstanceID):
return size
def set_sizes(self, size_t addr, size_t size):
- """ (INT addr, INT size)
+ """ (UINT addr, UINT size)
Set the addressing offsets and lengths for objects
in an HDF5 file, in bytes.
@@ -223,7 +244,7 @@ cdef class PropDCID(PropInstanceID):
* h5d.CONTIGUOUS
* h5d.CHUNKED
"""
- H5Pset_layout(self.id, <H5D_layout_t>layout_code)
+ H5Pset_layout(self.id, layout_code)
def get_layout(self):
""" () => INT layout_code [Dataset creation]
@@ -301,7 +322,7 @@ cdef class PropDCID(PropInstanceID):
H5Pset_shuffle(self.id)
def set_szip(self, unsigned int options, unsigned int pixels_per_block):
- """ (INT plist, UINT options, UINT pixels_per_block) [Dataset creation]
+ """ (UINT options, UINT pixels_per_block) [Dataset creation]
Enable SZIP compression. See the HDF5 docs for argument meanings, and
general restrictions on use of the SZIP format.
@@ -309,7 +330,7 @@ cdef class PropDCID(PropInstanceID):
H5Pset_szip(self.id, options, pixels_per_block)
def remove_filter(self, int filter_class):
- """ (INT plist, INT filter_class) [Dataset creation]
+ """ (INT filter_class) [Dataset creation]
Remove a filter from the pipeline. The class code is one of
h5z.FILTER_*.
diff --git a/h5py/h5r.pxd b/h5py/h5r.pxd
index 7a50f1d..79cd722 100644
--- a/h5py/h5r.pxd
+++ b/h5py/h5r.pxd
@@ -11,7 +11,8 @@
#-
include "std_defs.pxi"
-
+from h5 cimport class ObjectID
+from h5s cimport class SpaceID
from h5g cimport H5G_obj_t
cdef extern from "hdf5.h":
diff --git a/h5py/h5r.pyx b/h5py/h5r.pyx
index 93608fb..e239b2f 100644
--- a/h5py/h5r.pyx
+++ b/h5py/h5r.pyx
@@ -15,7 +15,6 @@
"""
# Pyrex compile-time imports
-from h5 cimport ObjectID
from h5g cimport H5G_obj_t
# Runtime imports
@@ -105,7 +104,7 @@ def get_region(ObjectID dataset_id not None, Reference ref):
"""
return H5Rget_region(dataset_id.id, <H5R_type_t>ref.typecode, &ref.ref)
-def get_obj_type(Object ID ds_id not None, Reference ref):
+def get_obj_type(ObjectID ds_id not None, Reference ref):
""" (ObjectID ds_id, Reference ref) => INT obj_code
Determine what type of object an object reference points to. The
diff --git a/h5py/h5s.pxd b/h5py/h5s.pxd
index dbb2f5d..6476555 100644
--- a/h5py/h5s.pxd
+++ b/h5py/h5s.pxd
@@ -19,7 +19,7 @@
# root directory.
include "std_defs.pxi"
-from h5s cimport ObjectID
+from h5 cimport class ObjectID
cdef class SpaceID(ObjectID):
pass
diff --git a/h5py/h5s.pyx b/h5py/h5s.pyx
index 6f4ad93..5b9b9df 100644
--- a/h5py/h5s.pyx
+++ b/h5py/h5s.pyx
@@ -186,7 +186,7 @@ cdef class SpaceID(ObjectID):
finally:
efree(dims)
- def get_simple_extent_npoints(self)):
+ def get_simple_extent_npoints(self):
""" () => LONG npoints
Determine the total number of elements in a dataspace.
@@ -202,7 +202,7 @@ cdef class SpaceID(ObjectID):
# === Extents =================================================================
- def extent_copy(self, SpaceID source_id not None)
+ def extent_copy(self, SpaceID source_id not None):
""" (SpaceID source_id)
Replace this dataspace's extent with another's, changing its
@@ -454,7 +454,7 @@ cdef class SpaceID(ObjectID):
finally:
efree(buf)
- return outlist
+ return outlist
def select_hyperslab(self, object start, object count,
diff --git a/h5py/h5t.pxd b/h5py/h5t.pxd
index 63b0825..96e2039 100644
--- a/h5py/h5t.pxd
+++ b/h5py/h5t.pxd
@@ -15,11 +15,12 @@
# directory.
include "std_defs.pxi"
-from h5 cimport LockableID
+from h5 cimport class ObjectID, class LockableID
cdef class TypeID(LockableID):
- pass
+ cdef int enum_convert(self, long long *buf, int reverse) except -1
+
cdef extern from "hdf5.h":
cdef enum:
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index ecf09a1..7368060 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -274,7 +274,7 @@ cdef class TypeID(LockableID):
H5Tlock(self.id)
self._locked = 1
- def get_class():
+ def get_class(self):
""" () => INT classcode
Determine the datatype's class code.
@@ -306,7 +306,7 @@ cdef class TypeID(LockableID):
These determine which direction the list of native datatypes is
searched; see the HDF5 docs for a definitive list.
- The returned datatype is always an unlocked copy one of NATIVE_*.
+ The returned datatype is always an unlocked copy of one of NATIVE_*.
"""
return TypeID(H5Tget_native_type(self.id, <H5T_direction_t>direction))
@@ -335,7 +335,7 @@ cdef class TypeID(LockableID):
"""
H5Tset_size(self.id, size)
- def get_order(self)
+ def get_order(self):
""" () => INT order
Obtain the byte order of the datatype; one of:
@@ -371,7 +371,7 @@ cdef class TypeID(LockableID):
SGN_NONE: Unsigned
SGN_2: Signed 2's complement
"""
- H5Tset_sign(self.id <H5T_sign_t>sign)
+ H5Tset_sign(self.id, <H5T_sign_t>sign)
def is_variable_str(self):
""" () => BOOL is_variable
@@ -496,19 +496,19 @@ cdef class TypeID(LockableID):
# === Enumeration datatypes ===================================================
- cdef int enum_convert(hid_t type_id, long long *buf, int reverse) except -1:
+ cdef int enum_convert(self, long long *buf, int reverse) except -1:
# Convert the long long value in "buf" to the native representation
- # of type_id. Conversion performed in-place.
+ # of this (enumerated type). Conversion performed in-place.
# Reverse: false => llong->type; true => type->llong
cdef hid_t basetype
cdef H5T_class_t class_code
- class_code = H5Tget_class(type_id)
+ class_code = H5Tget_class(self.id)
if class_code != H5T_ENUM:
- raise ValueError("Type %d is not of class ENUM" % type_id)
+ raise ValueError("This type (class %d) is not of class ENUM" % class_code)
- basetype = H5Tget_super(type_id)
+ basetype = H5Tget_super(self.id)
assert basetype > 0
try:
@@ -519,511 +519,92 @@ cdef class TypeID(LockableID):
finally:
PY_H5Tclose(basetype)
-def enum_insert(hid_t type_id, char* name, long long value):
- """ (INT type_id, STRING name, INT/LONG value)
+ def enum_insert(self, char* name, long long value):
+ """ (STRING name, INT/LONG value)
- Define a new member of an enumerated type. The value will be
- automatically converted to the base type defined for this enum. If
- the conversion results in overflow, the value will be silently clipped.
- """
- cdef long long buf
-
- buf = value
- enum_convert(type_id, &buf, 0)
- H5Tenum_insert(type_id, name, &buf)
-
-def enum_nameof(hid_t type_id, long long value):
- """ (INT type_id, LLONG value) => STRING name
-
- Determine the name associated with the given value. Due to a
- limitation of the HDF5 library, this can only retrieve names up to
- 1023 characters in length.
- """
- cdef herr_t retval
- cdef char name[1024]
- cdef long long buf
+ Define a new member of an enumerated type. The value will be
+ automatically converted to the base type defined for this enum. If
+ the conversion results in overflow, the value will be silently
+ clipped.
+ """
+ cdef long long buf
- buf = value
- enum_convert(type_id, &buf, 0)
- retval = H5Tenum_nameof(type_id, &buf, name, 1024)
- if retval < 0: # not sure whether H5Tenum_nameof will actually log an error
- raise RuntimeError("Failed to determine enum name of %d" % value)
- retstring = name
- return retstring
+ buf = value
+ self.enum_convert(&buf, 0)
+ H5Tenum_insert(self.id, name, &buf)
-def enum_valueof(hid_t type_id, char* name):
- """ (INT type_id, STRING name) => LONG value)
+ def enum_nameof(self, long long value):
+ """ (LLONG value) => STRING name
- Get the value associated with an enum name.
- """
- cdef long long buf
+ Determine the name associated with the given value. Due to a
+ limitation of the HDF5 library, this can only retrieve names up to
+ 1023 characters in length.
+ """
+ cdef herr_t retval
+ cdef char name[1024]
+ cdef long long buf
+
+ buf = value
+ self.enum_convert(&buf, 0)
+ retval = H5Tenum_nameof(self.id, &buf, name, 1024)
+ if retval < 0: # not sure whether H5Tenum_nameof will actually log an error
+ raise RuntimeError("Failed to determine enum name of %d" % value)
+ retstring = name
+ return retstring
+
+ def enum_valueof(self, char* name):
+ """ (STRING name) => LONG value)
+
+ Get the value associated with an enum name.
+ """
+ cdef long long buf
- H5Tenum_valueof(type_id, name, &buf)
- enum_convert(type_id, &buf, 1)
- return buf
+ H5Tenum_valueof(self.id, name, &buf)
+ self.enum_convert(&buf, 1)
+ return buf
-def get_member_value(hid_t type_id, int idx):
- """ (INT type_id, UINT index) => LONG value
+ def get_member_value(self, int idx):
+ """ (UINT index) => LONG value
- Determine the value for the member at the given zero-based index.
- """
- cdef herr_t retval
- cdef hid_t ptype
- cdef long long val
- ptype = 0
+ Determine the value for the member at the given zero-based index.
+ """
+ cdef herr_t retval
+ cdef hid_t ptype
+ cdef long long val
+ ptype = 0
- if index < 0:
- raise ValueError("Index must be non-negative.")
+ if index < 0:
+ raise ValueError("Index must be non-negative.")
- H5Tget_member_value(type_id, idx, &val)
- enum_convert(type_id, &val, 1)
- return val
+ H5Tget_member_value(self.id, idx, &val)
+ self.enum_convert(&val, 1)
+ return val
# === Opaque datatypes ========================================================
-def set_tag(hid_t type_id, char* tag):
- """ (INT type_id, STRING tag)
-
- Set a string describing the contents of an opaque datatype.
- """
- H5Tset_tag(type_id, tag)
-
-def get_tag(hid_t type_id):
- """ (INT type_id) => STRING tag
-
- Get the tag associated with an opaque datatype.
- """
- cdef char* buf
- buf = NULL
-
- try:
- buf = H5Tget_tag(type_id)
- assert buf != NULL
- tag = buf
- return tag
- finally:
- free(buf)
-
-# === Custom Python additions =================================================
-
+ def set_tag(self, char* tag):
+ """ (STRING tag)
-# Map array protocol strings to their HDF5 atomic equivalents
-# Not sure why LE/BE versions of I8/U8 exist; I'll include them anyway.
-_code_map = {"<i1": H5T_STD_I8LE, "<i2": H5T_STD_I16LE, "<i4": H5T_STD_I32LE, "<i8": H5T_STD_I64LE,
- ">i1": H5T_STD_I8BE, ">i2": H5T_STD_I16BE, ">i4": H5T_STD_I32BE, ">i8": H5T_STD_I64BE,
- "|i1": H5T_NATIVE_INT8, "|u1": H5T_NATIVE_UINT8,
- "<u1": H5T_STD_U8LE, "<u2": H5T_STD_U16LE, "<u4": H5T_STD_U32LE, "<u8": H5T_STD_U64LE,
- ">u1": H5T_STD_U8BE, ">u2": H5T_STD_U16BE, ">u4": H5T_STD_U32BE, ">u8": H5T_STD_U64BE,
- "<f4": H5T_IEEE_F32LE, "<f8": H5T_IEEE_F64LE, ">f4": H5T_IEEE_F32BE, ">f8": H5T_IEEE_F64BE }
-
-# Intermediate mapping which takes complex types to their components
-_complex_map = { "<c8": H5T_IEEE_F32LE, "<c16": H5T_IEEE_F64LE, ">c8": H5T_IEEE_F32BE, ">c16": H5T_IEEE_F64BE }
-
-_order_map = { H5T_ORDER_NONE: '|', H5T_ORDER_LE: '<', H5T_ORDER_BE: '>'}
-_sign_map = { H5T_SGN_NONE: 'u', H5T_SGN_2: 'i' }
-
-DEFAULT_COMPLEX_NAMES = ('r','i')
-VALID_BYTEORDERS = ('<','>','=')
-
-# For an HDF5 compound object to be considered complex, at least the following
-# must be true:
-# (1) Must have exactly two fields
-# (2) Both must be IEEE floating-point, of the same precision and byteorder
-
-def _validate_complex(item):
- """ Common validation function for complex names, which must be 2-tuples
- containing strings.
- """
- if not isinstance(item, tuple) or len(item) != 2 or \
- not isinstance(item[0], str) or not isinstance(item[1], str):
- raise ValueError("Complex names must be given a 2-tuples of strings: (real, img)")
-
-def _validate_byteorder(item):
- """ Common validation function for byte orders, which must be <, > or =.
- """
- if not item in VALID_BYTEORDERS:
- raise ValueError("Byte order must be one of "+", ".join(VALID_BYTEORDERS))
-
-def _validate_names(names):
- """ Common validation function for compound object field names, which must
- be tuples of strings.
- """
- if isinstance(names, tuple):
- bad = False
- for name in names:
- if not isinstance(name, str):
- bad = True
- break
- if not bad:
- return
- raise ValueError("Compound names must be given as a tuple of strings.")
-
-
-def py_translate_h5t(hid_t type_id, object byteorder=None,
- object compound_names=None, object complex_names=None):
- """ (INT type_id, STRING byteorder=None, TUPLE compound_names=None.
- TUPLE complex_names=None)
- => DTYPE
-
- Create a Numpy dtype object as similar as possible to the given HDF5
- datatype object. The result is guaranteed to be logically compatible
- with the original object, with no loss of precision, but may not
- implement the same memory layout as the HDF5 type.
-
- Optional arguments:
-
- byteorder:
- None or one of <, >, =. Coerce the byte order of the resulting
- dtype object. "None" preserves the original HDF5 byte order.
- This option IS applied to subtypes of arrays and compound types.
-
- compound_names:
- None or a tuple indicating which fields of a compound type to
- preserve in the output. Fields in the new dtype will be listed
- in the order that they appear here. Specifying a field which
- doesn't appear in the HDF5 type raises ValueError. This option
- IS NOT applied to subtypes of a compound type, but IS applied to
- subtypes of arrays.
-
- complex_names:
- Specifies when and how to interpret HDF5 compound datatypes as
- Python complex numbers. May be None or a tuple with strings
- (real name, img name). "None" indicates the default mapping of
- ("r", "i"). To turn this off, set to the empty tuple "()".
- This option IS applied to subtypes of arrays and compound types.
- """
- cdef int classtype
- cdef int sign
- cdef int size
- cdef int order
- cdef int nfields
- cdef int i
- cdef hid_t tmp_id
-
- typeobj = None
-
- # Argument validation and defaults
-
- if byteorder is not None:
- _validate_byteorder(byteorder)
-
- if compound_names is not None:
- _validate_names(compound_names)
-
- if complex_names is None:
- complex_names = DEFAULT_COMPLEX_NAMES
- elif complex_names != ():
- _validate_complex(complex_names)
+ Set a string describing the contents of an opaque datatype.
+ """
+ H5Tset_tag(self.id, tag)
- # End argument validation
+ def get_tag(self):
+ """ () => STRING tag
- classtype = get_class(type_id)
-
- if classtype == H5T_INTEGER:
- size = get_size(type_id)
- sign = get_sign(type_id)
- order = get_order(type_id)
- typeobj = dtype(_order_map[order] + _sign_map[sign] + str(size))
-
- elif classtype == H5T_FLOAT:
- size = get_size(type_id)
- order = get_order(type_id)
- typeobj = dtype(_order_map[order] + "f" + str(size))
-
- elif classtype == H5T_STRING:
- if is_variable_str(type_id):
- raise ValueError("Variable-length strings are not supported.")
- else:
- size = get_size(type_id)
- typeobj = dtype("|S" + str(size))
-
- elif classtype == H5T_OPAQUE:
- size = get_size(type_id)
- typeobj = dtype("|V" + str(size))
-
- elif classtype == H5T_COMPOUND:
-
- nfields = get_nmembers(type_id)
- field_names = []
- field_types = []
-
- # First step: read field names and their Numpy dtypes into
- # two separate arrays.
- for i from 0 <= i < nfields:
- tmp_id = get_member_type(type_id, i)
- try:
- tmp_name = get_member_name(type_id, i)
- field_names.append(tmp_name)
- field_types.append(py_translate_h5t(tmp_id, byteorder,
- None, complex_names))
- finally:
- PY_H5Tclose(tmp_id)
-
-
- # 1. Only a particular (ordered) subset is requested
- if compound_names is not None:
- dt_list = []
- # Validate the requested fields
- for name in compound_names:
- try:
- idx = field_names.index(name)
- except ValueError:
- raise ValueError('Field "%s" not found. Valid fields are:\n%s' % (name, ", ".join(field_names)))
- dt_list.append( (name, field_types[idx]) )
-
- typeobj = dtype(dt_list)
-
- # 2. Check if it should be converted to a complex number
- elif len(field_names) == 2 and tuple(field_names) == complex_names and \
- field_types[0] == field_types[1] and field_types[0].kind == 'f':
-
- bstring = field_types[0].str
- blen = int(bstring[2:])
- nstring = bstring[0] + "c" + str(2*blen)
-
- typeobj = dtype(nstring)
-
- # 3. Read all fields of the compound type, in HDF5 order.
- else:
- typeobj = dtype(zip(field_names, field_types))
-
- elif classtype == H5T_ENUM:
- # Enumerated types are treated as their parent type, with an additional
- # enum field entry carrying a dictionary as metadata
- super_tid = H5Tget_super(type_id)
- try:
- edct = py_translate_enum(type_id)
- # Superclass must be an integer, so only provide byteorder.
- typeobj = py_enum_attach(edct, py_translate_h5t(super_tid, byteorder))
- finally:
- PY_H5Tclose(super_tid)
+ Get the tag associated with an opaque datatype.
+ """
+ cdef char* buf
+ buf = NULL
- elif classtype == H5T_ARRAY:
- super_tid = get_super(type_id)
try:
- base_dtype = py_translate_h5t(super_tid, byteorder, compound_names, complex_names)
+ buf = H5Tget_tag(self.id)
+ assert buf != NULL
+ tag = buf
+ return tag
finally:
- PY_H5Tclose(super_tid)
- shape = get_array_dims(type_id)
- typeobj = dtype( (base_dtype, shape) )
- else:
- raise ValueError('Unsupported datatype class "%s"' % PY_NAMES[classtype])
-
- if byteorder is not None:
- return typeobj.newbyteorder(byteorder)
-
- return typeobj
-
-def py_translate_dtype(dtype dtype_in not None, object complex_names=None):
- """ ( DTYPE dtype_in, TUPLE complex_names=None) => INT type_id
-
- Given a Numpy dtype object, generate a byte-for-byte memory-compatible
- HDF5 transient datatype object.
-
- complex_names:
- Specifies when and how to interpret Python complex numbers as
- HDF5 compound datatypes. May be None or a tuple with strings
- (real name, img name). "None" indicates the default mapping of
- ("r", "i"). This option is also applied to subtypes of arrays
- and compound types.
- """
- cdef hid_t type_out
- cdef hid_t tmp
- cdef hid_t basetype
- cdef int retval
-
- cdef char* type_str
- cdef char kind
- cdef char byteorder
- cdef int length
-
- type_out = -1
-
- if complex_names is None:
- complex_names = DEFAULT_COMPLEX_NAMES
- else:
- _validate_complex(complex_names)
-
- type_str = dtype_in.str
- kind = type_str[1]
- byteorder = type_str[0]
-
- length = int(dtype_in.str[2:]) # is there a better way to do this?
-
- names = dtype_in.names
-
- # Anything with field names is considered to be a compound type, except enums
- if names is not None:
-
- # Check for enumerated type first
- if (kind == c'u' or kind == c'i') and len(names) == 1 and names[0] == 'enum':
- basetype = _code_map[dtype_in.str]
- type_out = py_translate_dict(py_enum_recover(dtype_in), basetype)
-
- # Otherwise it's just a compound type
- else:
- type_out = create(H5T_COMPOUND, length)
- for name in dtype_in.names:
- dt, offset = dtype_in.fields[name]
- tmp = py_translate_dtype(dt, complex_names)
- try:
- insert(type_out, name, offset, tmp)
- finally:
- PY_H5Tclose(tmp)
-
- # Integers and floats map directly to HDF5 atomic types
- elif kind == c'u' or kind == c'i' or kind == c'f':
- try:
- type_out = _code_map[dtype_in.str]
- except KeyError:
- raise ValueError("Failed to find '%s' in atomic code map" % dtype_in.str)
-
- # Complex numbers are stored as HDF5 structs, with names defined at runtime
- elif kind == c'c':
-
- if length == 8:
- type_out = create_ieee_complex64(byteorder, _complex_names[0], _complex_names[1])
- elif length == 16:
- type_out = create_ieee_complex128(byteorder, _complex_names[0], _complex_names[1])
- else:
- raise ValueError("Unsupported length %d for complex dtype: %s" % (length, repr(dtype_in)))
-
- if type_out < 0:
- raise ValueError("No complex equivalent for dtype: %s" % repr(dtype_in))
-
- # Opaque/array types are differentiated by the presence of a subdtype
- elif kind == c'V':
-
- if dtype_in.subdtype:
- basetype = py_translate_dtype(dtype_in.subdtype[0], complex_names)
- try:
- type_out = array_create(basetype, dtype_in.subdtype[1])
- finally:
- PY_H5Tclose(basetype)
- else:
- type_out = create(H5T_OPAQUE, length)
-
- # Strings are assumed to be stored C-style.
- elif kind == c'S':
- type_out = copy(H5T_C_S1)
- set_size(type_out, length)
-
- else:
- raise ValueError("No conversion path for dtype: %s" % repr(dtype_in))
-
- return type_out
-
-
-def py_translate_enum(hid_t type_id):
- """ (INT type_id) => DICT enum
-
- Produce a dictionary in the format [STRING] => LONG from
- an HDF5 enumerated type.
- """
- cdef int nmem
- cdef int i
- nmem = get_nmembers(type_id)
-
- dictout = {}
-
- for i from 0 <= i < nmem:
- dictout[get_member_name(type_id, i)] = get_member_value(type_id,i)
-
- return dictout
-
-def py_translate_dict(object enumdict, hid_t basetype):
- """ (DICT enumdict, INT basetype) => INT new_type_id
-
- Create a new HDF5 enumeration from a Python dictionary in the
- format [string name] => long value, and an HDF5 base type.
- """
- cdef hid_t type_id
- type_id = enum_create(basetype)
- for name, value in enumdict.iteritems():
- enum_insert(type_id, str(name), value)
-
- return type_id
-
-def py_enum_attach(object enumdict, object base_dtype):
- """ (DICT enum, DTYPE base_dtype) => DTYPE new_dtype
-
- Convert a Python dictionary in the format [string] => integer to a
- Numpy dtype with associated enum dictionary. Returns a new
- dtype object; does not mutate the original.
- """
- return dtype( (base_dtype, [( (enumdict, 'enum'), base_dtype )] ) )
-
-def py_enum_recover(dtype dtype_in):
- """ (DTYPE dtype_with_enum) => DICT enum
-
- Get the enum dictionary from a Numpy dtype object.
- """
- cdef object names
- names = dtype_in.names
-
- if names is not None:
- if len(names) == 1 and names[0] == 'enum':
- return dtype_in.fields['enum'][2]
-
- raise ValueError("Type %s is not an enumerated type" % repr(dtype_in))
-
-def py_list_compound_names(hid_t type_in):
- """ (INT type_id) => LIST compound_names
-
- Obtain a Python list of member names for a compound or
- enumeration type.
- """
- cdef int nmem
- cdef int i
-
- nmem = get_nmembers(type_in)
-
- qlist = []
- for i from 0<=i<nmem:
- qlist.append(get_member_name(type_in,i))
-
- return qlist
-
-def py_can_convert_dtype(object dt, object complex_names=None):
- """ (DTYPE dt, TUPLE complex_names=None) => BOOL can_convert
-
- Test whether the given Numpy dtype can be converted to the appropriate
- memory-compatible HDF5 datatype. complex_names works as in the
- function h5t.py_translate_dtype.
- """
- cdef hid_t tid
- tid = 0
-
- retval = None
- try:
- tid = py_translate_dtype(dt, complex_names)
- retval = True
- except ValueError:
- retval = False
-
- if tid:
- PY_H5Tclose(tid)
-
- return retval
-
-PY_SIGN = DDict({H5T_SGN_NONE: "UNSIGNED", H5T_SGN_2: "SIGNED"})
-
-PY_CLASS = DDict({ H5T_NO_CLASS: "ERROR", H5T_INTEGER: "INTEGER",
- H5T_FLOAT: "FLOAT", H5T_TIME: "TIME", H5T_STRING: "STRING",
- H5T_BITFIELD: "BITFIELD", H5T_OPAQUE: "OPAQUE",
- H5T_COMPOUND: "COMPOUND", H5T_REFERENCE: "REFERENCE",
- H5T_ENUM: "ENUM", H5T_VLEN: "VLEN", H5T_ARRAY: "ARRAY" })
-
-PY_ORDER = DDict({ H5T_ORDER_LE: "LITTLE-ENDIAN", H5T_ORDER_BE: "BIG-ENDIAN",
- H5T_ORDER_VAX: "VAX MIXED-ENDIAN", H5T_ORDER_NONE: "NONE" })
-
-
-
-
-
-
-
+ free(buf)
diff --git a/h5py/std_defs.pxi b/h5py/std_defs.pxi
index 1dd4ab5..c15c179 100644
--- a/h5py/std_defs.pxi
+++ b/h5py/std_defs.pxi
@@ -19,4 +19,3 @@ from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, \
hssize_t, haddr_t, hvl_t
from defs_c cimport size_t, time_t, ssize_t
-
--
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