本文整理汇总了Python中pyximport.install函数的典型用法代码示例。如果您正苦于以下问题:Python install函数的具体用法?Python install怎么用?Python install使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了install函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_spline_data
def write_spline_data():
"""Precompute spline coefficients and save them to data files that
are #included in the remaining c source code. This is a little devious.
"""
import scipy.special
import pyximport
pyximport.install(setup_args={"include_dirs": [np.get_include()]})
sys.path.insert(0, "src/vonmises")
import buildspline
del sys.path[0]
n_points = 1024
miny, maxy = 1e-5, 700
y = np.logspace(np.log10(miny), np.log10(maxy), n_points)
x = scipy.special.iv(1, y) / scipy.special.iv(0, y)
# fit the inverse function
derivs = buildspline.createNaturalSpline(x, np.log(y))
if not os.path.exists("src/vonmises/data/inv_mbessel_x.dat"):
np.savetxt("src/vonmises/data/inv_mbessel_x.dat", x, newline=",\n")
if not os.path.exists("src/vonmises/data/inv_mbessel_y.dat"):
np.savetxt("src/vonmises/data/inv_mbessel_y.dat", np.log(y), newline=",\n")
if not os.path.exists("src/vonmises/data/inv_mbessel_deriv.dat"):
np.savetxt("src/vonmises/data/inv_mbessel_deriv.dat", derivs, newline=",\n")
开发者ID:rbharath,项目名称:mixtape,代码行数:25,代码来源:setup.py
示例2: cython_pyximport
def cython_pyximport(self, line, cell):
"""Compile and import a Cython code cell using pyximport.
The contents of the cell are written to a `.pyx` file in the current
working directory, which is then imported using `pyximport`. This
magic requires a module name to be passed::
%%cython_pyximport modulename
def f(x):
return 2.0*x
The compiled module is then imported and all of its symbols are
injected into the user's namespace. For most purposes, we recommend
the usage of the `%%cython` magic.
"""
module_name = line.strip()
if not module_name:
raise ValueError('module name must be given')
fname = module_name + '.pyx'
with io.open(fname, 'w', encoding='utf-8') as f:
f.write(cell)
if 'pyximport' not in sys.modules:
import pyximport
pyximport.install(reload_support=True)
if module_name in self._reloads:
module = self._reloads[module_name]
reload(module)
else:
__import__(module_name)
module = sys.modules[module_name]
self._reloads[module_name] = module
self._import_all(module)
开发者ID:DamianHeard,项目名称:ipython,代码行数:32,代码来源:cythonmagic.py
示例3: __init__
def __init__(self, call=None, *args):
# Delay import until use of class instance. We were getting some very
# odd build-as-we-go errors running tests and documentation otherwise
import pyximport
pyximport.install()
try:
ext = os.path.splitext(call)[1].lower()
print('ext', ext)
if ext == '.py' or ext == '.pyx': # python/cython file
print('profiling python/cython file ...')
subprocess.call(['python', '-m', 'cProfile',
'-o', 'profile.prof', call])
s = pstats.Stats('profile.prof')
stats = s.strip_dirs().sort_stats('time')
self.stats = stats
except:
print('profiling function call ...')
self.args = args
self.call = call
cProfile.runctx('self._profile_function()', globals(), locals(),
'profile.prof')
s = pstats.Stats('profile.prof')
stats = s.strip_dirs().sort_stats('time')
self.stats = stats
开发者ID:MPDean,项目名称:dipy,代码行数:29,代码来源:profile.py
示例4: test_cython_quicksort
def test_cython_quicksort(self):
import pyximport; pyximport.install()
import quick_cython
l = [5, 1, 3, 5, 2]
self.assertEqual(sorted(l), quick_cython.quicksort(l))
开发者ID:Anamaria01,项目名称:meetups,代码行数:7,代码来源:test_quicksort.py
示例5: install_pyx
def install_pyx():
try:
import pyximport
log.info('Gearing up with Cython')
pyximport.install()
except Exception, e:
log.info(e)
开发者ID:dmangame,项目名称:dmangame,代码行数:7,代码来源:main.py
示例6: test_hamming_speed_01
def test_hamming_speed_01():
import time
#Importing cython module:
import pyximport; pyximport.install()
import hamming_cython
num_peptide = 1000
protein_length = 1000
peptide_list = get_peptide_list_random(n=num_peptide)
protein_seq = get_protein_seq_random(protein_length=protein_length)
xi = time.time()
match_list = get_match_list(peptide_list, protein_seq, sim_fraction_cutoff=0.5)
xj = time.time()
dx = xj-xi
print ['%.2fs' % dx, 'num_peptide=',num_peptide, 'protein_length=',protein_length, 'len(match_list)', len(match_list)]
#print match_list[0:5]
xi = time.time()
match_list = hamming_cython.get_match_list_cython(peptide_list, protein_seq, 0.5)
xj = time.time()
dx = xj-xi
print ['%.2fs' % dx, 'num_peptide=',num_peptide, 'protein_length=',protein_length, 'len(match_list)', len(match_list)]
#print match_list[0:5]
xi = time.time()
match_list = hamming_cython.get_match_list_numpy(peptide_list, protein_seq, 0.5)
xj = time.time()
dx = xj-xi
print ['%.2fs' % dx, 'num_peptide=',num_peptide, 'protein_length=',protein_length, 'len(match_list)', len(match_list)]
开发者ID:ykimbiology,项目名称:kim2013-positional-bias,代码行数:31,代码来源:bruteforce_cython.py
示例7: call
def call(self, fun, arg=list()):
'''
Call a function in the load path.
'''
name = fun[:fun.rindex('.')]
try:
fn_, path, desc = imp.find_module(name, self.module_dirs)
mod = imp.load_module(name, fn_, path, desc)
except ImportError:
if self.opts.get('cython_enable', True) is True:
# The module was not found, try to find a cython module
try:
import pyximport
pyximport.install()
for mod_dir in self.module_dirs:
for fn_ in os.listdir(mod_dir):
if name == fn_[:fn_.rindex('.')]:
# Found it, load the mod and break the loop
mod = pyximport.load_module(
name, os.path.join(mod_dir, fn_)
)
return getattr(
mod, fun[fun.rindex('.') + 1:])(*arg)
except ImportError:
log.info("Cython is enabled in options though it's not "
"present in the system path. Skipping Cython "
"modules.")
return getattr(mod, fun[fun.rindex('.') + 1:])(*arg)
开发者ID:akoumjian,项目名称:salt,代码行数:29,代码来源:loader.py
示例8: load_matrix
def load_matrix(f):
if not f.endswith('.bin'):
f += ".bin"
import pyximport
pyximport.install(setup_args={"include_dirs": np.get_include()})
from representations import sparse_io
return sparse_io.retrieve_mat_as_coo(f).tocsr()
开发者ID:clear-datacenter,项目名称:socialsent,代码行数:7,代码来源:matrix_serializer.py
示例9: test_cython2_quicksort
def test_cython2_quicksort(self):
import pyximport; pyximport.install()
import quick_cython_2
l = [3, 2, 5, 1, 2, 5]
quick_cython_2.quicksort(l)
self.assertEqual(sorted(l), l)
开发者ID:Anamaria01,项目名称:meetups,代码行数:8,代码来源:test_quicksort.py
示例10: benchmark
def benchmark(v, pyx, b='b'):
# write each .pyx iteration
with open('faster_hash_v{}.pyx'.format(v), mode='w') as f:
f.write(pyx)
# install .pyx
pyximport.install()
# timeit
print('v{}:'.format(v), timeit.timeit('fnv1a(b)', setup='from faster_hash_v{v} import fnv1a; b = {b}"{u}"'.format(v=v, u=u, b=b)))
开发者ID:xiachufang,项目名称:faster-hash,代码行数:8,代码来源:benchmark.py
示例11: init
def init():
global _initialized
if not _initialized:
pyximport.install(
setup_args = {
'include_dirs': [np.get_include()]
}
)
_initialized = True
开发者ID:EtiennePerot,项目名称:3D-Models-automaton,代码行数:9,代码来源:pyxinit.py
示例12: test_PyDecay
def test_PyDecay():
import pyximport
pyximport.install()
from _cvodes_anyode import PyDecay
pd = PyDecay(1.0)
tout, yout = pd.adaptive(1.0, 1.0)
for t, y in zip(tout, yout):
assert abs(y - exp(-t)) < 1e-9
开发者ID:bjodah,项目名称:pycvodes,代码行数:9,代码来源:_test_cvodes_anyode.py
示例13: test_PyDecay_mxsteps
def test_PyDecay_mxsteps():
import pyximport
pyximport.install()
from _odeint_anyode import PyDecay
import pytest
pd = PyDecay(1.0)
with pytest.raises(Exception):
tout, yout = pd.adaptive(1.0, 1.0, mxsteps=1)
开发者ID:bjodah,项目名称:pyodeint,代码行数:9,代码来源:_test_odeint_anyode.py
示例14: fit_transform
def fit_transform(self, X:Union[csr_matrix, memmap],
n_docs_distribution,
n_jobs=1,
verbose=False,
joblib_backend='multiprocessing',
use_cython:bool=False):
"""Main method of PMI class.
"""
assert isinstance(X, (memmap, csr_matrix))
assert isinstance(n_docs_distribution, numpy.ndarray)
matrix_size = X.shape
sample_range = list(range(0, matrix_size[0]))
feature_range = list(range(0, matrix_size[1]))
n_total_document = sum(n_docs_distribution)
logger.debug(msg='Start calculating PMI with n(process)={}'.format(n_jobs))
logger.debug(msg='size(input_matrix)={} * {}'.format(X.shape[0], X.shape[1]))
if use_cython:
import pyximport; pyximport.install()
from DocumentFeatureSelection.pmi.pmi_cython import main
logger.warning(msg='n_jobs parameter is invalid when use_cython=True')
pmi_score_csr_source = main(X=X,
n_docs_distribution=n_docs_distribution,
sample_range=sample_range,
feature_range=feature_range,
n_total_doc=n_total_document,
verbose=False)
else:
self.pmi = pmi
pmi_score_csr_source = joblib.Parallel(n_jobs=n_jobs, backend=joblib_backend)(
joblib.delayed(self.docId_word_PMI)(
X=X,
n_docs_distribution=n_docs_distribution,
feature_index=feature_index,
sample_index=sample_index,
n_total_doc=n_total_document,
verbose=verbose
)
for sample_index in sample_range
for feature_index in feature_range
)
row_list = [t[0] for t in pmi_score_csr_source]
col_list = [t[1] for t in pmi_score_csr_source]
data_list = [t[2] for t in pmi_score_csr_source]
pmi_featured_csr_matrix = csr_matrix((data_list, (row_list, col_list)),
shape=(X.shape[0],
X.shape[1]))
logging.debug(msg='End calculating PMI')
return pmi_featured_csr_matrix
开发者ID:Kensuke-Mitsuzawa,项目名称:DocumentFeatureSelection,代码行数:56,代码来源:PMI_python3.py
示例15: mu_q_method
def mu_q_method(e):
cython_header = 'import numpy as np\ncimport numpy as np\nctypedef np.double_t DTYPE_t\ncimport cython\n\[email protected](False)\[email protected](False)\[email protected](True)\ndef mu_q(%s):\n\tcdef double mu_q\n'
#@todo - for Cython cdef variables and generalize function def()
arg_values = {}
eps_arr = e
arg_values['e_arr'] = eps_arr
for name, theta_arr in zip(self.rand_var_names, self.theta_arrs):
arg_values[ '%s_flat' % name ] = theta_arr
arg_values.update(self._get_arg_values_dG())
def_dec = 'np.ndarray[DTYPE_t, ndim=1] '
def_dec += ', np.ndarray[DTYPE_t, ndim=1] '.join(arg_values)
cython_header = cython_header % def_dec
cython_header += ' cdef double '
cython_header += ', '.join(self.var_names) + ', eps, dG, q\n'
cython_header += ' cdef int i_'
cython_header += ', i_'.join(self.var_names) + '\n'
if self.cached_dG:
cython_header = cython_header.replace(r'1] dG_grid', r'%i] dG_grid' % self.n_rand_vars)
if self.compiled_eps_loop == False:
cython_header = cython_header.replace(r'np.ndarray[DTYPE_t, ndim=1] e_arr', r'double e_arr')
cython_header = cython_header.replace(r'eps,', r'eps = e_arr,')
cython_code = (cython_header + self.code).replace('\t', ' ')
cython_file_name = 'spirrid_cython.pyx'
regenerate_code = True
if os.path.exists(cython_file_name):
f_in = open(cython_file_name, 'r').read()
if f_in == cython_code:
regenerate_code = False
if regenerate_code:
infile = open('spirrid_cython.pyx', 'w')
infile.write(cython_code)
infile.close()
print 'pyx file updated'
import pyximport
pyximport.install(reload_support = True)
import spirrid_cython
if regenerate_code:
reload(spirrid_cython)
mu_q = spirrid_cython.mu_q
if self.compiled_eps_loop:
mu_q_arr = mu_q(**arg_values)
else:
# Python loop over eps
#
mu_q_arr = np.zeros_like(eps_arr)
for idx, e in enumerate(eps_arr):
# C loop over random dimensions
#
arg_values['e_arr'] = e # prepare the parameter
mu_q_val = mu_q(**arg_values)
# add the value to the return array
mu_q_arr[idx] = mu_q_val
return mu_q_arr, None
开发者ID:axelvonderheide,项目名称:scratch,代码行数:56,代码来源:code_gen_compiled.py
示例16: get_nv
def get_nv(neifile):
try:
import pyximport; pyximport.install()
import get_nv as gnv
neifile['nv']=gnv.get_nvc(neifile['neighbours'],neifile['nnodes'],neifile['maxnei'])
neifile['trigrid'] = mplt.Triangulation(neifile['lon'], neifile['lat'],neifile['nv'])
except:
print('There was an issue with during using cython falling back to python.')
nv=np.empty((len(neifile['neighbours'])*2,3))
neighbours=copy.deepcopy(neifile['neighbours'])
kk=0
for i in range(neifile['nnodes']-2):
nei_cnt=1
for ii in range(neifile['maxnei']-1):
if neighbours[i,ii+1]==0:
break
nei_cnt=ii+1
if neighbours[i,ii]<=(i+1):
continue
if neighbours[i,ii+1]<=(i+1):
continue
for j in range(neifile['maxnei']):
if neighbours[neighbours[i,ii]-1,j]!=neighbours[i,ii+1]:
continue
nv[kk,:]=[i+1,neighbours[i,ii],neighbours[i,ii+1]]
kk=kk+1
break
if (nei_cnt>1):
for j in range(neifile['maxnei']):
if neighbours[i,0]<=(i+1):
break
if neighbours[i,nei_cnt]<=(i+1):
break
if neighbours[neighbours[i,0]-1,j] ==0:
break
if neighbours[neighbours[i,0]-1,j] !=neighbours[i,nei_cnt]:
continue
nv[kk,:]=[i+1,neighbours[i,nei_cnt],neighbours[i,0] ]
kk=kk+1
break
nv=np.delete(nv,np.s_[kk:],axis=0)
neifile['nv']=(nv-1).astype(int)
neifile['trigrid'] = mplt.Triangulation(neifile['lon'], neifile['lat'],neifile['nv'])
return neifile
开发者ID:moflaher,项目名称:workspace_python,代码行数:54,代码来源:gridtools.py
示例17: load_module
def load_module(module_name, module_path):
"""Load the module named `module_name` from `module_path`
independently of the Python version."""
if sys.version_info >= (3,0):
import pyximport
pyximport.install()
sys.path.append(module_path)
return __import__(module_name)
else:
import imp
module_info = imp.find_module(module_name, [module_path])
return imp.load_module(module_name, *module_info)
开发者ID:stan-dev,项目名称:pystan,代码行数:12,代码来源:model.py
示例18: run
def run(word_gen, index, window_size, out_file):
context = []
pair_counts = Counter()
for word in word_gen:
context.append(index[word])
if len(context) > window_size * 2 + 1:
context.pop(0)
pair_counts = _process_context(context, pair_counts, window_size)
import pyximport
pyximport.install(setup_args={"include_dirs": np.get_include()})
from representations import sparse_io
sparse_io.export_mat_from_dict(pair_counts, out_file)
开发者ID:LinguList,项目名称:histwords,代码行数:12,代码来源:cooccurgen.py
示例19: scanfuncs
def scanfuncs(filename, prefixes, cython=False):
""" Return list of function names from ``filename`` that begin with prefix.
This *does not* import the Python file, so this is safe to use, but
functionality is limited to retrieving names of basic functions defined
within global scope of the file.
This *does*, however, import Cython files (if applicable).
"""
# Used by: findarenas, findbenchmarks
path, name = os.path.split(filename)
name, ext = os.path.splitext(name)
# Should `cython` be a keyword argument, or should we just infer it?
cython = cython or ext == '.pyx'
if not cython:
funcs = pyclbr.readmodule_ex(name, [path])
funcnames = []
for key, val in funcs.items():
if (any(key.startswith(prefix) for prefix in prefixes) and
val.file == filename):
funcnames.append(key)
return funcnames
# Scan Cython file. We need to import it.
import pyximport
pyximport.install()
sys.dont_write_bytecode = True
# Make sure local imports work for the given file
sys.path.insert(0, path)
pyximport.build_module(name, filename)
try:
mod = pyximport.load_module(name, filename)
except ImportError:
# There is most likely a '*.py' file that shares the same
# base name as the '*.pyx' file we are trying to import.
# Removing the directory from sys.path should fix this,
# but will disable local importing.
sys.path.pop(0)
mod = pyximport.load_module(name, filename)
# Undo making local imports work
if sys.path[0] == path:
sys.path.pop(0)
funcnames = []
for funcname in mod.__dict__:
if any(funcname.startswith(prefix) for prefix in prefixes):
funcnames.append(funcname)
return funcnames
开发者ID:eriknw,项目名称:benchtoolz,代码行数:47,代码来源:benchutils.py
示例20: compare_fingerprints
def compare_fingerprints(fp1, fp2, threshold = 5, optimize=False, CYTHON=False):
if optimize:
fp1, fp2 = remove_unmatched_hash_values(fp1, fp2)
fp1_hashes = [f[2] for f in fp1]
fp2_hashes = [f[2] for f in fp2]
if CYTHON:
try:
import pyximport; pyximport.install()
from cython_fingerprints import cython_match
except ImportError:
sys.exit('Cython does not appear to be properly configured on your system. Try comparing fingerprints using CYTHON=False')
match_results = cython_match(fp1, fp2, fp1_hashes, fp2_hashes, threshold)
else:
match_results = do_matching(fp1, fp2, fp1_hashes, fp2_hashes, threshold)
return match_results
开发者ID:bmd,项目名称:intertextuality-tool,代码行数:19,代码来源:compare_fingerprints.py
注:本文中的pyximport.install函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论