Python support added
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
%module H5hut
|
||||
%{
|
||||
#define SWIG_FILE_WITH_INIT
|
||||
#include <stdint.h>
|
||||
#include "h5core/h5_types.h"
|
||||
//#include "H5.h"
|
||||
#include "H5hut.h"
|
||||
%}
|
||||
|
||||
%import <stdint.i>
|
||||
|
||||
%include numpy.i
|
||||
|
||||
%apply unsigned long int { h5_prop_t };
|
||||
%apply unsigned long int { h5_file_t };
|
||||
|
||||
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_size_t* };
|
||||
%apply (unsigned int* IN_ARRAY1) { h5_uint32_t* }; //uint32_t
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_uint64_t* }; //uint64_t
|
||||
%apply (int* IN_ARRAY1) { h5_int32_t* }; //int32_t
|
||||
%apply (long long* IN_ARRAY1) { h5_int64_t* }; //int64_t
|
||||
%apply (float* IN_ARRAY1) { h5_float32_t* };
|
||||
%apply (double* IN_ARRAY1) { h5_float64_t* };
|
||||
|
||||
|
||||
%init %{
|
||||
import_array();
|
||||
%}
|
||||
|
||||
|
||||
%ignore h5_report_errorhandler;
|
||||
%ignore h5_abort_errorhandler;
|
||||
%ignore h5priv_vprintf;
|
||||
%ignore h5_verror;
|
||||
%ignore H5ReportErrorhandler;
|
||||
%ignore H5AbortErrorhandler;
|
||||
|
||||
%include "h5core/h5_types.h"
|
||||
//%include "H5.h"
|
||||
//%include "H5_attribs.h"
|
||||
%include "H5_model.h"
|
||||
%include "H5hut.h"
|
||||
%include "H5Block_attribs.h"
|
||||
//%include "H5Block.h"
|
||||
%include "H5Block_io.h"
|
||||
%include "H5Block_model.h"
|
||||
//%include "H5Part.h"
|
||||
%include "H5Part_io.h"
|
||||
%include "H5Part_model.h"
|
||||
//%include "H5Fed_adjacency.h"
|
||||
//%include "H5Fed.h"
|
||||
//%include "H5Fed_model.h"
|
||||
//%include "H5Fed_retrieve.h"
|
||||
//%include "H5Fed_store.h"
|
||||
//%include "H5Fed_tags.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
%module H5hut_mpi
|
||||
%{
|
||||
#define SWIG_FILE_WITH_INIT
|
||||
#define PARALLEL_IO 1
|
||||
#include <mpi.h>
|
||||
#include <stdint.h>
|
||||
#include "h5core/h5_types.h"
|
||||
//#include "H5.h"
|
||||
#include "H5hut.h"
|
||||
%}
|
||||
|
||||
%import <stdint.i>
|
||||
|
||||
%include numpy.i
|
||||
|
||||
%apply unsigned long int { h5_prop_t };
|
||||
%apply unsigned long int { h5_file_t };
|
||||
|
||||
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_size_t* };
|
||||
%apply (unsigned int* IN_ARRAY1) { h5_uint32_t* }; //uint32_t
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_uint64_t* }; //uint64_t
|
||||
%apply (int* IN_ARRAY1) { h5_int32_t* }; //int32_t
|
||||
%apply (long long* IN_ARRAY1) { h5_int64_t* }; //int64_t
|
||||
%apply (float* IN_ARRAY1) { h5_float32_t* };
|
||||
%apply (double* IN_ARRAY1) { h5_float64_t* };
|
||||
|
||||
|
||||
%init %{
|
||||
import_array();
|
||||
%}
|
||||
|
||||
%include mpi4py/mpi4py.i
|
||||
%mpi4py_typemap(Comm, MPI_Comm);
|
||||
%typemap(in) MPI_Comm* {
|
||||
MPI_Comm *ptr = (MPI_Comm *)0;
|
||||
int res = SWIG_AsPtr_MPI_Comm($input, &ptr);
|
||||
if (!SWIG_IsOK(res) || !ptr) {
|
||||
SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "$symname" "', argument " "$argnum"" of type '" "MPI_Comm""'");
|
||||
}
|
||||
$1 = ptr;
|
||||
if (SWIG_IsNewObj(res)) free((char*)ptr);
|
||||
}
|
||||
|
||||
%ignore h5_report_errorhandler;
|
||||
%ignore h5_abort_errorhandler;
|
||||
%ignore h5priv_vprintf;
|
||||
%ignore h5_verror;
|
||||
%ignore H5ReportErrorhandler;
|
||||
%ignore H5AbortErrorhandler;
|
||||
|
||||
%include "h5core/h5_types.h"
|
||||
//%include "H5.h"
|
||||
//%include "H5_attribs.h"
|
||||
%include "H5_model.h"
|
||||
%include "H5hut.h"
|
||||
%include "H5Block_attribs.h"
|
||||
//%include "H5Block.h"
|
||||
%include "H5Block_io.h"
|
||||
%include "H5Block_model.h"
|
||||
//%include "H5Part.h"
|
||||
%include "H5Part_io.h"
|
||||
%include "H5Part_model.h"
|
||||
//%include "H5Fed_adjacency.h"
|
||||
//%include "H5Fed.h"
|
||||
//%include "H5Fed_model.h"
|
||||
//%include "H5Fed_retrieve.h"
|
||||
//%include "H5Fed_store.h"
|
||||
//%include "H5Fed_tags.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
if ENABLE_PYTHON
|
||||
|
||||
if ENABLE_PARALLEL
|
||||
|
||||
BUILT_SOURCES = H5hut_mpi_wrap.c
|
||||
SWIG_SOURCES = H5hut_mpi.i $(MPI4PY_INCLUDE)/mpi4py/mpi4py.i numpy.i
|
||||
|
||||
pkgpython_PYTHON = H5hut_mpi.py __init__.py
|
||||
pkgpyexec_LTLIBRARIES = _H5hut_mpi.la
|
||||
|
||||
_H5hut_mpi_la_SOURCES = H5hut_mpi_wrap.c $(SWIG_SOURCES)
|
||||
_H5hut_mpi_la_CPPFLAGS = -DPARALLEL_IO $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(MPI4PY_INCLUDE) -I$(NUMPY_INCLUDE)
|
||||
_H5hut_mpi_la_LDFLAGS = -module
|
||||
_H5hut_mpi_la_LIBADD = $(top_builddir)/src/h5core/libH5hut.la
|
||||
|
||||
H5hut_mpi_wrap.c : $(SWIG_SOURCES)
|
||||
$(SWIG) $(SWIG_PYTHON_OPT) -python -DPARALLEL_IO -I$(top_srcdir)/src/include -I$(MPI4PY_INCLUDE) -o $@ $<
|
||||
|
||||
else
|
||||
|
||||
BUILT_SOURCES = H5hut_wrap.c
|
||||
SWIG_SOURCES = H5hut.i numpy.i
|
||||
|
||||
pkgpython_PYTHON = H5hut.py __init__.py
|
||||
pkgpyexec_LTLIBRARIES = _H5hut.la
|
||||
|
||||
_H5hut_la_SOURCES = H5hut_wrap.c $(SWIG_SOURCES)
|
||||
_H5hut_la_CPPFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(NUMPY_INCLUDE)
|
||||
_H5hut_la_LDFLAGS = -module
|
||||
_H5hut_la_LIBADD = $(top_builddir)/src/h5core/libH5hut.la
|
||||
|
||||
H5hut_wrap.c : $(SWIG_SOURCES)
|
||||
$(SWIG) $(SWIG_PYTHON_OPT) -python -I$(top_srcdir)/src/include -o $@ $<
|
||||
|
||||
|
||||
endif
|
||||
|
||||
#all-local:
|
||||
# $(INSTALL) -d $(DESTDIR)/site-packages/h5hut
|
||||
# $(INSTALL) -m644 H5hut.py $(DESTDIR)/site-packages/h5hut/
|
||||
# $(INSTALL) -m644 .libs/_H5hut.so $(DESTDIR)/site-packages/h5hut/
|
||||
endif
|
||||
|
||||
clean: clean-am
|
||||
|
||||
clean-local:
|
||||
$(RM) -f *~ H5hut_wrap.c H5hut.py H5hut.pyc H5hut_mpi_wrap.c H5hut_mpi.py H5hut_mpi.pyc
|
||||
@@ -0,0 +1,73 @@
|
||||
#TODO: use the rewrite to swap depending whether mpi is there are not..
|
||||
|
||||
import numpy
|
||||
|
||||
try:
|
||||
import H5hut_mpi as H5hut_rewrite
|
||||
from H5hut_mpi import *
|
||||
except:
|
||||
import H5hut as H5hut_rewrite
|
||||
from H5hut import *
|
||||
|
||||
|
||||
__h5hut_table__ = {}
|
||||
|
||||
# for now assume last parameter is the data field..
|
||||
funcx = """
|
||||
def {0}(*args, **kwargs):
|
||||
import numpy
|
||||
if type(args[-1]) is numpy.ndarray:
|
||||
#print "writing type", args[-1].dtype
|
||||
__h5hut_table__['{0}'][args[-1].dtype](*args, **kwargs)
|
||||
elif ((type(args[-1]) is list or type(args[-1]) is tuple) and len(args[-1]) > 0):
|
||||
#print "writing type", type(args[-1][0]).dtype
|
||||
__h5hut_table__['{0}'][numpy.dtype(type(args[-1][0]))](*args, **kwargs)
|
||||
else:
|
||||
print 'last argument is not a numpy data array'
|
||||
"""
|
||||
|
||||
def __update_types__():
|
||||
import numpy
|
||||
import sys
|
||||
import inspect
|
||||
|
||||
__h5hut_api__ = dir(H5hut_rewrite)
|
||||
|
||||
__h5hut_types__ = [ "Int32", "Int64", "Float32", "Float64" ]
|
||||
__numpy_types__ = [ numpy.dtype(numpy.int32),
|
||||
numpy.dtype(numpy.int64),
|
||||
numpy.dtype(numpy.float32),
|
||||
numpy.dtype(numpy.float64) ]
|
||||
|
||||
for __i__ in __h5hut_api__:
|
||||
for __j__ in __h5hut_types__:
|
||||
if __j__ in __i__:
|
||||
key = __i__[:-len(__j__)]
|
||||
|
||||
numpy_key = __numpy_types__[__h5hut_types__.index(__j__)]
|
||||
func = H5hut_rewrite.__dict__[__i__]
|
||||
|
||||
if key not in __h5hut_table__:
|
||||
__h5hut_table__[key] = {}
|
||||
|
||||
__h5hut_table__[key][numpy_key] = func
|
||||
|
||||
del H5hut_rewrite.__dict__[__i__]
|
||||
del sys.modules["H5hut"].__dict__[__i__]
|
||||
|
||||
for __new_func__ in __h5hut_table__.keys():
|
||||
types = __h5hut_table__[__new_func__]
|
||||
#args = inspect.getargspec(types[0])
|
||||
#print __new_func__
|
||||
result = funcx.format(__new_func__)
|
||||
exec(result)
|
||||
|
||||
#H5hut_rewrite.__dict__[__new_func__] = globals()[__new_func__]
|
||||
sys.modules["H5hut"].__dict__[__new_func__] = locals()[__new_func__]
|
||||
|
||||
__update_types__()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+3115
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user