[h5py] 128/455: Start reworking h5t

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

    Start reworking h5t
---
 h5py/compat.h    |  34 ++++++++++++++++
 h5py/defs.pxd    |  16 ++++----
 h5py/h5t.pyx     |  53 ++++++++++++++++++++-----
 h5py/utils.pxd   |   6 ---
 h5py/utils_low.c | 117 -------------------------------------------------------
 h5py/utils_low.h |  30 --------------
 setup.py         |   5 +--
 7 files changed, 87 insertions(+), 174 deletions(-)

diff --git a/h5py/compat.h b/h5py/compat.h
new file mode 100644
index 0000000..1b85c83
--- /dev/null
+++ b/h5py/compat.h
@@ -0,0 +1,34 @@
+/***** Preamble block *********************************************************
+* 
+* This file is part of h5py, a low-level Python interface to the HDF5 library.
+* 
+* Copyright (C) 2008 Andrew Collette
+* http://h5py.alfven.org
+* License: BSD  (See LICENSE.txt for full license)
+* 
+* $Date$
+* 
+****** End preamble block ****************************************************/
+
+/* Contains compatibility macros and definitions for use by Cython code */
+
+#ifndef H5PY_COMPAT
+#define H5PY_COMPAT
+
+#include <stddef.h>
+#include "Python.h"
+#include "numpy/arrayobject.h"
+#include "hdf5.h"
+
+/* The HOFFSET macro can't be used from Cython. */
+
+#define h5py_size_n64 (sizeof(npy_complex64))
+#define h5py_size_n128 (sizeof(npy_complex128))
+
+#define h5py_offset_n64_real (HOFFSET(npy_complex64, real))
+#define h5py_offset_n64_imag (HOFFSET(npy_complex64, imag))
+#define h5py_offset_n128_real (HOFFSET(npy_complex128, real))
+#define h5py_offset_n128_imag (HOFFSET(npy_complex128, imag))
+
+#endif
+
diff --git a/h5py/defs.pxd b/h5py/defs.pxd
index f6aa670..ac46836 100644
--- a/h5py/defs.pxd
+++ b/h5py/defs.pxd
@@ -55,14 +55,14 @@ cdef extern from "stdint.h":
 
 # === Compatibility definitions and macros for h5py ===========================
 
-#cdef extern from "compat.h":
-
-#  size_t h5py_size_n64
-#  size_t h5py_size_n128
-#  size_t h5py_offset_n64_real
-#  size_t h5py_offset_n64_imag
-#  size_t h5py_offset_n128_real
-#  size_t h5py_offset_n128_imag
+cdef extern from "compat.h":
+
+  size_t h5py_size_n64
+  size_t h5py_size_n128
+  size_t h5py_offset_n64_real
+  size_t h5py_offset_n64_imag
+  size_t h5py_offset_n128_real
+  size_t h5py_offset_n128_imag
 
 # === H5 - Common definitions and library functions ===========================
 
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index 81c2279..c235059 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -66,7 +66,6 @@ from numpy cimport dtype, ndarray
 from python_string cimport PyString_FromStringAndSize
 
 from utils cimport  emalloc, efree, \
-                    create_ieee_complex64, create_ieee_complex128, \
                     require_tuple, convert_dims, convert_tuple
 
 # Initialization
