本文整理汇总了Python中numpy.ctypeslib.load_library函数的典型用法代码示例。如果您正苦于以下问题:Python load_library函数的具体用法?Python load_library怎么用?Python load_library使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_library函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_basic
def test_basic(self):
try:
# Should succeed
load_library("multiarray", np.core.multiarray.__file__)
except ImportError as e:
msg = "ctypes is not available on this python: skipping the test" " (import error was: %s)" % str(e)
print(msg)
开发者ID:nforro,项目名称:numpy,代码行数:7,代码来源:test_ctypeslib.py
示例2: test_basic2
def test_basic2(self):
# Regression for #801: load_library with a full library name
# (including extension) does not work.
try:
try:
so = get_shared_lib_extension(is_python_ext=True)
# Should succeed
load_library("multiarray%s" % so, np.core.multiarray.__file__)
except ImportError:
print("No distutils available, skipping test.")
except ImportError as e:
msg = "ctypes is not available on this python: skipping the test" " (import error was: %s)" % str(e)
print(msg)
开发者ID:nforro,项目名称:numpy,代码行数:13,代码来源:test_ctypeslib.py
示例3: __init__
def __init__(self, nx, ny):
self.nx = nx
self.ny = ny
self.nx_p = byref(c_int(nx))
self.ny_p = byref(c_int(ny))
# Load the library using numpy
libm = npct.load_library('my_math', './')
modname = 'my_math'
my_cos = getattr(libm, '__{}_MOD_{}'.format(modname, 'my_cos'))
my_cos_2d = getattr(libm, '__{}_MOD_{}'.format(modname, 'my_cos_2d'))
# Set the argument and return type
c_int_p = POINTER(c_int)
arr_1d_f8 = npct.ndpointer(ndim=1, dtype='f8')
my_cos.argtypes = (c_int_p, arr_1d_f8, arr_1d_f8)
my_cos.restype = None
arr_2d_f8 = npct.ndpointer(ndim=2, dtype='f8', flags='F')
my_cos_2d.argtypes = (c_int_p, c_int_p, arr_2d_f8, arr_2d_f8)
my_cos_2d.restype = None
# Set to public
self.libm = libm
self.my_cos = my_cos
self.my_cos_2d = my_cos_2d
开发者ID:wbkifun,项目名称:my_stuff,代码行数:28,代码来源:main.py
示例4: resize
def resize(img,scale):
"""
downsample img to scale
"""
sdims=img.shape
datatype=c_double
if img.dtype!=datatype:
print "Error the image must be of doubles!"
raise RuntimeError
if scale>1.0:
print "Invalid scaling factor!"
raise RuntimeError
img = asfortranarray(img,c_double) # make array continguous
try:
mresize = ctypeslib.load_library("libresize.so",".")
except:
print "Unable to load resize library"
raise RuntimeError
#use two times the 1d resize to get a 2d resize
fresize = mresize.resize1dtran
fresize.restype = None
fresize.argtypes = [ ctypeslib.ndpointer(dtype=datatype, ndim=3), c_int,ctypeslib.ndpointer(dtype=datatype, ndim=3), c_int, c_int , c_int ]
ddims = [int(round(sdims[0]*scale)),int(round(sdims[1]*scale)),sdims[2]];
mxdst = zeros((ddims), dtype=datatype)
tmp = zeros((ddims[0],sdims[1],sdims[2]), dtype=datatype)
img1=img
t1=time()
fresize(img1, sdims[0], tmp, ddims[0], sdims[1], sdims[2]);
fresize(tmp, sdims[1], mxdst, ddims[1], ddims[0], sdims[2]);
t2=time()
return mxdst.reshape(ddims[2],ddims[1],ddims[0]).T
开发者ID:ChrisYang,项目名称:CRFdet,代码行数:35,代码来源:resize.py
示例5: check_basic
def check_basic(self):
try:
cdll = load_library('multiarray',
np.core.multiarray.__file__)
except ImportError, e:
sys.stdout.write('S')
sys.stdout.flush()
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:7,代码来源:test_ctypeslib.py
示例6: call_histogram_integer
def call_histogram_integer(arr1, arr2, size1, size2, size3, location):
##################
# input type for the cos_doubles function
# must be an integer array, with single dimension that is contiguous
array_1d_int = npct.ndpointer(dtype=np.int64, ndim=1, flags='CONTIGUOUS')
# check the existence of the library
filename = location+"/histogram_integer.so"
status = os.path.isfile(filename)
if not(status):
print filename+' not found by call_histogram_integer'
return -1
# load the library, using numpy mechanisms
libcd = npct.load_library("histogram_integer", location)
# setup the return typs and argument types
libcd.histogram_integer.restype = None
libcd.histogram_integer.argtypes = [array_1d_int, array_1d_int, c_int, c_int, c_int,array_1d_int ]
n_ri = (size1*size2+size3+1)
ri = np.zeros(n_ri, dtype=np.int64)
libcd.histogram_integer(arr1, arr2, size1, size2, size3, ri )
return ri
开发者ID:lorenzo314,项目名称:pyxcosmo,代码行数:25,代码来源:call_histogram_integer.py
示例7: test_basic
def test_basic(self):
try:
cdll = load_library('multiarray',
np.core.multiarray.__file__)
except ImportError as e:
msg = "ctypes is not available on this python: skipping the test" \
" (import error was: %s)" % str(e)
print msg
开发者ID:MrBago,项目名称:numpy,代码行数:8,代码来源:test_ctypeslib.py
示例8: __init__
def __init__(self, dbname, host, user, password):
self.connect = "dbname=%s host=%s user=%s password=%s"%(dbname, host, user, password) #TODO Harcode
self.array_1d_double = npct.ndpointer(dtype=np.double, ndim=1, flags='CONTIGUOUS')
self.array_1d_int = npct.ndpointer(dtype=np.int64, ndim=1, flags='CONTIGUOUS')
self.array_2d_double = npct.ndpointer(dtype=np.double, ndim=2, flags='CONTIGUOUS')
#TODO path harcode
self.libcd = npct.load_library("cfsfdp", "/home/sergio/iibm/workspace/NeuroDB/NeuroDB/cfunctions/cfsfdp")
开发者ID:sergio2pi,项目名称:NeuroDB,代码行数:8,代码来源:sorter.py
示例9: lib
def lib(self, compiler=GNUCompiler()):
if self._lib is None:
with open(self.src_file, 'w') as f:
f.write(self.ccode)
compiler.compile(self.src_file, self.lib_file, self.log_file)
print("Compiled %s ==> %s" % ("random", self.lib_file))
self._lib = npct.load_library(self.lib_file, '.')
return self._lib
开发者ID:OceanPARCELS,项目名称:parcels,代码行数:8,代码来源:rng.py
示例10: _load_tipsy
def _load_tipsy():
"""Load the tipsy module. For internal use only """
if _load_tipsy.lib is not None:
return _load_tipsy.lib
lib = npct.load_library("libtipsy", "")
def decode_err(err):
if int(err) != 0:
raise IOError(lib.tipsy_strerror(err).decode('utf-8'))
# Force parameter type-checking and return-value error checking
lib.tipsy_strerror.restype = ctypes.c_char_p
lib.tipsy_strerror.argtypes = [ctypes.c_int]
lib.tipsy_py_init_reader_native.restype = decode_err
lib.tipsy_py_init_reader_native.argtypes = [ctypes.c_char_p]
lib.tipsy_py_init_writer_native.restype = decode_err
lib.tipsy_py_init_writer_native.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
lib.tipsy_py_destroy_native.restype = None
lib.tipsy_py_destroy_native.argtypes = []
lib.tipsy_py_read_header_native.restype = decode_err
lib.tipsy_py_read_header_native.argtypes = [ctypes.POINTER(tipsy_c.header.struct)]
lib.tipsy_py_read_gas_native.restype = decode_err
lib.tipsy_py_read_gas_native.argtypes = [ctypes.POINTER(tipsy_c.header.struct),
ctypes.POINTER(tipsy_c.gas_data.struct)]
lib.tipsy_py_read_dark_native.restype = decode_err
lib.tipsy_py_read_dark_native.argtypes = [ctypes.POINTER(tipsy_c.header.struct),
ctypes.POINTER(tipsy_c.dark_data.struct)]
lib.tipsy_py_read_star_native.restype = decode_err
lib.tipsy_py_read_star_native.argtypes = [ctypes.POINTER(tipsy_c.header.struct),
ctypes.POINTER(tipsy_c.star_data.struct)]
lib.tipsy_py_write_header_native.restype = decode_err
lib.tipsy_py_write_header_native.argtypes = [ctypes.POINTER(tipsy_c.header.struct)]
lib.tipsy_py_write_gas_native.restype = decode_err
lib.tipsy_py_write_gas_native.argtypes = [ctypes.POINTER(tipsy_c.gas_data.struct)]
lib.tipsy_py_write_dark_native.restype = decode_err
lib.tipsy_py_write_dark_native.argtypes = [ctypes.POINTER(tipsy_c.dark_data.struct)]
lib.tipsy_py_write_star_native.restype = decode_err
lib.tipsy_py_write_star_native.argtypes = [ctypes.POINTER(tipsy_c.star_data.struct)]
_load_tipsy.lib = lib
return lib
开发者ID:hainest,项目名称:jeans-disk,代码行数:53,代码来源:tipsy_native.py
示例11: load_DLL
def load_DLL(libname, path):
"""
Loads a model from a DLL file and returns it.
The filepath can be be both with or without file suffixes (as long as
standard file suffixes are used, that is).
Example inputs that should work:
>> lib = loadDLL('model')
>> lib = loadDLL('model.dll')
>> lib = loadDLL('model.so')
. All of the above should work on the JModelica supported platforms.
However, the first one is recommended as it is the most platform independent
syntax.
Parameters::
libname --
Name of the library without prefix.
path --
The relative or absolute path to the library.
See also http://docs.python.org/library/ct.html
"""
if sys.platform == 'win32':
# Temporarily add the value of 'path' to system library path in case the dll
# is dependent on other dlls. In that case they should be located in 'path'.
libpath = 'PATH'
if os.environ.has_key(libpath):
oldpath = os.environ[libpath]
else:
oldpath = None
if oldpath is not None:
newpath = path + os.pathsep + oldpath
else:
newpath = path
os.environ[libpath] = newpath
# Don't catch this exception since it hides the actual source
# of the error.
dll = Nct.load_library(libname, path)
if sys.platform == 'win32':
# Set back to the old path
if oldpath is not None:
os.environ[libpath] = oldpath
else:
del os.environ[libpath]
return dll
开发者ID:xogeny,项目名称:PyFMI,代码行数:52,代码来源:core.py
示例12: chi2_dist
def chi2_dist(X,Y=None,K=None):
if X.dtype==c_float:
datatype=c_float
else:
datatype=c_double
X = array(X,datatype).copy() # make array continguous
if Y==None:
Y=X
else:
Y = array(Y,datatype).copy()
n,dim = X.shape
m,dim = Y.shape
if (K==None):
K = empty( (n,m), datatype)
elif (K.shape != (n,m)):
K = empty( (n,m), datatype)
try:
chi2lib = ctypeslib.load_library("libchi2.so",".") # adapt path to library location
except:
print "Unable to load chi2-library"
raise RuntimeError
if X==Y:
if datatype==c_float:
chi2_routine = chi2lib.chi2_distance_float
else:
chi2_routine = chi2lib.chi2_distance_double
chi2_routine.restype = datatype
chi2_routine.argtypes = [c_int, \
c_int, ctypeslib.ndpointer(dtype=datatype, ndim=2, flags='C_CONTIGUOUS'), \
c_int, ctypeslib.ndpointer(dtype=datatype, ndim=2, flags='C_CONTIGUOUS'), \
ctypeslib.ndpointer(dtype=datatype, ndim=2, flags='C_CONTIGUOUS') ]
meanK = chi2_routine(dim, n, X, m, Y, K)
else:
if datatype==c_float:
chi2_routine = chi2lib.chi2sym_distance_float
else:
chi2_routine = chi2lib.chi2sym_distance_double
chi2_routine.restype = datatype
chi2_routine.argtypes = [c_int, \
c_int, ctypeslib.ndpointer(dtype=datatype, ndim=2, flags='C_CONTIGUOUS'), \
ctypeslib.ndpointer(dtype=datatype, ndim=2, flags='C_CONTIGUOUS') ]
meanK = chi2_routine(dim, n, X, K)
return K,meanK
开发者ID:antran89,项目名称:BoW_frameworks,代码行数:50,代码来源:chi2.py
示例13: test_basic2
def test_basic2(self):
"""Regression for #801: load_library with a full library name
(including extension) does not work."""
try:
try:
from distutils import sysconfig
so = sysconfig.get_config_var("SO")
cdll = load_library("multiarray%s" % so, np.core.multiarray.__file__)
except ImportError:
print "No distutils available, skipping test."
except ImportError, e:
msg = "ctypes is not available on this python: skipping the test" " (import error was: %s)" % str(e)
print msg
开发者ID:hadesain,项目名称:robothon,代码行数:14,代码来源:test_ctypeslib.py
示例14: test_basic2
def test_basic2(self):
"""Regression for #801: load_library with a full library name
(including extension) does not work."""
try:
try:
so = get_shared_lib_extension(is_python_ext=True)
cdll = load_library('multiarray%s' % so,
np.core.multiarray.__file__)
except ImportError:
print "No distutils available, skipping test."
except ImportError as e:
msg = "ctypes is not available on this python: skipping the test" \
" (import error was: %s)" % str(e)
print msg
开发者ID:MrBago,项目名称:numpy,代码行数:14,代码来源:test_ctypeslib.py
示例15: _load_fast3tree_lib
def _load_fast3tree_lib(dim):
mytype = np.dtype([('idx', np.int64), ('pos', _float_dtype, dim)], align=True)
mytype_ctype = C.ndpointer(mytype, ndim=1, flags='C,A')
center_ctype = C.ndpointer(dtype=_float_dtype, ndim=1, shape=(dim,), flags='C,A')
box_ctype = C.ndpointer(dtype=_float_dtype, ndim=2, shape=(2,dim), flags='C,A')
tree_ptr_ptr = C.ndpointer(dtype=_ptr_dtype, ndim=1, shape=(1,), flags='C,A')
c_lib = C.load_library('fast3tree_%dd'%(dim), __path__[0])
c_lib.fast3tree_init.restype = _ptr_ctype
c_lib.fast3tree_init.argtypes = [C.ctypes.c_int64, mytype_ctype]
c_lib.fast3tree_rebuild.restype = None
c_lib.fast3tree_rebuild.argtypes = [_ptr_ctype, C.ctypes.c_int64, mytype_ctype]
c_lib.fast3tree_maxmin_rebuild.restype = None
c_lib.fast3tree_maxmin_rebuild.argtypes = [_ptr_ctype]
c_lib.fast3tree_free.restype = None
c_lib.fast3tree_free.argtypes = [tree_ptr_ptr]
c_lib.fast3tree_results_init.restype = _ptr_ctype
c_lib.fast3tree_results_init.argtypes = None
c_lib.fast3tree_find_sphere.restype = None
c_lib.fast3tree_find_sphere.argtypes = [_ptr_ctype, _ptr_ctype, center_ctype, _float_ctype]
c_lib.fast3tree_find_sphere_periodic.restype = C.ctypes.c_int
c_lib.fast3tree_find_sphere_periodic.argtypes = [_ptr_ctype, _ptr_ctype, center_ctype, _float_ctype]
c_lib.fast3tree_find_inside_of_box.restype = None
c_lib.fast3tree_find_inside_of_box.argtypes = [_ptr_ctype, _ptr_ctype, box_ctype]
c_lib.fast3tree_find_outside_of_box.restype = None
c_lib.fast3tree_find_outside_of_box.argtypes = [_ptr_ctype, _ptr_ctype, box_ctype]
c_lib.fast3tree_results_clear.restype = None
c_lib.fast3tree_results_clear.argtypes = [_ptr_ctype]
c_lib.fast3tree_results_free.restype = None
c_lib.fast3tree_results_free.argtypes = [_ptr_ctype]
c_lib.fast3tree_set_minmax.restype = None
c_lib.fast3tree_set_minmax.argtypes = [_ptr_ctype, _float_ctype, _float_ctype]
c_lib.fast3tree_find_next_closest_distance.restype = _float_ctype
c_lib.fast3tree_find_next_closest_distance.argtypes = [_ptr_ctype, _ptr_ctype, center_ctype]
return c_lib, mytype
开发者ID:andrew-zentner,项目名称:halotools,代码行数:49,代码来源:__init__.py
示例16: load
def load(soname):
"""
Load a compiled shared object.
Parameters
----------
soname : str
Name of the .so file (w/o the suffix).
Returns
-------
obj
The loaded shared object.
"""
return npct.load_library(str(get_jit_dir().joinpath(soname)), '.')
开发者ID:opesci,项目名称:devito,代码行数:15,代码来源:compiler.py
示例17: check_basic2
def check_basic2(self):
"""Regression for #801: load_library with a full library name
(including extension) does not work."""
try:
try:
from distutils import sysconfig
so = sysconfig.get_config_var('SO')
cdll = load_library('multiarray%s' % so,
np.core.multiarray.__file__)
except ImportError:
sys.stdout.write('S')
sys.stdout.flush()
except ImportError, e:
sys.stdout.write('S')
sys.stdout.flush()
开发者ID:mbentz80,项目名称:jzigbeercp,代码行数:15,代码来源:test_ctypeslib.py
示例18: subwindow_search_pyramid
def subwindow_search_pyramid(numpoints, width, height, xpos, ypos, clstid, numbins, numlevels, weights):
"""Subwindow search for best box with bag-of-words histogram with a spatial
pyramid kernel."""
pyramidlib = load_library("libess.so",".")
pyramidlib.pyramid_search.restype = Box_struct
pyramidlib.pyramid_search.argtypes = [c_int,c_int,c_int,
ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS'),
ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS'),
ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS'),
c_int, c_int,
ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS')]
box = pyramidlib.pyramid_search(numpoints, width, height,
xpos, ypos, clstid, numbins, numlevels, weights)
return box
开发者ID:SarahMohamed,项目名称:ESS,代码行数:16,代码来源:ESS.py
示例19: ratemap
def ratemap(x, fs, lowcf=50.0, highcf=3500.0, numchans=32, frameshift=10.0,
ti=8.0, compression='cuberoot'):
"""
Python wrapper for ratemap.c
% ratemap = ratemap(x,fs,lowcf,highcf,numchans,frameshift,ti,compression)
%
% x input signal
% fs sampling frequency in Hz
% lowcf centre frequency of lowest filter in Hz (50)
% highcf centre frequency of highest filter in Hz (3500)
% numchans number of channels in filterbank (32)
% frameshift interval between successive frames in ms (10)
% ti temporal integration in ms (8)
% compression type of compression ['cuberoot','log','none'] ('cuberoot')
"""
numsamples = len(x)
xarray_type = ndpointer(float, flags='aligned, contiguous')
oarray_type = ndpointer(float, ndim=2, flags='aligned, contiguous, writeable')
carray_type = ctypes.c_char * len(compression)
frameshift_samples = get_round(frameshift * float(fs) / 1000)
numframes = int(math.ceil(numsamples / float(frameshift_samples)))
x = require(x, float, ['CONTIGUOUS', 'ALIGNED'])
result = empty((numframes, numchans), dtype=float)
program_dirname = os.path.dirname(os.path.realpath(__file__))
_libratemap = load_library('libratemap', program_dirname)
_libratemap.ratemap.argtypes = (
xarray_type, ctypes.c_int, ctypes.c_int, ctypes.c_double, ctypes.c_double,
ctypes.c_int, ctypes.c_double, ctypes.c_double, ctypes.POINTER(ctypes.c_char), oarray_type)
_libratemap.ratemap.restype = None
_libratemap.ratemap(x, ctypes.c_int(numsamples), ctypes.c_int(fs),
ctypes.c_double(lowcf), ctypes.c_double(highcf), ctypes.c_int(numchans),
ctypes.c_double(frameshift),
ctypes.c_double(ti), carray_type(*compression), result)
return result
开发者ID:rikrd,项目名称:python_ratemap,代码行数:41,代码来源:__init__.py
示例20: gammatone
def gammatone(x, fs, cf, hrect=False):
"""
Python wrapper for gammatone.c
% bm, env, instp, instf = gammatone_c(x, fs, cf, hrect)
%
% x - input signal
% fs - sampling frequency (Hz)
% cf - centre frequency of the filter (Hz)
% hrect - half-wave rectifying if hrect = True (default False)
%
% bm - basilar membrane displacement
% env - instantaneous envelope
% instp - instantaneous phase (unwrapped radian)
% instf - instantaneous frequency (Hz)
"""
numsamples = len(x)
xarray_type = ndpointer(float, flags='aligned, contiguous')
oarray_type = ndpointer(float, flags='aligned, contiguous, writeable')
x = require(x, float, ['CONTIGUOUS', 'ALIGNED'])
bm = empty_like(x)
env = empty_like(x)
instp = empty_like(x)
instf = empty_like(x)
program_dirname = os.path.dirname(os.path.realpath(__file__))
_libratemap = load_library('libratemap', program_dirname)
_libratemap.gammatone.argtypes = (
xarray_type, ctypes.c_int,
ctypes.c_int, ctypes.c_double, ctypes.c_int,
oarray_type, oarray_type,
oarray_type, oarray_type)
_libratemap.gammatone.restype = None
_libratemap.gammatone(x, ctypes.c_int(numsamples),
ctypes.c_int(fs), ctypes.c_double(cf), ctypes.c_int(hrect),
bm, env, instp, instf)
return bm, env, instp, instf
开发者ID:rikrd,项目名称:python_ratemap,代码行数:41,代码来源:__init__.py
注:本文中的numpy.ctypeslib.load_library函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论