from ctypes import POINTER as PTR from ctypes import c_bool, c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructRealAVector, CStructTruncMode # ------------------------ CStructTruncMode._fields_ = [('frobenius', c_bool), ('absolute', c_bool), ('blocks', c_bool), ('zeta_level', real), ('zeta_age', real)] # ------------------------ new_truncmode = get_func('new_truncmode', PTR(CStructTruncMode), []) del_truncmode = get_func('del_truncmode', None, [PTR(CStructTruncMode)]) new_releucl_truncmode = get_func('new_releucl_truncmode', PTR(CStructTruncMode), []) new_relfrob_truncmode = get_func('new_relfrob_truncmode', PTR(CStructTruncMode), []) new_blockreleucl_truncmode = get_func('new_blockreleucl_truncmode', PTR(CStructTruncMode), []) new_blockrelfrob_truncmode = get_func('new_blockrelfrob_truncmode', PTR(CStructTruncMode), []) new_abseucl_truncmode = get_func('new_abseucl_truncmode', PTR(CStructTruncMode), []) findrank_truncmode = get_func( 'findrank_truncmode', c_uint, [PTR(CStructTruncMode), real, PTR(CStructRealAVector)])
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CEnumClusterMode, CStructCluster, CStructClusterGeometry) # ------------------------ CFuncClusterCallbackT = CFUNCTYPE(None, *(PTR(CStructCluster), c_uint, c_void_p)) CEnumClusterMode.H2_ADAPTIVE = CEnumClusterMode(0) CEnumClusterMode.H2_REGULAR = CEnumClusterMode(1) CEnumClusterMode.H2_SIMSUB = CEnumClusterMode(2) CEnumClusterMode.H2_PCA = CEnumClusterMode(3) # ------------------------ CStructCluster._fields_ = [ ('size', c_uint), ('idx', PTR(c_uint)), ('sons', c_uint), ('dim', c_uint), ('bmin', PTR(real)), ('bmax', PTR(real)), ('desc', c_uint),
class WSABUF(ctypes.Structure): _fields_ = [ ('len', ctypes.c_ulong), # u_long ('buf', PTR(ctypes.c_char)), # char FAR * ]
except ImportError: # Fallback for python before version 2.7 from distutils.sysconfig import get_config_var from itertools import islice from ctypes import (cdll, CDLL, RTLD_GLOBAL, POINTER as PTR, CFUNCTYPE as CFT, Structure, cast, pointer, byref, c_int, c_uint, c_float, c_double, c_char, c_char_p, c_void_p) from ctypes.util import find_library # Maybe a bit ugly. Is there a more kosher way of making sure that the # libstdc++ (or similar) symbols are available to the molfile-plugins? _cxx = CDLL(find_library('stdc++'), mode=RTLD_GLOBAL) c_int_p = PTR(c_int) c_int_pp = PTR(c_int_p) c_char_pp = PTR(c_char_p) c_char_ppp = PTR(c_char_pp) c_float_p = PTR(c_float) c_float_pp = PTR(c_float_p) # # As of molfile_plugin abiversion 16, the following trajectory # formats are supported (pasted from the AMD web page): # # Molecular Dynamics Trajectory File Plugins # # AMBER 'binpos' trajectory reader (.binpos) # AMBER "CRD" trajectory reader (.crd, .crdbox) # AMBER NetCDF trajectory reader (.nc)
class molfile_plugin_t(Structure): # ABI from molfile abiversion 16 # This is the important(TM) structure. # Only partial read support is considered for now, other # functions have been replaced by a dummy_fun_t placeholder. _fields_ = [ ('abiversion', c_int), ('type', c_char_p), ('name', c_char_p), ('prettyname', c_char_p), ('author', c_char_p), ('majorv', c_int), ('minorv', c_int), ('is_reentrant', c_int), ('filename_extension', c_char_p), # # void *(* open_file_read)(const char *filepath, const char *filetype, int *natoms); ('open_file_read', CFT(c_void_p, c_char_p, c_char_p, c_int_p)), # # int (*read_structure)(void *, int *optflags, molfile_atom_t *atoms); ('read_structure', CFT(c_int, c_void_p, c_int_p, PTR(molfile_atom_t))), # # int (*read_bonds)(void *, int *nbonds, int **from, int **to, float **bondorder, # int **bondtype, int *nbondtypes, char ***bondtypename); ('read_bonds', dummy_fun_t), # # int (* read_next_timestep)(void *, int natoms, molfile_timestep_t *); ('read_next_timestep', CFT(c_int, c_void_p, c_int, PTR(molfile_timestep_t))), # # void (* close_file_read)(void *); ('close_file_read', CFT(None, c_void_p)), # # void *(* open_file_write)(const char *filepath, const char *filetype, # int natoms); ('open_file_write', dummy_fun_t), # # int (* write_structure)(void *, int optflags, const molfile_atom_t *atoms); ('write_structure', dummy_fun_t), # # int (* write_timestep)(void *, const molfile_timestep_t *); ('write_timestep', dummy_fun_t), # # void (* close_file_write)(void *); ('close_file_write', dummy_fun_t), # # int (* read_volumetric_metadata)(void *, int *nsets, # molfile_volumetric_t **metadata); ('read_volumetric_metadata', CFT(c_int, c_void_p, c_int_p, PTR(PTR(molfile_volumetric_t)))), # # int (* read_volumetric_data)(void *, int set, float *datablock, # float *colorblock); ('read_volumetric_data', CFT(c_int, c_void_p, c_int, c_float_p, c_float_p)), # # int (* read_rawgraphics)(void *, int *nelem, const molfile_graphics_t **data); ('read_rawgraphics', dummy_fun_t), # # int (* read_molecule_metadata)(void *, molfile_metadata_t **metadata); ('read_molecule_metadata', CFT(c_int, c_void_p, PTR(PTR(molfile_metadata_t)))), # # int (* write_bonds)(void *, int nbonds, int *from, int *to, float *bondorder, # int *bondtype, int nbondtypes, char **bondtypename); ('write_bonds', dummy_fun_t), # # int (* write_volumetric_data)(void *, molfile_volumetric_t *metadata, # float *datablock, float *colorblock); ('write_volumetric_data', dummy_fun_t), # # int (* read_angles)(void *handle, int *numangles, int **angles, int **angletypes, # int *numangletypes, char ***angletypenames, int *numdihedrals, # int **dihedrals, int **dihedraltypes, int *numdihedraltypes, # char ***dihedraltypenames, int *numimpropers, int **impropers, # int **impropertypes, int *numimpropertypes, char ***impropertypenames, # int *numcterms, int **cterms, int *ctermcols, int *ctermrows); ('read_angles', dummy_fun_t), # # int (* write_angles)(void *handle, int numangles, const int *angles, const int *angletypes, # int numangletypes, const char **angletypenames, int numdihedrals, # const int *dihedrals, const int *dihedraltypes, int numdihedraltypes, # const char **dihedraltypenames, int numimpropers, # const int *impropers, const int *impropertypes, int numimpropertypes, # const char **impropertypenames, int numcterms, const int *cterms, # int ctermcols, int ctermrows); ('write_angles', dummy_fun_t), # # int (* read_qm_metadata)(void *, molfile_qm_metadata_t *metadata); ('read_qm_metadata', dummy_fun_t), # # int (* read_qm_rundata)(void *, molfile_qm_t *qmdata); ('read_qm_rundata', dummy_fun_t), # # int (* read_timestep)(void *, int natoms, molfile_timestep_t *, # molfile_qm_metadata_t *, molfile_qm_timestep_t *); ('read_timestep', CFT(c_int, c_void_p, c_int, PTR(molfile_timestep_t), PTR(molfile_qm_metadata_t), PTR(molfile_qm_timestep_t))), # # int (* read_timestep_metadata)(void *, molfile_timestep_metadata_t *); ('read_timestep_metadata', CFT(c_int, c_void_p, PTR(molfile_timestep_metadata_t))), # # int (* read_qm_timestep_metadata)(void *, molfile_qm_timestep_metadata_t *); ('read_qm_timestep_metadata', dummy_fun_t), # # int (* cons_fputs)(const int, const char*); ('cons_fputs', CFT(c_int, c_int, c_char_p)) ]
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructDBlock, CStructDCluster, CStructDClusterBasis, CStructDClusterOperator) # ------------------------ CFuncDClusterBasisCallbackT = CFUNCTYPE( None, *(PTR(CStructDClusterBasis), c_uint, c_uint, c_void_p)) # ------------------------ CStructDClusterBasis._fields_ = [ ('t', PTR(CStructDCluster)), ('directions', c_uint), ('k', PTR(c_uint)), ('koff', PTR(c_uint)), ('ktree', c_uint), ('kbranch', c_uint), ('V', PTR(CStructAMatrix)), ('E', PTR(PTR(CStructAMatrix))), ('sons', c_uint), ('son', PTR(PTR(CStructDClusterBasis))), ('dirson', PTR(PTR(c_uint))), ]
import numpy as np import os from ctypes import POINTER as PTR, c_byte, c_ushort, c_size_t speedup_ctypes = np.ctypeslib.load_library('speedup_ctypes.so', os.path.dirname(__file__)) speedup_ctypes.inrange.argtypes = [ PTR(c_ushort), PTR(c_byte), PTR(c_ushort), PTR(c_ushort), c_size_t ] import speedup_cy def threshold_and_mask(depth, bg): import scipy from scipy.ndimage import binary_erosion def m_(): # Optimize this in C? return (depth > bg['bgLo']) & (depth < bg['bgHi']) # background def m2_(): mm = np.empty((480, 640), 'bool') speedup_ctypes.inrange(depth.ctypes.data_as(PTR(c_ushort)), mm.ctypes.data_as(PTR(c_byte)), bg['bgHi'].ctypes.data_as(PTR(c_ushort)), bg['bgLo'].ctypes.data_as(PTR(c_ushort)), 480 * 640) return mm
# load BLAS and GSL from ctypes.util import find_library libblas = CDLL(find_library("libblas"), RTLD_GLOBAL) libgslcblas = CDLL(find_library("gslcblas"), RTLD_GLOBAL) libgsl = CDLL(find_library("gsl"), RTLD_GLOBAL) class gsl_wavelet_type(Structure): pass class gsl_wavelet(Structure): pass class gsl_wavelet_workspace(Structure): pass p_gsl_wavelet_type = PTR(gsl_wavelet_type) def _p_const(fname): return p_gsl_wavelet_type.in_dll(libgsl,"gsl_wavelet_" + fname) def _types(fname, restype, argtypes): f = libgsl.__getattr__("gsl_wavelet_" + fname) if restype != None: f.restype = restype f.argtypes = argtypes return f _types("alloc", PTR(gsl_wavelet), [p_gsl_wavelet_type, c_size_t]) _types("free", None, [PTR(gsl_wavelet)]) _types("name", c_char_p, [PTR(gsl_wavelet)]) _types("workspace_alloc", PTR(gsl_wavelet_workspace), [c_size_t])
from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p, c_size_t from h2libpy.lib.settings import real, field from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructAVector, CStructAMatrix # ------------------------ CStructAVector._fields_ = [ ('v', PTR(field)), ('dim', c_uint), ('owner', c_void_p) ] # ------------------------ init_avector = get_func('init_avector', PTR(CStructAVector), [PTR(CStructAVector), c_uint]) init_sub_avector = get_func('init_sub_avector', PTR(CStructAVector), [PTR(CStructAVector), PTR(CStructAVector), c_uint, c_uint]) init_zero_avector = get_func('init_zero_avector', PTR(CStructAVector), [PTR(CStructAVector), c_uint]) init_column_avector = get_func('init_column_avector', PTR(CStructAVector), [PTR(CStructAVector), PTR(CStructAMatrix), c_uint]) init_pointer_avector = get_func('init_pointer_avector', PTR(CStructAVector), [PTR(CStructAVector), PTR(field), c_uint]) uninit_avector = get_func('uninit_avector', None, [PTR(CStructAVector)]) new_avector = get_func('new_avector', PTR(CStructAVector), [c_uint]) new_sub_avector = get_func('new_sub_avector', PTR(CStructAVector), [PTR(CStructAVector), c_uint, c_uint]) new_zero_avector = get_func('new_zero_avector', PTR(CStructAVector), [c_uint]) new_pointer_avector = get_func('new_pointer_avector', PTR(CStructAVector), [PTR(field), c_uint]) del_avector = get_func('del_avector', None, [PTR(CStructAVector)])
from ctypes import POINTER as PTR from ctypes import c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructCluster, CStructClusterGeometry # ------------------------ CStructClusterGeometry._fields_ = [ ('dim', c_uint), ('nidx', c_uint), ('x', PTR(PTR(real))), ('smin', PTR(PTR(real))), ('smax', PTR(PTR(real))), ('w', PTR(real)), ('hmin', PTR(real)), ('hmax', PTR(real)), ('buf', PTR(real)), ] # ------------------------ new_clustergeometry = get_func('new_clustergeometry', PTR(CStructClusterGeometry), [c_uint, c_uint]) del_clustergeometry = get_func('del_clustergeometry', None, [PTR(CStructClusterGeometry)]) update_point_bbox_clustergeometry = get_func( 'update_point_bbox_clustergeometry', None, [PTR(CStructClusterGeometry), c_uint, PTR(c_uint)])
from ctypes import POINTER as PTR from ctypes import c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructSingQuad2d, CStructSurface3d # ------------------------ CStructSingQuad2d._fields_ = [ ('x_id', PTR(real)), ('y_id', PTR(real)), ('w_id', PTR(real)), ('base_id', real), ('n_id', c_uint), ('x_edge', PTR(real)), ('y_edge', PTR(real)), ('w_edge', PTR(real)), ('base_edge', real), ('n_edge', c_uint), ('x_vert', PTR(real)), ('y_vert', PTR(real)), ('w_vert', PTR(real)), ('base_vert', real), ('n_vert', c_uint), ('x_dist', PTR(real)), ('y_dist', PTR(real)), ('w_dist', PTR(real)), ('base_dist', real), ('n_dist', c_uint), ('x_single', PTR(real)),
from ctypes import POINTER as PTR from ctypes import c_uint from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructPatEntry, CStructSparsePattern # ------------------------ CStructSparsePattern._fields_ = [ ('rows', c_uint), ('cols', c_uint), ('row', PTR(PTR(CStructPatEntry))), ] CStructPatEntry._fields_ = [('row', c_uint), ('col', c_uint), ('next', PTR(CStructPatEntry))] # ------------------------ new_sparsepattern = get_func('new_sparsepattern', PTR(CStructSparsePattern), [c_uint, c_uint]) del_sparsepattern = get_func('del_sparsepattern', None, [PTR(CStructSparsePattern)]) clear_sparsepattern = get_func('clear_sparsepattern', None, [PTR(CStructSparsePattern)]) addnz_sparsepattern = get_func('addnz_sparsepattern', None, [PTR(CStructSparsePattern), c_uint, c_uint]) print_sparsepattern = get_func('print_sparsepattern', None, [PTR(CStructSparsePattern)])
from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructMacroSurface3d, CStructSurface3d # ------------------------ CFuncPhi = CFUNCTYPE(None, *(c_uint, real, real, c_void_p, real * 3)) # ------------------------ CStructMacroSurface3d._fields_ = [ ('vertices', c_uint), ('edges', c_uint), ('triangles', c_uint), ('x', PTR(real * 3)), ('e', PTR(c_uint * 2)), ('t', PTR(c_uint * 3)), ('s', PTR(c_uint * 3)), ('phi', CFuncPhi), ('phidata', c_void_p), ] # ------------------------ new_macrosurface3d = get_func('new_macrosurface3d', PTR(CStructMacroSurface3d), [c_uint, c_uint, c_uint]) del_macrosurface3d = get_func('del_macrosurface3d', None, [PTR(CStructMacroSurface3d)]) new_sphere_macrosurface3d = get_func('new_sphere_macrosurface3d', PTR(CStructMacroSurface3d), [])
CStructRkMatrix) # ------------------------ CStructRkMatrix._fields_ = [ ('A', CStructAMatrix), ('B', CStructAMatrix), ('k', c_uint), ] # ------------------------ init_rkmatrix = get_func('init_rkmatrix', PTR(CStructRkMatrix), [PTR(CStructRkMatrix), c_uint, c_uint, c_uint]) init_sub_rkmatrix = get_func('init_sub_rkmatrix', PTR(CStructRkMatrix), [PTR(CStructRkMatrix), PTR(CStructRkMatrix), c_uint, c_uint, c_uint, c_uint]) uninit_rkmatrix = get_func('uninit_rkmatrix', None, [PTR(CStructRkMatrix)]) new_rkmatrix = get_func('new_rkmatrix', PTR(CStructRkMatrix), [c_uint, c_uint, c_uint]) new_sub_rkmatrix = get_func('new_sub_rkmatrix', PTR(CStructRkMatrix), [PTR(CStructRkMatrix), c_uint, c_uint, c_uint, c_uint]) del_rkmatrix = get_func('del_rkmatrix', None, [PTR(CStructRkMatrix)]) setrank_rkmatrix = get_func('setrank_rkmatrix', None, [PTR(CStructRkMatrix), c_uint]) resize_rkmatrix = get_func('resize_rkmatrix', None, [PTR(CStructRkMatrix), c_uint, c_uint, c_uint]) getsize_rkmatrix = get_func('getsize_rkmatrix', c_size_t, [PTR(CStructRkMatrix)]) getsize_heap_rkmatrix = get_func('getsize_heap_rkmatrix', c_size_t, [PTR(CStructRkMatrix)]) clone_rkmatrix = get_func('clone_rkmatrix', PTR(CStructRkMatrix), [PTR(CStructRkMatrix)]) copy_rkmatrix = get_func('copy_rkmatrix', None, [c_bool, PTR(CStructRkMatrix), PTR(CStructRkMatrix)]) scale_rkmatrix = get_func('scale_rkmatrix', None, [field, PTR(CStructRkMatrix)]) random_rkmatrix = get_func('random_rkmatrix', None, [PTR(CStructRkMatrix), c_uint]) addeval_rkmatrix_avector = get_func('addeval_rkmatrix_avector', None, [field, PTR(CStructRkMatrix), PTR(CStructAVector), PTR(CStructAVector)]) addevaltrans_rkmatrix_avector = get_func('addevaltrans_rkmatrix_avector', None, [field, PTR(CStructRkMatrix), PTR(CStructAVector), PTR(CStructAVector)])
from ctypes import POINTER as PTR from ctypes import c_uint, c_void_p from h2libpy.lib.krylov import CFuncAddevalT, CFuncPrcdT from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructDH2Matrix, CStructH2Matrix, CStructHMatrix, CStructSparseMatrix) # ------------------------ solve_cg_avector = get_func('solve_cg_avector', c_uint, [ c_void_p, CFuncAddevalT, PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_amatrix_avector = get_func('solve_cg_amatrix_avector', c_uint, [ PTR(CStructAMatrix), PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_sparsematrix_avector = get_func('solve_cg_sparsematrix_avector', c_uint, [ PTR(CStructSparseMatrix), PTR(CStructAVector), PTR(CStructAVector), real, c_uint ]) solve_cg_hmatrix_avector = get_func('solve_cg_hmatrix_avector', c_uint, [ PTR(CStructHMatrix), PTR(CStructAVector),
from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint, c_void_p from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructRealAVector # ------------------------ CStructRealAVector._fields_ = [('v', PTR(real)), ('dim', c_uint), ('owner', c_void_p)] # ------------------------ init_realavector = get_func('init_realavector', PTR(CStructRealAVector), [PTR(CStructRealAVector), c_uint]) init_sub_realavector = get_func( 'init_sub_realavector', PTR(CStructRealAVector), [PTR(CStructRealAVector), PTR(CStructRealAVector), c_uint, c_uint]) init_pointer_realavector = get_func( 'init_pointer_realavector', PTR(CStructRealAVector), [PTR(CStructRealAVector), PTR(real), c_uint]) uninit_realavector = get_func('uninit_realavector', None, [PTR(CStructRealAVector)]) new_realavector = get_func('new_realavector', PTR(CStructRealAVector), [c_uint]) new_sub_realavector = get_func('new_sub_realavector', PTR(CStructRealAVector), [PTR(CStructRealAVector), c_uint, c_uint]) new_pointer_realavector = get_func('new_pointer_realavector', PTR(CStructRealAVector),
from ctypes import POINTER as PTR from ctypes import c_bool, c_char_p, c_size_t, c_uint from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructCluster, CStructHMatrix, CStructRkMatrix, CStructSparseMatrix) # ------------------------ CStructHMatrix._fields_ = [ ('rc', PTR(CStructCluster)), ('cc', PTR(CStructCluster)), ('r', PTR(CStructRkMatrix)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructHMatrix))), ('rsons', c_uint), ('csons', c_uint), ('refs', c_uint), ('desc', c_uint), ] # ------------------------ init_hmatrix = get_func( 'init_hmatrix', PTR(CStructHMatrix), [PTR(CStructHMatrix), PTR(CStructCluster), PTR(CStructCluster)])
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructDBlock, CStructDCluster, CStructLevelDir) # ------------------------ CFuncAdmissible = CFUNCTYPE( c_bool, *(PTR(CStructDCluster), PTR(CStructDCluster), c_uint, PTR(c_uint), PTR(c_uint), c_void_p)) # ------------------------ CStructDBlock._fields_ = [ ('rc', PTR(CStructDCluster)), ('cc', PTR(CStructDCluster)), ('rd', c_uint), ('cd', c_uint), ('adm', c_bool), ('rsons', c_uint), ('csons', c_uint), ('son', PTR(PTR(CStructDBlock))), ('desc', c_uint), ] # ------------------------
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructCluster, CStructClusterBasis, CStructH2Matrix, CStructH2MatrixList, CStructHMatrix, CStructUniform) # ------------------------ CFuncH2MatrixCallbackT = CFUNCTYPE(None, *(PTR(CStructH2Matrix), c_uint, c_uint, c_uint, c_uint, c_void_p)) CFuncH2MatrixListCallbackT = CFUNCTYPE(None, *(PTR(CStructCluster), c_uint, c_uint, PTR(CStructH2MatrixList), c_void_p)) # ------------------------ CStructH2Matrix._fields_ = [ ('rb', PTR(CStructClusterBasis)), ('cb', PTR(CStructClusterBasis)), ('u', PTR(CStructUniform)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructH2Matrix))), ('rsons', c_uint), ('csons', c_uint), ('refs', c_uint),
from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t from h2libpy.lib.settings import field from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructClusterBasis, CStructClusterOperator, CStructRkMatrix, CStructUniform) # ------------------------ CStructUniform._fields_ = [ ('rb', PTR(CStructClusterBasis)), ('cb', PTR(CStructClusterBasis)), ('S', CStructAMatrix), ('rnext', PTR(CStructUniform)), ('rprev', PTR(CStructUniform)), ('cnext', PTR(CStructUniform)), ('cprev', PTR(CStructUniform)), ] # ------------------------ new_uniform = get_func('new_uniform', PTR(CStructUniform), [PTR(CStructClusterBasis), PTR(CStructClusterBasis)]) del_uniform = get_func('new_uniform', None, [PTR(CStructUniform)]) ref_row_uniform = get_func( 'ref_row_uniform', None, [PTR(CStructUniform), PTR(CStructClusterBasis)])
from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructCluster, CStructDCluster, CStructLevelDir) # ------------------------ CStructDCluster._fields_ = [ ('size', c_uint), ('idx', PTR(c_uint)), ('sons', c_uint), ('son', PTR(PTR(CStructDCluster))), ('dim', c_uint), ('bmin', PTR(real)), ('bmax', PTR(real)), ('directions', c_uint), ('dir', PTR(PTR(real))), ('dirson', PTR(PTR(c_uint))), ('desc', c_uint), ] CStructLevelDir._fields_ = [('depth', c_uint), ('dim', c_uint), ('maxdiam', PTR(real)), ('splits', PTR(c_uint)), ('directions', PTR(c_uint)), ('dir', PTR(PTR(PTR(real)))), ('dirmem', PTR(real))] # ------------------------
from ctypes import POINTER as PTR from ctypes import c_bool, c_char_p, c_uint from h2libpy.lib.settings import real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import CStructSurface3d # ------------------------ CStructSurface3d._fields_ = [ ('vertices', c_uint), ('edges', c_uint), ('triangles', c_uint), ('x', PTR(real * 3)), ('e', PTR(c_uint * 2)), ('t', PTR(c_uint * 3)), ('s', PTR(c_uint * 3)), ('n', PTR(real * 3)), ('g', PTR(real)), ('hmin', real), ('hmax', real) ] # ------------------------ new_surface3d = get_func('new_surface3d', PTR(CStructSurface3d), [c_uint, c_uint, c_uint]) prepare_surface3d = get_func('prepare_surface3d', None, [PTR(CStructSurface3d)]) del_surface3d = get_func('del_surface3d', None, [PTR(CStructSurface3d)])
class molfile_timestep_t(Structure): _fields_ = [('coords', PTR(c_float)), ('velocities', PTR(c_float)), ('A', c_float), ('B', c_float), ('C', c_float), ('alpha', c_float), ('beta', c_float), ('gamma', c_float), ('physical_time', c_double)]
from ctypes import POINTER as PTR from ctypes import c_uint from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructDCluster, CStructDClusterBasis, CStructDClusterOperator) # ------------------------ CStructDClusterOperator._fields_ = [ ('t', PTR(CStructDCluster)), ('krow', PTR(c_uint)), ('kcol', PTR(c_uint)), ('dir', c_uint), ('C', PTR(CStructAMatrix)), ('sons', c_uint), ('son', PTR(PTR(CStructDClusterOperator))), ('refs', c_uint), ] # ------------------------ init_dclusteroperator = get_func('init_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDClusterOperator), PTR(CStructDCluster)]) init_leaf_dclusteroperator = get_func('init_leaf_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDClusterOperator), PTR(CStructDCluster)]) uninit_dclusteroperator = get_func('uninit_dclusteroperator', None, [PTR(CStructDClusterOperator)]) new_dclusteroperator = get_func('new_dclusteroperator', PTR(CStructDClusterOperator), [PTR(CStructDCluster)]) ref_dclusteroperator = get_func('ref_dclusteroperator', None, [PTR(PTR(CStructDClusterOperator)), PTR(CStructDClusterOperator)])
def py_reg_cb(v, p): pc = p.contents if pc.type == MOLFILE_PLUGIN_TYPE: if pc.abiversion >= MIN_ABI_VERSION: plugin_p.contents = cast(p, PTR(molfile_plugin_t)).contents return VMDPLUGIN_SUCCESS
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_bool, c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructBlock, CStructDClusterBasis, CStructDClusterOperator, CStructDH2Matrix, CStructDUniform, CStructTruncMode) # ------------------------ CFuncDH2MatrixCallbackT = CFUNCTYPE( None, *(PTR(CStructDH2Matrix), c_uint, c_uint, c_uint, c_uint, c_void_p)) # ------------------------ CStructDH2Matrix._fields_ = [ ('rb', PTR(CStructDClusterBasis)), ('cb', PTR(CStructDClusterBasis)), ('u', PTR(CStructDUniform)), ('f', PTR(CStructAMatrix)), ('son', PTR(PTR(CStructDH2Matrix))), ('rsons', c_uint), ('csons', c_uint), ('desc', c_uint), ] # ------------------------
def inet_ntop(family, addrbytes): """converts raw bytes into IPv4 or IPv6 string""" addrstr = ctypes.create_string_buffer(80) # at least 46 bytes for IPv6 if not _inet_ntop(family, addrbytes, addrstr, ctypes.sizeof(addrstr)): raise ctypes.WinError(_WSAGetLastError()) return addrstr.value #=============================================================================== # WSASendTo #=============================================================================== _WSASendTo = winsockdll.WSASendTo _WSASendTo.argtypes = [ wintypes.HANDLE, # SOCKET s, PTR(WSABUF), # LPWSABUF lpBuffers, wintypes.DWORD, # DWORD dwBufferCount -- must be 1 PTR(wintypes.DWORD), # OUT LPDWORD lpNumberOfBytesSent -- must be NULL wintypes.DWORD, # DWORD dwFlags PTR(SockAddrIP4), # IN struct sockaddr *lpTo ctypes.c_int, # int iToLen PTR(OVERLAPPED), # IN LPWSAOVERLAPPED lpOverlapped wintypes. DWORD, # IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine -- must be NULL ] _WSASendTo.restype = ctypes.c_int # 0 means success def WSASendTo(hsock, data, sockaddr, overlapped, flags=0): """generic sendto (must pass a populated sockaddr object)""" buf = WSABUF(len(data), data)
import numpy as np import preprocess import opencl import lattice import config import os import dataset import stencil from ctypes import POINTER as PTR, c_byte, c_size_t, c_float speedup_ctypes = np.ctypeslib.load_library('speedup_ctypes.so', os.path.dirname(__file__)) speedup_ctypes.histogram.argtypes = [ PTR(c_byte), PTR(c_float), PTR(c_float), c_size_t, c_size_t, c_size_t, c_size_t ] def initialize(): b_width = [config.bounds[1][i] - config.bounds[0][i] for i in range(3)] global occ, vac, color, color_count, previous_estimate, good_alignment occ = np.zeros(b_width) > 0 vac = np.zeros(b_width) > 0 color = np.zeros((b_width[0], b_width[1], b_width[2], 3), 'u1') color_count = np.zeros(b_width, 'i') good_alignment = False previous_estimate = None
def _get_inner_overlapped(ov): addr = id(ov) + _get_overlapped_offset() return ctypes.cast(addr, PTR(OVERLAPPED)).contents
from ctypes import CFUNCTYPE from ctypes import POINTER as PTR from ctypes import c_size_t, c_uint, c_void_p from h2libpy.lib.settings import field, real from h2libpy.lib.util.helper import get_func from h2libpy.lib.util.structs import (CStructAMatrix, CStructAVector, CStructCluster, CStructClusterBasis, CStructClusterOperator, CStructUniform) # ------------------------ CFuncClusterBasisCallbackT = CFUNCTYPE( None, *(PTR(CStructClusterBasis), c_uint, c_void_p)) # ------------------------ CStructClusterBasis._fields_ = [('t', PTR(CStructCluster)), ('k', c_uint), ('ktree', c_uint), ('kbranch', c_uint), ('V', CStructAMatrix), ('E', CStructAMatrix), ('sons', c_uint), ('son', PTR(PTR(CStructClusterBasis))), ('Z', PTR(CStructAMatrix)), ('refs', c_uint), ('rlist', PTR(CStructUniform)), ('clist', PTR(CStructUniform))] # ------------------------ init_clusterbasis = get_func( 'init_clusterbasis', PTR(CStructClusterBasis), [PTR(CStructClusterBasis), PTR(CStructCluster)])