@@ -1158,14 +1157,25 @@ cpdef object py_create(object dtype_in, object enum_vals=None):
             HDF5 type will be an enumeration with that base type, and the 
             given values. Ignored for all other types.
     """
-    cdef dtype dt
-    cdef TypeID otype
-    cdef TypeID base
+    global _code_map
+
+    cdef dtype dt       # The dtype we'll be converting
+    cdef TypeID otype   # The output TypeID
+
+    cdef hid_t tid, tid_sub
+
     cdef TypeID tmp
-    cdef dtype dt_tmp
+
+    # For compound types
+    cdef dtype dt_tmp   
+    cdef size_t offset
+
     cdef char kind
     cdef char byteorder
     cdef int length
+    
+
+    cdef size_t c_size, c_off_r, c_off_i
 
     dt = dtype(dtype_in)
     otype = None
@@ -1178,12 +1188,15 @@ cpdef object py_create(object dtype_in, object enum_vals=None):
 
     # Void types with field names are considered to be compound
     if kind == c'V' and names is not None:
-        otype = create(H5T_COMPOUND, length)
+        
+        tid = H5Tcreate(H5T_COMPOUND, length)
 
         for name in names:
             dt_tmp, offset = dt.fields[name]
             tmp = py_create(dt_tmp)
-            otype.insert(name, offset, tmp)
+            H5Tinsert(tid, name, offset, tmp.id)
+
+        otype = TypeCompoundID(tid)
 
     # Enums may be created out of integer types
     elif (kind == c'u' or kind == c'i') and enum_vals is not None:
@@ -1202,12 +1215,34 @@ cpdef object py_create(object dtype_in, object enum_vals=None):
     elif kind == c'c':
 
         if length == 8:
-            otype = typewrap(create_ieee_complex64(byteorder, cfg._r_name, cfg._i_name))
+            c_size = h5py_size_n64
+            c_off_r = h5py_offset_n64_real
+            c_off_i = h5py_offset_n64_imag
+            if byteorder == c'<':
+                tid_sub = H5T_IEEE_F32LE
+            elif byteorder == c'>':
+                tid_sub = H5T_IEEE_F32BE
+            else:
+                tid_sub = H5T_NATIVE_FLOAT
         elif length == 16:
-            otype = typewrap(create_ieee_complex128(byteorder, cfg._r_name, cfg._i_name))
+            c_size = h5py_size_n128
+            c_off_r = h5py_offset_n128_real
+            c_off_i = h5py_offset_n128_imag
+            if byteorder == c'<':
+                tid_sub = H5T_IEEE_F64LE
+            elif byteorder == c'>':
+                tid_sub = H5T_IEEE_F64BE
+            else:
+                tid_sub = H5T_NATIVE_DOUBLE
         else:
             raise ValueError("Unsupported length %d for complex dtype: %s" % (length, repr(dt)))
 
+        tid = H5Tcreate(H5T_COMPOUND, c_size)
+        H5Tinsert(tid, cfg._r_name, c_off_r, tid_sub)
+        H5Tinsert(tid, cfg._i_name, c_off_i, tid_sub)
+
+        otype = TypeCompoundID(tid)
+
     # Opaque/array types are differentiated by the presence of a subdtype
     elif kind == c'V':
 
diff --git a/h5py/utils.pxd b/h5py/utils.pxd
index 8558dcd..2361ae2 100644
--- a/h5py/utils.pxd
+++ b/h5py/utils.pxd
@@ -14,12 +14,6 @@ include "defs.pxd"
 
 from numpy cimport ndarray
 
-cdef extern from "utils_low.h":
-
-    # Python to HDF5 complex conversion
-    hid_t create_ieee_complex64(char byteorder, char* real_name, char* img_name) except -1
-    hid_t create_ieee_complex128(char byteorder, char* real_name, char* img_name) except -1
-
 # === Custom API ==============================================================
 
 # Memory handling
diff --git a/h5py/utils_low.c b/h5py/utils_low.c
deleted file mode 100644
index 5934b99..0000000
--- a/h5py/utils_low.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/***** Preamble block *********************************************************
-* 
-* This file is part of h5py, a low-level Python interface to the HDF5 library.
-* 
-* Copyright (C) 2008 Andrew Collette
-* http://h5py.alfven.org
-* License: BSD  (See LICENSE.txt for full license)
-* 
-* $Date$
-* 
-****** End preamble block ****************************************************/
-
-/* 
-   Utilities which are difficult or impossible to implement in pure Pyrex, 
-   such as functions requiring HDF5 C macros.
-
-   This file contains code based on utils.c from the PyTables project.  The
-   complete PyTables license is available under licenses/pytables.txt in the
-   distribution root directory.
-*/
-
-#include "Python.h"
-#include "numpy/arrayobject.h"
-#include "utils_low.h"
-#include "hdf5.h"
-#include "pythread.h"
-
-
-/* Rewritten versions of create_ieee_complex64/128 from Pytables, to support 
-   standard array-interface typecodes and variable names for real/imag parts.  
-   Also removed unneeded datatype copying.
-   Both return -1 on failure, and raise Python exceptions.
-
-   These must be written in C as they use the HOFFSET macro.
-*/
-hid_t create_ieee_complex64(const char byteorder, const char* real_name, const char* img_name) {
-  hid_t float_id = -1;
-  hid_t complex_id = -1;
-  herr_t retval = -1;
-
-  complex_id = H5Tcreate(H5T_COMPOUND, sizeof(npy_complex64));
-  if(complex_id < 0) goto err;
-
-  if (byteorder == '<')
-    float_id = H5T_IEEE_F32LE;
-  else if (byteorder == '>')
-    float_id = H5T_IEEE_F32BE;
-  else if (byteorder == '=' || byteorder == '|')
-    float_id = H5T_NATIVE_FLOAT;
-  else {
-    PyErr_SetString(PyExc_ValueError, "Byte order must be one of <, > or |");
-    goto err;
-  }
-
-  retval = H5Tinsert(complex_id, real_name, HOFFSET(npy_complex64, real), float_id);
-  if(retval<0) goto err;
-
-  retval = H5Tinsert(complex_id, img_name, HOFFSET(npy_complex64, imag), float_id);
-  if(retval<0) goto err;
-
-  return complex_id;
-
-  err:
-    if(!PyErr_Occurred()){
-        PyErr_SetString(PyExc_RuntimeError, "Failed to propagate exception at create_ieee_complex64.");
-    }
-    if(complex_id > 0)
-        H5Tclose(complex_id);
-    return -1;
-}
-
-hid_t create_ieee_complex128(const char byteorder, const char* real_name, const char* img_name) {
-  hid_t float_id = -1;
-  hid_t complex_id = -1;
-  herr_t retval = -1;
-
-  complex_id = H5Tcreate(H5T_COMPOUND, sizeof(npy_complex128));
-  if(complex_id < 0) goto err;
-
-  if (byteorder == '<')
-    float_id = H5T_IEEE_F64LE;
-  else if (byteorder == '>')
-    float_id = H5T_IEEE_F64BE;
-  else if (byteorder == '=' || byteorder == '|')
-    float_id = H5T_NATIVE_DOUBLE;
-  else {
-    PyErr_SetString(PyExc_ValueError, "Byte order must be one of <, > or |");
-    goto err;
-  }
-
-  retval = H5Tinsert(complex_id, real_name, HOFFSET(npy_complex128, real), float_id);
-  if(retval<0) goto err;
-
-  retval = H5Tinsert(complex_id, img_name, HOFFSET(npy_complex128, imag), float_id);
-  if(retval<0) goto err;
-
-  return complex_id;
-
-  err:
-    if(!PyErr_Occurred()){
-        PyErr_SetString(PyExc_RuntimeError, "Failed to propagate exception at create_ieee_complex128.");
-    }
-    if(complex_id > 0)
-        H5Tclose(complex_id);
-    return -1;
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/h5py/utils_low.h b/h5py/utils_low.h
deleted file mode 100644
index 0e90c2e..0000000
--- a/h5py/utils_low.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/***** Preamble block *********************************************************
-* 
-* This file is part of h5py, a low-level Python interface to the HDF5 library.
-* 
-* Copyright (C) 2008 Andrew Collette
-* http://h5py.alfven.org
-* License: BSD  (See LICENSE.txt for full license)
-* 
-* $Date$
-* 
-****** End preamble block ****************************************************/
-
-/*
-   This file contains code based on utils.c from the PyTables project.  The
-   complete PyTables license is available under licenses/pytables.txt in the
-   distribution root directory.
-*/
-
-#ifndef H5PY_UTILS_LOW
-#define H5PY_UTILS_LOW
-
-#include "Python.h"
-#include "hdf5.h"
-#include "numpy/arrayobject.h"
-
-hid_t create_ieee_complex64(const char byteorder, const char* real_name, const char* img_name);
-hid_t create_ieee_complex128(const char byteorder, const char* real_name, const char* img_name);
-
-#endif
-
diff --git a/setup.py b/setup.py
index 797208c..2c6efe4 100644
--- a/setup.py
+++ b/setup.py
@@ -56,9 +56,6 @@ MODULES = {16:  ['h5', 'h5f', 'h5g', 'h5s', 'h5t', 'h5d', 'h5a', 'h5p', 'h5z',
            18:  ['h5', 'h5f', 'h5g', 'h5s', 'h5t', 'h5d', 'h5a', 'h5p', 'h5z',
                  'h5i', 'h5r', 'h5fd', 'utils', 'h5o', 'h5l']}
 
-# C source files required for all modules
-EXTRA_SRC = ['utils_low.c']
-
 def fatal(instring, code=1):
     print >> sys.stderr, "Fatal: "+instring
     exit(code)
@@ -236,7 +233,7 @@ DEF H5PY_THREADS = %(THREADS)d  # Enable thread-safety and non-blocking reads
         creator = ExtensionCreator(self.hdf5)
         modules = sorted(MODULES[max(self.api)])
         self.distribution.ext_modules = \
-            [creator.create_extension(x, EXTRA_SRC) for x in modules]
+            [creator.create_extension(x) for x in modules]
 
         # Necessary because Cython doesn't detect changes to the .pxi
         recompile_all = 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