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
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))
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)
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)
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")
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()
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)]
def install_pyx(): try: import pyximport log.info('Gearing up with Cython') pyximport.install() except Exception, e: log.info(e)
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)))
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)
def init(): global _initialized if not _initialized: pyximport.install( setup_args = { 'include_dirs': [np.get_include()] } ) _initialized = True
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
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)
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
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
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
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)
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)
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
def main(): usage = "python profile.py <package>.<module>\n" if len(sys.argv) != 2: sys.stderr.write(usage) sys.exit(1) arg = sys.argv[1] if arg in entries: pyximport.install() command = entries[arg].__module__ + '.main()' cProfile.runctx(command, globals(), locals(), "Profile.prof") s = pstats.Stats("Profile.prof") s.strip_dirs().sort_stats("time").print_stats() else: sys.stderr.write("Invalid module `%s'.\n" % arg) sys.exit(1)
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
def BootstrapCython(id, base_dir='~'): """Bootstrap Cython compilation, with a process-specific build directory. The specified id will be used to uniquely identify this process. Using id's that are durable across restarts makes the bootstrapping process more efficient. Args: id - ID unique to this process. """ import shutil pyx_build_dir = os.path.expanduser('%s/.pyxbld-%s' % (base_dir, id)) # Clean up stale Cython pyximport state. if os.path.exists(pyx_build_dir): shutil.rmtree(pyx_build_dir) os.makedirs(pyx_build_dir) import pyximport pyximport.install(build_dir=pyx_build_dir)
def cyimport(import_path): """ Import a Cython module if available, otherwise return None (and skip any relevant tests). """ if HAVE_CYTHON: import pyximport py_importer, pyx_importer = pyximport.install() mod = __import__(import_path, fromlist=[True]) pyximport.uninstall(py_importer, pyx_importer) return mod
def run(self, argv): self.parse_args(argv) with logging.LogManager(self.runtime_settings): self.logger = logging.getLogger(__name__) if self.runtime_settings.dev_mode: import pyximport pyximport.install() for sig in (signal.SIGINT, signal.SIGTERM): self.event_loop.add_signal_handler( sig, functools.partial(self.handle_signal, sig)) try: self.event_loop.run_until_complete(self.run_async()) finally: self.event_loop.stop() self.event_loop.close() return self.returncode
def run(count_path, out_path, smooth=0, cds=True, normalize=False, neg=1): counts = create_representation("Explicit", count_path, normalize=False) old_mat = counts.m index = counts.wi smooth = old_mat.sum() * smooth # getting marginal probs row_probs = old_mat.sum(1) + smooth col_probs = old_mat.sum(0) + smooth if cds: col_probs = np.power(col_probs, 0.75) row_probs = row_probs / row_probs.sum() col_probs = col_probs / col_probs.sum() # building PPMI matrix ppmi_mat = make_ppmi_mat(old_mat, row_probs, col_probs, smooth, neg=neg, normalize=normalize) import pyximport pyximport.install(setup_args={"include_dirs": np.get_include()}) from representations import sparse_io sparse_io.export_mat_eff(ppmi_mat.row, ppmi_mat.col, ppmi_mat.data, out_path + ".bin") util.write_pickle(index, out_path + "-index.pkl")
def install(): global get_distutils_extension if not get_distutils_extension: old_get_distutils_extension = pyximport.pyximport.get_distutils_extension def get_distutils_extension(modname, pyxfilename, language_level=None): #logging.log("modname: %s" % modname, color="cyan") #logging.log("pyxfilename: %s" % pyxfilename, color="cyan") #logging.log("language_level: %s" % language_level, color="cyan") global extension_mod, setup_args extension_mod, setup_args = old_get_distutils_extension(modname, pyxfilename, language_level) #logging.log("extension_mod: %s" % extension_mod, color="cyan") #logging.log("setup_args: %s" % setup_args, color="cyan") #logging.log("extension_mod.language: %s" % extension_mod.language, color="cyan") #logging.log("extension_mod.extra_compile_args: %s" % extension_mod.extra_compile_args, color="cyan") #logging.log("extension_mod.include_dirs: %s" % extension_mod.include_dirs, color="cyan") extension_mod.language='c++' extension_mod.extra_compile_args.append('-std=c++11') extension_mod.include_dirs.append(os.path.dirname(pyxfilename)) if have_numpy: extension_mod.include_dirs.append(numpy.get_include()) extension_mod.extra_compile_args.append('-w') #extension_mod.extra_compile_args.append('-DNPY_NO_DEPRECATED_API=DNPY_1_7_API_VERSION') #extension_mod.extra_compile_args.append('-DNPY_NO_DEPRECATED_API') #extension_mod.extra_compile_args.append('-DNPY_1_7_API_VERSION') #extension_mod.extra_compile_args.append('-DCYTHON_TRACE=1') #extension_mod.define_macros.append( ('CYTHON_TRACE', '1') ) return extension_mod,setup_args pyximport.pyximport.get_distutils_extension = get_distutils_extension if sys.platform == 'linux2': # Omitting 'strict-prototypes' warning For Python 2.x opt = sysconfig.get_config_vars().get('OPT', '') opt = opt.replace('-Wstrict-prototypes', '') sysconfig.get_config_vars()['OPT'] = opt # Omitting 'strict-prototypes' warning For Python 3.x cflags = sysconfig.get_config_vars().get('CFLAGS', '') cflags = cflags.replace('-Wstrict-prototypes', '') sysconfig.get_config_vars()['CFLAGS'] = cflags #directive_defaults['binding'] = True #directive_defaults['linetrace'] = True pyximport.install()
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 or not self._pyximport_installed: import pyximport pyximport.install() self._pyximport_installed = True if module_name in self._reloads: module = self._reloads[module_name] # Note: reloading extension modules is not actually supported # (requires PEP-489 reinitialisation support). # Don't know why this should ever have worked as it reads here. # All we really need to do is to update the globals below. #reload(module) else: __import__(module_name) module = sys.modules[module_name] self._reloads[module_name] = module self._import_all(module)
def profile_scd_cy(self, xtr, ytr, xte, yte): import pstats import cProfile import pyximport pyximport.install() self.set_train_kernel(xtr) self.set_test_kernel(xtr, xte) self.ytr = ytr T = self.nsweep * self.n - 1 str = "coor_cy.scd_cy(ktr=self.ktr, ytr=self.ytr, kte=self.kte, yte=self.yte, lmda=self.lmda,\ nsweep=np.int(self.nsweep), T=int(T), batchsize=np.int(self.batchsize))" cProfile.runctx(str, globals(), locals(), "Profile.prof") s = pstats.Stats("Profile.prof") s.strip_dirs().sort_stats("time").print_stats() @staticmethod def tune_parameter(x, y, gmlist=[0.1], Clist=[1.0], algo_type='scg_da'): # cross validation to tweak the parameter n, p = x.shape err = np.zeros((len(gmlist), len(Clist))) kf = cv.KFold(n, n_folds=3) for train_ind, valid_ind in kf: xtrain = x[train_ind, :] ytrain = y[train_ind] ntrain = ytrain.size xvalid = x[valid_ind, :] yvalid = y[valid_ind] for i, gm in enumerate(gmlist): for j, C in enumerate(Clist): clf = DualKSVM(lmda=C / ntrain, gm=gm, kernelstr='rbf', rho=0.1, b=5, c=1, verbose=False, algo_type=algo_type) clf.fit(xtrain, ytrain) pred = clf.predict(xvalid) err[i, j] += zero_one_loss(pred, yvalid) row, col = np.unravel_index(err.argmin(), err.shape) return gmlist[row], Clist[col]
import os os.chdir('H:/Google Drive/trading/futures') # cython setup import pyximport pyximport.install(reload_support=True) import datetime import importlib import strategies.cstrategy importlib.reload(strategies.cstrategy) import strategies.cstrategy from vnpy.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting from vnpy.app.cta_strategy.strategies.atr_rsi_strategy import ( AtrRsiStrategy, ) # from datetime import datetime # from vnpy_extension.template import CustomTemplate import vnpy_extension.array_manager importlib.reload(vnpy_extension.array_manager) import vnpy_extension.template importlib.reload(vnpy_extension.template) # DualThrust = type('DualThrust', (vnpy_extension.template.CustomTemplate, ), { # 'strategies': [strategies.cstrategy.DUAL_THRUST( # n_days = 2, # fix_loss = 25, # upper_scale = 0.25, # lower_scale = 0.75
import os import sys from collections import defaultdict, OrderedDict from copy import deepcopy from operator import itemgetter, attrgetter import numpy as np import six from pythomics.proteomics.config import CARBON_NEUTRON from scipy import optimize from scipy.signal import convolve, kaiser if os.environ.get('PYQUANT_DEV', False) == 'True': try: import pyximport pyximport.install(setup_args={'include_dirs': np.get_include()}, reload_support=True) except Exception as e: import traceback traceback.print_exc() pass from pyquant.cpeaks import bigauss_func, gauss_func, bigauss_ndim, gauss_ndim, bigauss_jac,\ gauss_jac, find_nearest, find_nearest_index, get_ppm from . import PEAK_FINDING_REL_MAX, PEAK_FIT_MODE_AVERAGE, PEAK_FIT_MODE_FAST, PEAK_FIT_MODE_SLOW from .logger import logger from .utils import divide_peaks, find_possible_peaks, estimate_peak_parameters, interpolate_data, savgol_smooth if six.PY3: xrange = range _epsilon = np.sqrt(np.finfo(float).eps)
import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np import pyximport pyximport.install(setup_args = {'options' : {'build_ext' : {'libraries' : 'lapack', 'include_dirs' : np.get_include(), }}}) import voronoi_cython as voronoi if False: """ Plot periodic Voronoi diagram made using tiles method and overlay the center tile """ segments = voronoi.voronoi(100, periodic=True) center_tile = voronoi.periodic_voronoi(segments=segments) """ Plot all segments: """ fig = plt.figure(1) ax = fig.add_subplot(111) ax.cla() lines = mpl.collections.LineCollection(segments, color='0.75') ax.add_collection(lines) """ Overlay those that cross into the unit square centered on (0,0): """ goodlines = mpl.collections.LineCollection(center_tile, color='0.15') ax.add_collection(goodlines) """ Add a box from (0,0) to (1,1) to show boundaries """
def import_module(module): """This will try to import the passed module. This will return the module if it was imported, or will return 'None' if it should not be imported. Parameters ---------- module: str The name of the module to import """ from ._console import Console try: import importlib m = importlib.import_module(module) except SyntaxError as e: Console.error(f"\nSyntax error when importing {module}\n" f"{e.__class__.__name__}:{e}\n" f"Line {e.lineno}.{e.offset}:{(e.offset-1)*' '} |\n" f"Line {e.lineno}.{e.offset}:{(e.offset-1)*' '}\\|/\n" f"Line {e.lineno}.{e.offset}: {e.text}") m = None except ImportError: # this is ok and expected if the module is in a python file # that will be loaded below m = None except Exception: # something else went wrong m = None if m is None: try: import os if os.path.exists(module): pyfile = module elif os.path.exists(f"{module}.py"): pyfile = f"{module}.py" elif os.path.exists(f"{module}.pyx"): pyfile = f"{module}.pyx" else: pyfile = None if pyfile: from pathlib import Path as _Path module = _Path(pyfile).stem if pyfile.endswith(".pyx"): try: import pyximport pyfile = _clean_cython(pyfile) Console.print(f"Compiling cython plugin from {pyfile}") pyximport.install(language_level=3) m = pyximport.load_module(module, pyfile, language_level=3) Console.print(f"Loaded cython {module} from {pyfile}") except Exception as e: Console.error( f"Cannot compile and load the cython plugin " f"{pyfile}. Error is {e.__class__}: {e}") else: import importlib.util spec = importlib.util.spec_from_file_location( module, pyfile) if spec is None: raise ImportError( f"Cannot build a spec for the module from " f"the file {pyfile}") m = importlib.util.module_from_spec(spec) spec.loader.exec_module(m) Console.print(f"Loaded {module} from {pyfile}") except SyntaxError as e: Console.error( f"\nSyntax error when reading {pyfile}\n" f"{e.__class__.__name__}:{e}\n" f"Line {e.lineno}.{e.offset}:{(e.offset-1)*' '} |\n" f"Line {e.lineno}.{e.offset}:{(e.offset-1)*' '}\\|/\n" f"Line {e.lineno}.{e.offset}: {e.text}") except Exception as e: Console.error(f"\nError when importing {module}\n" f"{e.__class__.__name__}: {e}\n") m = None if m is not None: Console.print(f"IMPORT {m}") return m
# set up easy cython import import numpy as np import pyximport, os from distutils.extension import Extension ext_modules = [ Extension('_mandelbrot', ['_mandelbrot.pyx'], extra_compile_args=['-fopenmp', '-O3', '-march=native'], extra_link_args=['-fopenmp']) ] pyximport.install(setup_args={ "include_dirs": [np.get_include(), os.curdir], 'ext_modules': ext_modules }) from _mandelbrot import mandelbrot # a helpful timer class that can be used by the "with" statement import time class Timer(object): def __enter__(self): self.start = time.time() return self def __exit__(self, *args): self.end = time.time() self.interval = self.end - self.start # create coordinates, along with output count array def make_coords(center=(-0.575 - 0.575j), width=0.0025, count=4000):
def load_modules(self): ''' Loads all of the modules from module_dirs and returns a list of them ''' self.modules = [] log.trace('loading {0} in {1}'.format(self.tag, self.module_dirs)) names = {} disable = set(self.opts.get('disable_{0}s'.format(self.tag), [])) cython_enabled = False if self.opts.get('cython_enable', True) is True: try: import pyximport pyximport.install() cython_enabled = True except ImportError: log.info('Cython is enabled in the options but not present ' 'in the system path. Skipping Cython modules.') for mod_dir in self.module_dirs: if not os.path.isabs(mod_dir): log.trace( 'Skipping {0}, it is not an absolute path'.format(mod_dir)) continue if not os.path.isdir(mod_dir): log.trace( 'Skipping {0}, it is not a directory'.format(mod_dir)) continue for fn_ in os.listdir(mod_dir): if fn_.startswith('_'): # skip private modules # log messages omitted for obviousness continue if fn_.split('.')[0] in disable: log.trace( 'Skipping {0}, it is disabled by configuration'.format( fn_)) continue if (fn_.endswith(('.py', '.pyc', '.pyo', '.so')) or (cython_enabled and fn_.endswith('.pyx')) or os.path.isdir(os.path.join(mod_dir, fn_))): extpos = fn_.rfind('.') if extpos > 0: _name = fn_[:extpos] else: _name = fn_ names[_name] = os.path.join(mod_dir, fn_) else: log.trace('Skipping {0}, it does not end with an expected ' 'extension'.format(fn_)) for name in names: try: if names[name].endswith('.pyx'): # If there's a name which ends in .pyx it means the above # cython_enabled is True. Continue... mod = pyximport.load_module( '{0}.{1}.{2}.{3}'.format( self.loaded_base_name, self.mod_type_check(names[name]), self.tag, name), names[name], tempfile.gettempdir()) else: fn_, path, desc = imp.find_module(name, self.module_dirs) mod = imp.load_module( '{0}.{1}.{2}.{3}'.format(self.loaded_base_name, self.mod_type_check(path), self.tag, name), fn_, path, desc) # reload all submodules if necessary submodules = [ getattr(mod, sname) for sname in dir(mod) if isinstance(getattr(mod, sname), mod.__class__) ] # reload only custom "sub"modules i.e is a submodule in # parent module that are still available on disk (i.e. not # removed during sync_modules) for submodule in submodules: try: smname = '{0}.{1}.{2}'.format( self.loaded_base_name, self.tag, name) smfile = '{0}.py'.format( os.path.splitext(submodule.__file__)[0]) if submodule.__name__.startswith(smname) and \ os.path.isfile(smfile): reload(submodule) except AttributeError: continue except ImportError: log.debug( 'Failed to import {0} {1}, this is most likely NOT a ' 'problem:\n'.format(self.tag, name), exc_info=True) continue except Exception: log.error( 'Failed to import {0} {1}, this is due most likely to a ' 'syntax error. Traceback raised:\n'.format(self.tag, name), exc_info=True) continue self.modules.append(mod)
import pyximport import numpy as np import math pyximport.install(setup_args={'include_dirs': [np.get_include()]}, inplace=True) from _glcm_loop import _3d_glcm_vector_loop import profiling_tools """ Group 3 : Textural features (Class version) """ def glcm_vector_loop(volume, distance, dx, dy, dz, bin_width): bin_width = int(bin_width) volume = (volume / bin_width) * bin_width return _3d_glcm_vector_loop(volume, distance, dx, dy, dz) class GLCM_Matrices: def __init__(self, volume, bin_width): self.volume = volume self.bin_width = bin_width self.vectors = [[0, 1, 1], [-1, 1, 1], [-1, 0, 1], [-1, -1, 1],
from operator import itemgetter import dynet as dn import numpy as np from os.path import dirname import nn import pyximport pyximport.install(build_dir=dirname(__file__) + "/.cache/") from tagger_base.cviterbi import viterbi class ViterbiDecoder(nn.DynetSaveable): @classmethod def add_parser_arguments(cls, arg_parser): group = arg_parser.add_argument_group(cls.__name__) group.add_argument("--beam-size", dest="beam_size", type=int, default=None) def __init__(self, model, tag_dict, options): super(ViterbiDecoder, self).__init__(model) self.index_to_tag = tag_dict.int_to_word self.tag_to_index = tag_dict.word_to_int self.tag_count = len(self.index_to_tag) self.virtual_start = self.tag_count self.virtual_end = self.tag_count + 1
logger = logging.getLogger("gensim.models.word2vec") from gensim import utils, matutils # utility fnc for pickling, common scipy operations etc from six import iteritems, itervalues, string_types from six.moves import xrange try: from gensim_addons.models.word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION except ImportError: try: # try to compile and use the faster cython version import pyximport models_dir = os.path.dirname(__file__) or os.getcwd() pyximport.install(setup_args={"include_dirs": [models_dir, get_include()]}) from word2vec_inner import train_sentence_sg, train_sentence_cbow, FAST_VERSION except: # failed... fall back to plain numpy (20-80x slower training than the above) FAST_VERSION = -1 def train_sentence_sg(model, sentence, alpha, work=None): """ Update skip-gram model by training on a single sentence. The sentence is a list of Vocab objects (or None, where the corresponding word is not in the vocabulary. Called internally from `Word2Vec.train()`. This is the non-optimized, Python version. If you have cython installed, gensim will use the optimized version from word2vec_inner instead.
def _currentPath(self): if self.__path == "": self.__path = j.sal.fs.getDirName(inspect.getsourcefile(self.__init__)) sys.path.append(self.__path) pyximport.install() return self.__path
#!/usr/bin/env python import time import py_primes import numba_primes import pyximport pyximport.install() # <1> import cy_primes # <2> NUM_PRIMES = 50000 # <3> for mod in numba_primes, cy_primes, py_primes: # <4> timestamp = time.time() # <5> prime_list = mod.get_primes(NUM_PRIMES) # <6> timestamp2 = time.time() # <7> elapsed = timestamp2 - timestamp # <8> print(prime_list[:20], prime_list[-20:]) print("{} took {:.3f} seconds to find {} primes".format( mod.__name__, elapsed, len(prime_list))) # <9> print()
import os import numpy as np import pyximport from sidetopics.model.common import DataSet from os.path import dirname, realpath from distutils.core import setup os.environ['CC'] = os.environ['HOME'] + '/bin/cc' pyximport.install( \ build_in_temp=False, \ inplace=True, \ build_dir=dirname(dirname(realpath(__file__))) + '/lib', \ setup_args={ \ 'include_dirs': np.get_include(), \ 'libraries': [('m', dict()), ('gomp', dict()), ('gsl', dict()), ('gslcblas', dict())], \ 'extra_compile_args': '-fopenmp' }, \ reload_support=True)
import sys, time, datetime, copy, subprocess, itertools, pickle, warnings, numbers import numpy as np import scipy as sp import pandas as pd from matplotlib import pyplot as plt import matplotlib as mpl import matplotlib.gridspec as gridspec from scipy.special import gamma, digamma from .tools import Quasi_Newton, merge_stg, loglinear_COS, plinear try: import pyximport pyximport.install(setup_args={'include_dirs': np.get_include()}, language_level=2) from .Hawkes_C import LG_kernel_SUM_exp_cython, LG_kernel_SUM_pow_cython, preprocess_data_nonpara_cython, LG_kernel_SUM_nonpara_cython cython_import = True #print("cython") except: cython_import = False #print("python") ########################################################################################################## ## class ########################################################################################################## class base_class: ### initialize def set_kernel(self, type, **kwargs):
import pyximport; pyximport.install() import enigmaC import os, operator def read(adress = "D:/code/UE_Crypto_Charpak/Codes/message8.txt"): with open(adress, 'r', encoding='UTF-8') as file: message = file.read() return message gears = [ [211, 173, 77, 35, 89, 44, 92, 214, 80, 54, 3, 157, 191, 72, 16, 21, 200, 164, 202, 61, 31, 34, 129, 68, 63, 43, 232, 136, 87, 197, 251, 74, 250, 1, 193, 104, 47, 10, 110, 160, 188, 124, 153, 171, 170, 6, 206, 161, 152, 96, 40, 62, 172, 144, 175, 168, 123, 38, 18, 242, 79, 53, 228, 48, 186, 184, 210, 140, 162, 143, 253, 150, 235, 145, 45, 91, 134, 248, 5, 90, 59, 75, 84, 249, 127, 76, 132, 66, 165, 57, 128, 217, 33, 11, 100, 203, 26, 121, 213, 247, 216, 199, 46, 114, 154, 101, 0, 115, 105, 4, 155, 187, 130, 147, 12, 41, 149, 219, 239, 107, 56, 39, 69, 70, 238, 234, 158, 15, 19, 196, 221, 236, 86, 65, 243, 231, 98, 182, 51, 177, 28, 71, 169, 241, 222, 117, 178, 112, 131, 167, 111, 141, 205, 25, 183, 229, 230, 122, 208, 135, 245, 113, 24, 223, 201, 13, 190, 64, 156, 106, 94, 185, 93, 126, 254, 212, 109, 81, 240, 237, 224, 218, 17, 215, 176, 194, 226, 220, 166, 83, 50, 73, 225, 118, 20, 108, 36, 14, 138, 244, 78, 67, 174, 8, 95, 159, 116, 37, 32, 2, 133, 139, 85, 227, 9, 179, 255, 102, 97, 233, 27, 42, 82, 195, 55, 246, 252, 30, 189, 207, 198, 58, 99, 7, 103, 163, 60, 120, 137, 142, 125, 22, 181, 209, 119, 23, 180, 88, 204, 52, 29, 146, 49, 148, 192, 151], [70, 36, 41, 129, 87, 233, 155, 96, 185, 204, 65, 80, 137, 221, 89, 167, 220, 58, 131, 23, 20, 237, 132, 53, 15, 180, 85, 195, 38, 149, 72, 218, 173, 120, 123, 110, 94, 81, 148, 127, 77, 251, 62, 56, 230, 44, 34, 71, 136, 54, 166, 236, 21, 108, 249, 29, 223, 106, 12, 18, 217, 184, 203, 210, 39, 60, 78, 152, 197, 244, 189, 206, 143, 156, 27, 7, 103, 198, 107, 145, 69, 135, 182, 164, 74, 10, 202, 99, 111, 224, 199, 196, 254, 215, 250, 97, 178, 101, 47, 208, 19, 227, 33, 248, 43, 128, 64, 40, 109, 162, 1, 138, 86, 134, 46, 207, 95, 122, 79, 126, 9, 209, 90, 124, 214, 246, 228, 229, 37, 200, 0, 76, 13, 133, 98, 165, 187, 91, 179, 193, 172, 48, 157, 114, 175, 168, 255, 8, 66, 75, 125, 57, 102, 51, 119, 240, 118, 211, 243, 11, 88, 235, 216, 141, 183, 159, 55, 24, 150, 192, 194, 6, 231, 28, 100, 219, 68, 144, 186, 82, 139, 73, 130, 176, 161, 245, 45, 63, 61, 239, 14, 117, 4, 234, 190, 42, 242, 169, 59, 163, 17, 121, 147, 154, 112, 225, 191, 35, 52, 116, 22, 212, 142, 232, 188, 151, 158, 174, 226, 32, 238, 140, 5, 25, 213, 253, 252, 205, 83, 105, 67, 201, 3, 104, 31, 146, 93, 16, 92, 171, 49, 50, 2, 170, 241, 181, 153, 160, 247, 177, 30, 115, 113, 26, 84, 222], [7, 106, 109, 229, 172, 34, 253, 174, 130, 14, 99, 107, 157, 79, 30, 147, 39, 19, 35, 24, 47, 205, 124, 67, 136, 246, 27, 237, 149, 142, 55, 245, 105, 21, 74, 101, 91, 10, 120, 137, 233, 8, 72, 73, 1, 119, 122, 20, 100, 251, 203, 85, 81, 153, 150, 83, 127, 50, 48, 144, 197, 70, 133, 210, 234, 227, 179, 68, 219, 71, 76, 173, 22, 167, 90, 190, 58, 64, 60, 244, 5, 28, 95, 63, 159, 195, 140, 236, 56, 115, 193, 65, 213, 89, 239, 145, 108, 23, 97, 6, 61, 25, 31, 228, 254, 231, 206, 164, 217, 32, 148, 232, 126, 141, 16, 11, 77, 188, 112, 154, 138, 255, 57, 135, 146, 88, 3, 121, 224, 223, 160, 152, 215, 46, 62, 132, 249, 111, 176, 170, 184, 93, 202, 103, 104, 87, 177, 86, 118, 171, 41, 165, 155, 230, 44, 175, 15, 163, 13, 98, 180, 94, 226, 114, 194, 207, 26, 162, 178, 9, 182, 183, 216, 143, 123, 196, 158, 169, 218, 186, 38, 116, 51, 204, 29, 198, 250, 185, 80, 12, 211, 191, 78, 125, 161, 208, 54, 200, 247, 17, 168, 252, 37, 166, 0, 181, 242, 187, 139, 241, 151, 53, 201, 36, 243, 214, 238, 43, 192, 220, 18, 225, 113, 134, 45, 129, 96, 40, 156, 248, 84, 75, 209, 235, 52, 42, 92, 240, 110, 4, 189, 66, 49, 221, 117, 199, 102, 59, 82, 128, 212, 33, 2, 222, 131, 69], [24, 210, 76, 63, 167, 40, 13, 203, 90, 34, 102, 163, 15, 230, 100, 182, 179, 31, 58, 255, 57, 0, 122, 137, 104, 98, 231, 26, 70, 254, 33, 4, 1, 88, 206, 28, 65, 125, 164, 93, 186, 187, 16, 223, 87, 127, 64, 123, 101, 99, 83, 154, 66, 191, 121, 29, 218, 174, 138, 77, 142, 9, 194, 132, 247, 215, 89, 113, 107, 216, 196, 162, 43, 32, 213, 151, 190, 81, 124, 69, 169, 112, 176, 59, 51, 165, 68, 193, 80, 141, 156, 211, 135, 120, 208, 160, 228, 140, 35, 12, 25, 229, 147, 38, 133, 131, 168, 92, 245, 62, 157, 114, 67, 136, 202, 242, 105, 6, 42, 48, 253, 184, 204, 61, 241, 220, 161, 158, 39, 183, 198, 18, 209, 119, 172, 175, 106, 221, 177, 235, 11, 27, 94, 170, 181, 129, 30, 188, 19, 47, 7, 199, 145, 139, 23, 74, 91, 71, 95, 244, 224, 152, 53, 75, 251, 201, 45, 10, 17, 200, 207, 195, 5, 116, 236, 166, 60, 205, 14, 72, 185, 2, 49, 130, 79, 3, 178, 149, 180, 134, 252, 86, 148, 243, 20, 238, 85, 37, 155, 82, 197, 84, 217, 171, 212, 246, 21, 227, 111, 54, 55, 240, 219, 143, 225, 97, 233, 128, 234, 36, 73, 44, 249, 150, 117, 248, 126, 214, 46, 108, 118, 22, 250, 52, 153, 232, 78, 56, 96, 159, 222, 8, 103, 144, 146, 239, 189, 50, 41, 226, 110, 237, 192, 173, 115, 109], [179, 102, 107, 105, 6, 147, 40, 66, 8, 160, 89, 116, 126, 244, 176, 118, 167, 57, 86, 163, 17, 70, 1, 157, 231, 219, 187, 191, 196, 58, 199, 141, 183, 59, 100, 53, 43, 148, 245, 54, 65, 158, 241, 227, 60, 82, 52, 5, 72, 139, 207, 228, 90, 161, 20, 4, 31, 75, 96, 240, 106, 251, 37, 223, 128, 62, 94, 42, 190, 173, 172, 47, 101, 35, 152, 236, 119, 92, 253, 204, 93, 229, 188, 115, 230, 64, 117, 211, 136, 169, 170, 249, 175, 131, 88, 24, 14, 224, 125, 193, 138, 233, 248, 95, 22, 151, 28, 71, 41, 25, 132, 174, 255, 87, 239, 149, 130, 153, 69, 155, 192, 171, 74, 9, 112, 56, 83, 232, 39, 144, 97, 21, 242, 2, 213, 79, 78, 68, 111, 225, 7, 142, 80, 146, 206, 134, 137, 0, 30, 216, 184, 209, 98, 33, 217, 159, 198, 124, 122, 91, 135, 210, 23, 181, 154, 182, 252, 76, 156, 189, 77, 49, 61, 16, 12, 104, 45, 15, 11, 195, 178, 18, 208, 113, 127, 212, 34, 38, 108, 254, 203, 50, 166, 238, 202, 150, 3, 214, 200, 143, 63, 32, 205, 109, 44, 129, 13, 27, 180, 215, 48, 145, 140, 162, 234, 84, 36, 243, 221, 26, 19, 29, 120, 67, 168, 226, 177, 218, 73, 237, 103, 247, 81, 194, 10, 165, 110, 114, 121, 164, 250, 197, 133, 85, 186, 235, 51, 46, 246, 185, 201, 55, 222, 123, 99, 220], [7, 188, 27, 179, 50, 254, 167, 117, 35, 149, 89, 81, 186, 39, 133, 28, 83, 112, 249, 165, 31, 194, 86, 237, 64, 203, 45, 241, 6, 226, 156, 171, 172, 43, 200, 41, 24, 90, 131, 122, 127, 232, 168, 180, 139, 78, 108, 0, 22, 94, 107, 162, 14, 59, 175, 84, 98, 132, 251, 46, 116, 70, 99, 29, 74, 135, 182, 44, 15, 192, 229, 138, 201, 198, 79, 92, 77, 69, 208, 75, 253, 148, 109, 134, 174, 96, 34, 5, 93, 151, 185, 189, 164, 8, 72, 227, 114, 20, 106, 142, 231, 103, 204, 129, 244, 19, 217, 25, 80, 71, 145, 23, 17, 178, 221, 169, 88, 214, 215, 219, 32, 143, 230, 42, 195, 177, 255, 121, 85, 36, 157, 183, 225, 222, 216, 181, 144, 191, 193, 212, 243, 202, 250, 38, 110, 58, 209, 240, 111, 205, 224, 223, 37, 82, 245, 115, 21, 102, 128, 210, 239, 68, 147, 234, 54, 52, 206, 238, 176, 100, 53, 137, 118, 40, 184, 155, 4, 220, 199, 247, 150, 57, 30, 48, 10, 26, 236, 197, 158, 130, 2, 63, 55, 166, 16, 124, 228, 60, 95, 65, 153, 213, 190, 163, 126, 97, 62, 161, 141, 123, 104, 207, 76, 3, 125, 218, 146, 91, 140, 9, 196, 119, 47, 235, 12, 1, 11, 105, 18, 173, 13, 154, 51, 152, 67, 160, 248, 33, 73, 211, 66, 242, 56, 61, 170, 233, 187, 252, 120, 136, 87, 49, 113, 246, 159, 101], [106, 72, 252, 44, 50, 129, 83, 110, 116, 119, 183, 182, 202, 22, 100, 225, 228, 181, 126, 26, 130, 36, 78, 209, 164, 5, 59, 43, 82, 24, 174, 138, 150, 97, 180, 233, 84, 235, 237, 96, 28, 221, 109, 159, 142, 132, 111, 128, 205, 11, 55, 191, 62, 115, 87, 18, 239, 224, 108, 139, 77, 135, 167, 219, 34, 112, 215, 236, 158, 151, 105, 157, 89, 155, 49, 67, 136, 131, 14, 52, 127, 73, 208, 211, 234, 216, 196, 254, 71, 137, 41, 51, 147, 247, 107, 161, 251, 194, 162, 39, 58, 175, 133, 206, 120, 184, 192, 232, 88, 148, 94, 91, 45, 176, 60, 122, 144, 65, 203, 198, 156, 1, 117, 10, 85, 160, 134, 190, 3, 32, 226, 249, 80, 21, 231, 223, 230, 118, 61, 48, 19, 171, 35, 245, 213, 4, 253, 57, 66, 165, 0, 244, 76, 204, 199, 143, 74, 125, 113, 99, 30, 248, 218, 47, 40, 163, 177, 20, 69, 93, 121, 27, 255, 238, 246, 222, 166, 200, 217, 29, 90, 68, 124, 243, 152, 146, 141, 12, 70, 170, 33, 86, 197, 63, 104, 229, 242, 186, 114, 101, 227, 95, 16, 212, 220, 201, 64, 98, 46, 240, 42, 2, 102, 38, 179, 9, 75, 189, 178, 154, 53, 241, 250, 37, 140, 8, 13, 145, 149, 31, 210, 25, 153, 17, 123, 185, 103, 168, 56, 173, 79, 188, 7, 92, 172, 54, 169, 193, 187, 214, 81, 207, 15, 195, 6, 23], [215, 216, 89, 97, 48, 193, 179, 241, 131, 172, 17, 102, 107, 10, 2, 121, 153, 164, 175, 143, 43, 203, 122, 134, 126, 64, 132, 23, 79, 250, 53, 152, 83, 56, 58, 184, 211, 69, 86, 19, 112, 162, 37, 125, 156, 151, 123, 109, 44, 88, 42, 251, 174, 142, 199, 113, 26, 163, 210, 65, 117, 232, 141, 50, 106, 15, 252, 81, 165, 119, 249, 66, 243, 205, 104, 240, 234, 183, 192, 130, 227, 185, 3, 39, 74, 145, 24, 35, 32, 218, 182, 148, 78, 129, 76, 248, 6, 140, 133, 136, 59, 194, 173, 25, 30, 222, 186, 105, 57, 158, 63, 84, 223, 157, 114, 159, 221, 92, 235, 9, 45, 225, 101, 54, 146, 49, 244, 36, 99, 233, 238, 47, 237, 91, 67, 128, 189, 100, 209, 188, 80, 93, 254, 161, 155, 41, 177, 33, 21, 85, 217, 51, 170, 62, 77, 70, 96, 168, 4, 94, 11, 61, 214, 0, 14, 231, 195, 190, 87, 7, 71, 207, 60, 236, 230, 180, 137, 213, 191, 68, 72, 197, 29, 147, 115, 187, 46, 12, 181, 38, 138, 246, 124, 166, 40, 27, 202, 201, 226, 176, 212, 204, 52, 149, 167, 196, 34, 220, 28, 98, 228, 13, 90, 224, 169, 135, 20, 16, 229, 75, 55, 154, 82, 150, 160, 198, 255, 1, 95, 118, 206, 120, 242, 116, 200, 110, 103, 22, 111, 178, 171, 5, 245, 139, 18, 253, 247, 31, 108, 208, 127, 8, 144, 239, 73, 219] ] inv_gears = [[106,33,209,10,109,78,45,233,203,214,37,93,114,165,197,127,14,182,58,128,194,15,241,245,162,153,96,220,140,250,227,20,208,92,21,3,196,207,57,121,50,115,221,25,5,74,102,36,63,252,190,138,249,61,9,224,120,89,231,80,236,19,51,24,167,133,87,201,23,122,123,141,13,191,31,81,85,2,200,60,8,177,222,189,82,212,132,28,247,4,79,75,6,172,170,204,49,218,136,232,94,105,217,234,35,108,169,119,195,176,38,150,147,161,103,107,206,145,193,244,237,97,157,56,41,240,173,84,90,22,112,148,86,210,76,159,27,238,198,211,67,151,239,69,53,73,251,113,253,116,71,255,48,42,104,110,168,11,126,205,39,47,68,235,17,88,188,149,55,142,44,43,52,1,202,54,184,139,146,215,246,242,137,154,65,171,64,111,40,228,166,12,254,34,185,223,129,29,230,101,16,164,18,95,248,152,46,229,158,243,66,0,175,98,7,183,100,91,181,117,187,130,144,163,180,192,186,213,62,155,156,135,26,219,125,72,131,179,124,118,178,143,59,134,199,160,225,99,77,83,32,30,226,70,174,216],[130,110,242,232,192,222,171,75,147,120,85,159,58,132,190,24,237,200,59,100,20,52,210,19,167,223,253,74,173,55,250,234,219,102,46,207,1,128,28,64,107,2,195,104,45,186,114,98,141,240,241,153,208,23,49,166,43,151,17,198,65,188,42,187,106,10,148,230,176,80,0,47,30,181,84,149,131,40,66,118,11,37,179,228,254,26,112,4,160,14,122,137,238,236,36,116,7,95,134,87,174,97,152,76,233,229,57,78,53,108,35,88,204,252,143,251,209,191,156,154,33,201,117,34,123,150,119,39,105,3,182,18,22,133,113,81,48,12,111,180,221,163,212,72,177,79,235,202,38,29,168,215,67,246,203,6,73,142,216,165,247,184,109,199,83,135,50,15,145,197,243,239,140,32,217,144,183,249,96,138,25,245,82,164,61,8,178,136,214,70,194,206,169,139,170,27,91,68,77,90,129,231,86,62,9,227,71,115,99,121,63,157,211,224,124,93,162,60,31,175,16,13,255,56,89,205,218,101,126,127,44,172,213,5,193,161,51,21,220,189,155,244,196,158,69,185,125,248,103,54,94,41,226,225,92,146],[204,44,252,126,239,80,99,0,41,169,37,115,189,158,9,156,114,199,220,17,47,33,72,97,19,101,166,26,81,184,14,102,109,251,5,18,213,202,180,16,227,150,235,217,154,224,133,20,58,242,57,182,234,211,196,30,88,122,76,247,78,100,134,83,77,91,241,23,67,255,61,69,42,43,34,231,70,116,192,13,188,52,248,55,230,51,147,145,125,93,74,36,236,141,161,82,226,98,159,10,48,35,246,143,144,32,1,11,96,2,238,137,118,222,163,89,181,244,148,45,38,127,46,174,22,193,112,56,249,225,8,254,135,62,223,123,24,39,120,208,86,113,29,173,59,95,124,15,110,28,54,210,131,53,119,152,228,12,176,84,130,194,167,157,107,151,203,73,200,177,139,149,4,71,7,155,138,146,168,66,160,205,170,171,140,187,179,207,117,240,75,191,218,90,164,85,175,60,185,245,197,212,142,50,183,21,106,165,195,232,63,190,250,92,215,132,172,108,178,68,219,243,253,129,128,221,162,65,103,3,153,105,111,40,64,233,87,27,216,94,237,209,206,214,79,31,25,198,229,136,186,49,201,6,104,121],[21,32,181,185,31,172,117,150,241,61,167,140,99,6,178,12,42,168,131,148,194,206,231,154,0,100,27,141,35,55,146,17,73,30,9,98,219,197,103,128,5,248,118,72,221,166,228,149,119,182,247,84,233,162,209,210,237,20,18,83,176,123,109,3,46,36,52,112,86,79,28,157,179,220,155,163,2,59,236,184,88,77,199,50,201,196,191,44,33,66,8,156,107,39,142,158,238,215,25,49,14,48,10,242,24,116,136,68,229,255,250,208,81,67,111,254,173,224,230,133,93,54,22,47,78,37,226,45,217,145,183,105,63,104,189,92,113,23,58,153,97,89,60,213,243,152,244,102,192,187,223,75,161,234,51,198,90,110,127,239,95,126,71,11,38,85,175,4,106,80,143,203,134,253,57,135,82,138,186,16,188,144,15,129,121,180,40,41,147,246,76,53,252,87,62,171,70,200,130,151,169,165,114,7,122,177,34,170,94,132,1,91,204,74,227,65,69,202,56,212,125,137,240,43,160,214,249,207,96,101,13,26,235,216,218,139,174,251,195,245,211,124,115,193,159,108,205,64,225,222,232,164,190,120,29,19],[147,22,133,196,55,47,4,140,8,123,234,178,174,206,96,177,173,20,181,220,54,131,104,162,95,109,219,207,106,221,148,56,201,153,186,73,216,62,187,128,6,108,67,36,204,176,247,71,210,171,191,246,46,35,39,251,125,17,29,33,44,172,65,200,85,40,7,223,137,118,21,107,48,228,122,57,167,170,136,135,142,232,45,126,215,243,18,113,94,10,52,159,77,80,66,103,58,130,152,254,34,72,1,230,175,3,60,2,188,203,236,138,124,183,237,83,11,86,15,76,222,238,158,253,157,98,12,184,64,205,116,93,110,242,145,160,88,146,100,49,212,31,141,199,129,211,143,5,37,115,195,105,74,117,164,119,168,23,41,155,9,53,213,19,239,235,192,16,224,89,90,121,70,69,111,92,14,226,180,0,208,163,165,32,150,249,244,26,82,169,68,27,120,99,233,179,28,241,156,30,198,250,194,190,79,202,144,50,182,151,161,87,185,134,197,209,149,154,227,25,255,218,252,63,97,139,225,43,51,81,84,24,127,101,214,245,75,229,193,114,59,42,132,217,13,38,248,231,102,91,240,61,166,78,189,112],[47,225,190,213,176,87,28,0,93,219,184,226,224,230,52,68,194,112,228,105,97,156,48,111,36,107,185,2,15,63,182,20,120,237,86,8,129,152,143,13,173,35,123,33,67,26,59,222,183,251,4,232,165,170,164,192,242,181,145,53,197,243,206,191,24,199,240,234,161,77,61,109,94,238,64,79,212,76,45,74,108,11,153,16,55,128,22,250,116,10,37,217,75,88,49,198,85,205,56,62,169,255,157,101,210,227,98,50,46,82,144,148,17,252,96,155,60,7,172,221,248,127,39,209,195,214,204,40,158,103,189,38,57,14,83,65,249,171,71,44,218,208,99,121,136,110,216,162,81,9,180,89,233,200,231,175,30,130,188,254,235,207,51,203,92,19,193,6,42,115,244,31,32,229,84,54,168,125,113,3,43,135,66,131,174,90,12,246,1,91,202,137,69,138,21,124,220,187,73,178,34,72,141,25,102,149,166,211,78,146,159,239,139,201,117,118,134,106,215,119,177,114,133,151,150,132,29,95,196,70,122,100,41,245,163,223,186,23,167,160,147,27,241,140,104,154,253,179,236,18,142,58,247,80,5,126],[150,121,211,128,145,25,254,242,225,215,123,49,187,226,78,252,202,233,55,140,167,133,13,255,29,231,19,171,40,179,160,229,129,190,64,142,21,223,213,99,164,90,210,27,3,112,208,163,139,74,4,91,79,220,245,50,238,147,100,26,114,138,52,193,206,117,148,75,181,168,188,88,1,81,156,216,152,60,22,240,132,250,28,6,36,124,191,54,108,72,180,111,243,169,110,201,39,33,207,159,14,199,212,236,194,70,0,94,58,42,7,46,65,158,198,53,8,122,137,9,104,170,115,234,182,157,18,80,47,5,20,77,45,102,126,61,76,89,31,59,224,186,44,155,116,227,185,92,109,228,32,69,184,232,219,73,120,71,68,43,125,95,98,165,24,149,176,62,237,246,189,141,244,239,30,101,113,166,218,214,34,17,11,10,105,235,197,248,241,217,127,51,106,247,97,253,86,192,119,154,177,205,12,118,153,48,103,251,82,23,230,83,203,144,249,66,85,178,162,63,204,41,175,135,57,15,130,200,16,195,136,134,107,35,84,37,67,38,173,56,209,221,196,183,151,143,174,93,161,131,222,96,2,146,87,172],[163,227,14,82,158,241,96,169,251,119,13,160,187,211,164,65,217,10,244,39,216,148,237,27,86,103,56,195,208,182,104,247,88,147,206,87,127,42,189,83,194,145,50,20,48,120,186,131,4,125,63,151,202,30,123,220,33,108,34,100,172,161,153,110,25,59,71,134,179,37,155,170,180,254,84,219,94,154,92,28,140,67,222,32,111,149,38,168,49,2,212,133,117,141,159,228,156,3,209,128,137,122,11,236,74,107,64,12,248,47,235,238,40,55,114,184,233,60,229,69,231,15,22,46,192,43,24,250,135,93,79,8,26,98,23,215,99,176,190,243,97,62,53,19,252,85,124,183,91,203,223,45,31,16,221,144,44,113,109,115,224,143,41,57,17,68,193,204,157,214,152,240,9,102,52,18,199,146,239,6,175,188,90,77,35,81,106,185,139,136,167,178,78,5,101,166,205,181,225,54,234,197,196,21,201,73,230,171,249,138,58,36,200,177,162,0,1,150,89,255,207,116,105,112,213,121,198,80,210,218,174,165,61,129,76,118,173,132,130,253,75,7,232,72,126,242,191,246,95,70,29,51,66,245,142,226]] message8 = read("D:/code/UE_Crypto_Charpak/Codes/message8.txt") brutforce(message8[:13], inv_gears)
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from typing import List import pyximport importers = pyximport.install() from cape_splitter.fast_tokenizer.word_tokenizer import word_tokenizer, sentence_tokenizer pyximport.uninstall(*importers) import pytest def _spans_to_token_list(text: str, spans: List[List[int]]) -> List[str]: return [text[span[0]:span[1] + 1] for span in spans] _TOKENIZED_WORDS = [ (" Hello World whaît a\nwonderful\tplace.!! ", [' ', 'Hello ', 'World ', 'whaît ', 'a\n', 'wonderful\t', 'place.!! ']), ("This-is-a= two[word&sentence", ["This-is-a= ", "two[word&sentence"]), ("*****@*****.**", ["*****@*****.**"]),
Command line options -------------------- """ import os import sys import re import optparse import pysam import CGAT.Experiment as E try: import pyximport pyximport.install(build_in_temp=False) import _bam2bed except ImportError: import CGAT._bam2bed as _bam2bed def main(argv=None): """script main. parses command line options in sys.argv, unless *argv* is given. """ if not argv: argv = sys.argv # setup command line parser parser = E.OptionParser(version="%prog version: $Id$",
def gen_module(self, name, functions, pack=None): ''' Load a single module and pack it with the functions passed ''' full = '' mod = None for mod_dir in self.module_dirs: if not os.path.isabs(mod_dir): continue if not os.path.isdir(mod_dir): continue fn_ = os.path.join(mod_dir, name) if os.path.isdir(fn_): full = fn_ break else: for ext in ('.py', '.pyo', '.pyc', '.so'): full_test = '{0}{1}'.format(fn_, ext) if os.path.isfile(full_test): full = full_test break if full: break if not full: return None cython_enabled = False if self.opts.get('cython_enable', True) is True: try: import pyximport pyximport.install() cython_enabled = True except ImportError: log.info('Cython is enabled in the options but not present ' 'in the system path. Skipping Cython modules.') try: if full.endswith('.pyx') and cython_enabled: # If there's a name which ends in .pyx it means the above # cython_enabled is True. Continue... mod = pyximport.load_module(name, full, tempfile.gettempdir()) else: fn_, path, desc = imp.find_module(name, self.module_dirs) mod = imp.load_module( '{0}.{1}.{2}.{3}'.format(self.loaded_base_name, self.mod_type_check(path), self.tag, name), fn_, path, desc) except ImportError: log.debug('Failed to import {0} {1}:\n'.format(self.tag, name), exc_info=True) return mod except Exception: log.error('Failed to import {0} {1}, this is due most likely to a ' 'syntax error:\n'.format(self.tag, name), exc_info=True) return mod if hasattr(mod, '__opts__'): mod.__opts__.update(self.opts) else: mod.__opts__ = self.opts mod.__grains__ = self.grains if pack: if isinstance(pack, list): for chunk in pack: try: setattr(mod, chunk['name'], chunk['value']) except KeyError: pass else: setattr(mod, pack['name'], pack['value']) # Call a module's initialization method if it exists module_init = getattr(mod, '__init__', None) if inspect.isfunction(module_init): try: module_init(self.opts) except TypeError: pass funcs = {} module_name = mod.__name__[mod.__name__.rindex('.') + 1:] if getattr(mod, '__load__', False) is not False: log.info( 'The functions from module {0!r} are being loaded from the ' 'provided __load__ attribute'.format(module_name)) for attr in getattr(mod, '__load__', dir(mod)): if attr.startswith('_'): # private functions are skipped continue func = getattr(mod, attr) if not inspect.isfunction(func): # Not a function!? Skip it!!! continue # Let's get the function name. # If the module has the __func_alias__ attribute, it must be a # dictionary mapping in the form of(key -> value): # <real-func-name> -> <desired-func-name> # # It default's of course to the found callable attribute name # if no alias is defined. funcname = getattr(mod, '__func_alias__', {}).get(attr, attr) funcs['{0}.{1}'.format(module_name, funcname)] = func self._apply_outputter(func, mod) if not hasattr(mod, '__salt__'): mod.__salt__ = functions try: context = sys.modules[functions[functions.keys() [0]].__module__].__context__ except (AttributeError, IndexError): context = {} mod.__context__ = context return funcs
import numpy as np # import time # from Cython.Build import cythonize import pyximport pyximport.install( inplace=True, setup_args={"include_dirs": np.get_include()}, ) import models.transformations.emerging.inverse_op_cython as inverse_op_cython class Inverse(): def __init__(self): pass def __call__(self, z, w, b): if np.isnan(z).any(): return z z = z - b z_np = np.array(z, dtype='float64') w_np = np.array(w, dtype='float64') x_np = inverse_op_cython.inverse_conv(z_np, w_np) return x_np.astype('float32')
import re, gzip, time try: # Python 2 compat import cPickle as pickle except ImportError: import pickle import threading import numpy as np import logging import scipy import pyximport pyximport.install(setup_args={"include_dirs": np.get_include()}) from multiprocessing import Queue, Lock, cpu_count from collections import OrderedDict from .glove_inner import train_glove try: # Python 2 compat import cPickle as pickle except ImportError: import pickle class Glove(object): def __init__(self, cooccurence, alpha=0.75, x_max=100.0, d=50, seed=1234): """ Glove model for obtaining dense embeddings from a co-occurence (sparse) matrix. """ self.alpha = alpha
import numpy as np import pyximport pyximport.install(language_level=2) HIGHTHRESH = 1.5 STANDARDTHRESH = 1.0 #faces have ID,faceVector ; observed faces a list of faceVectors,rects def compare(listStudentFaces, listOfObservedFaces): comparedFaces = { } #a dictionary that will hold a comparisons for a face except of the best result bestResultPerStudent = [ ] # alist of the best results per person [valueOfComparison, theStudentID ,idOfObservedFace, rectangleOfObservedFace] #go through the individuals faces for i in listStudentFaces: fvec = i[1] #get the faceVector for current person tmpList = [ ] #the calculation per person that will be added to compared faces j = 0 #j will be used as an ID of observed faces hence they will all will have ID range [0-N) #go through all the observed faces while j < len(listOfObservedFaces): #get the comparison value d = fvec - listOfObservedFaces[j][0] result = np.dot(d, d) tmpList.append([result, j, listOfObservedFaces[j][1]]) j = j + 1 #sort the observed faces compared with the current person based on their valueOfComparison; sorted based on increasing order tmpList = sorted(tmpList, key=lambda x: x[0]) #remove the best result tmp = tmpList.pop(0)
import pytest from unittestmock import UnitTestMock import pyximport pyximport.install(setup_args={"script_args": ["--force"]}, language_level=3) from cykhash import unique_int64, unique_int32, unique_float64, unique_float32 from cykhash import unique_stable_int64, unique_stable_int32, unique_stable_float64, unique_stable_float32 from uniqueinterfacetester import use_unique_int64, use_unique_int32, use_unique_float64, use_unique_float32 from uniqueinterfacetester import use_unique_stable_int64, use_unique_stable_int32, use_unique_stable_float64, use_unique_stable_float32 UNIQUE = { 'int64': unique_int64, 'int32': unique_int32, 'float64': unique_float64, 'float32': unique_float32, } STABLE = { 'int64': unique_stable_int64, 'int32': unique_stable_int32, 'float64': unique_stable_float64, 'float32': unique_stable_float32, } CY_UNIQUE = { 'int64': use_unique_int64, 'int32': use_unique_int32, 'float64': use_unique_float64, 'float32': use_unique_float32, }
import scipy.optimize import matplotlib.pyplot as plt import RMS.ConfigReader as cr from RMS.Formats import Platepar from RMS.Formats import CALSTARS from RMS.Formats import StarCatalog from RMS.Formats import FFfile from RMS.Astrometry.ApplyAstrometry import raDec2AltAz, raDecToXYPP, xyToRaDecPP, rotationWrtHorizon from RMS.Astrometry.Conversions import date2JD, jd2Date from RMS.Astrometry.FFTalign import alignPlatepar from RMS.Math import angularSeparation # Import Cython functions import pyximport pyximport.install(setup_args={'include_dirs': [np.get_include()]}) from RMS.Astrometry.CyFunctions import matchStars, subsetCatalog, cyraDecToXY def computeMinimizationTolerances(config, platepar, star_dict_len): """ Compute tolerances for minimization. """ # Calculate the function tolerance, so the desired precision can be reached (the number is calculated # in the same regard as the cost function) fatol = (config.dist_check_threshold** 2) / np.sqrt(star_dict_len * config.min_matched_stars + 1) # Parameter estimation tolerance for angular values fov_w = platepar.X_res / platepar.F_scale xatol_ang = config.dist_check_threshold * fov_w / platepar.X_res
# -*- coding: utf-8 -*- """ Created on %(date)s @author: %(username)s """ import os import timeit import time import numpy as np import pyximport pyximport.install() from .idw_nebs import slct_nebrs_cy, get_idw from krig_single_pts import (OrdinaryKriging, SimpleKriging, ExternalDriftKriging_MD) def get_all_grid(interp_x_coords_arr, interp_y_coords_arr, nebor_x_coords_arr, nebor_y_coords_arr, nebor_vals_arr, idw_exp, n_quads, n_per_quad, min_dist_thresh, n_nebs, interp_types,
import errno import uuid import time import platform import tempfile import os.path from contextlib import contextmanager from zlib import compress as _compress from dpark.utils.crc32c import crc32c try: from dpark.portable_hash import portable_hash as _hash except ImportError: import pyximport pyximport.install(inplace=True) from dpark.portable_hash import portable_hash as _hash try: import pwd def getuser(): return pwd.getpwuid(os.getuid()).pw_name except: import getpass def getuser(): return getpass.getuser() COMPRESS = 'zlib'
for i in range(kn - 1, len_x): for j in range(kn - 1, len_y): # hard matching if hard_matching: if x[i] == y[j]: sum_ += lamda * lamda * Kd[(kn - 1) % 2][i*y_dim + j] else: # soft matching, regulated from models.h, amminoacidic model sum_ += lamda * lamda * \ aa_model[(ord(x[i])-65)*26 + ord(y[j])-65] * \ Kd[(kn - 1) % 2][i*y_dim + j]; return sum_ try: import pyximport; pyximport.install(pyimport=True, reload_support=True) import sk_fast _core_function = sk_fast._core_stringkernel except ImportError: _core_function = _core_stringkernel def _stringkernel_unsymmetric(X, X_train_, kn=1, lamda=.5, hard_matching=True, normalize=True, aa_model=None, return_norms=False, n_jobs=1): # X != X_train_ x_len = len(X) y_len = len(X_train_) kernel = np.empty((x_len, y_len)) function = partial(_core_function, kn=kn, lamda=lamda, hard_matching=hard_matching, aa_model=aa_model)
warned = False # Code to compile the Cython extensions # Extensions tested on Linux and Mac OS X, but not on Windows # please report any bug (or patches!) on # https://github.com/ggventurini/python-deltasigma/issues try: if 'nt' in os.name: # if somebody actually goes through the trouble of compiling # it on Windows, we'll make available a patch to re-enable it. # In most cases now, users only get error messages from BLAS # not being available. raise ImportError('CBLAS extension disabled on Windows') import pyximport pyximport.install(setup_args=setup_args, language_level=3) from ._simulateDSM_cblas import simulateDSM as _simulateDSM_cblas except ImportError as e: if _debug: print(str(e)) _simulateDSM_cblas = None try: import pyximport pyximport.install(setup_args=setup_args, inplace=True, language_level=3) from ._simulateDSM_scipy_blas import simulateDSM as _simulateDSM_scipy_blas except ImportError as e: if _debug: print(str(e)) _simulateDSM_scipy_blas = None
#Analysis script for Verdiem data from CalPlug 2014 study - Idle Time Reporter using XOR #Developed by M. Klopfer Sept 11, 2018 - V1.5 #Operation: This script is a stand-alone processor that takes the Verdiem data and formats it into a style used as a .CSV input into the PLSin program. This script will not actually output a .CSV file its current state, just format the text in a way that can be quickly formatted into the specific PLSim format. #The script reads from a database/table with the following entries: record_id subject_identifier desktop_type MPID device status int_record date day_of_week P1 P2...[There are 96 entries that correspond to 15 minute periods across the day] #Dependencies and setup considerations: This program uses Miniconda/Eclipse in development and is within an Eclipse workshop - it shares identical dependencies as PLSim: https://github.com/CalPlug/PlugLoadSimulator-PLSim #Note, if the console is not large enough in Eclipse to display the return, consider the following: https://stackoverflow.com/questions/2600653/adjusting-eclipse-console-size import sys import calendar from datetime import timedelta, datetime, date, time from time import mktime import pyximport; pyximport.install() #pyximport cython accelerator import mysql.connector #from distutils.core import setup #from Cython.Build import cythonize #Run Options for Output Formatting elapsedminortime=True #Print headers as time (False) or minutes since 00:00 (True) writetosummarydb = True #Option allows summary to be written to a summary table in the database dbrecordpost = 0 #counter for posted records finaldeltalist =[] #holder for the total collected delta values across all days periodlength=15 #assume a standard 15 min period length totalperiods = 96 #total number of columns devoted to the periods periodstartcolumn = 9 #column which the period info starts in record_idrow = 0 #position original identifier is in subjectrow = 1 #Row the subject info is in desktop_typerow = 2 #position for the desktop type info MPIDrow = 3 #row MPID info is placed in
import numpy as np import pyximport # Cython Compilation pyximport.install(setup_args={"include_dirs": np.get_include()}, language_level=3) from .rank_cy import evaluate_cy # pylint: disable=relative-beyond-top-level def compute_CMC_mAP(distmat, q_pids, g_pids, q_camids, g_camids, max_rank=20, use_metric_cuhk03=False): """Evaluates CMC rank. Args: distmat (numpy.ndarray): distance matrix of shape (num_query, num_gallery). q_pids (numpy.ndarray): 1-D array containing person identities of each query instance. g_pids (numpy.ndarray): 1-D array containing person identities of each gallery instance. q_camids (numpy.ndarray): 1-D array containing camera views under which each query instance is captured. g_camids (numpy.ndarray): 1-D array containing camera views under which each gallery instance is captured. max_rank (int, optional): maximum CMC rank to be computed. Default is 20. use_metric_cuhk03 (bool, optional): use single-gallery-shot setting for cuhk03.
try: import pyximport; pyximport.install() except ImportError: pass from cydmx import dmxwidget import sys def main(): modname = sys.argv[1] module = __import__(modname.rsplit('.', 1)[0]) widgets = [] for name in dir(module): val = getattr(module, name) try: if issubclass(val, dmxwidget.Widget) and val != dmxwidget.Widget: widgets.append(val) except TypeError: pass ws = dmxwidget.WidgetServer() ws.run(widgets) if __name__ == "__main__": main()
""" This module provides methods for checking webpage type. @ author: Ziming Sheng @ date: 2019-07-25 """ import collections import re from urllib import parse from lxml import etree from lxml.html import clean, defs import numpy import pyximport pyximport.install(pyimport=True) from cyGaussian import gaussian def collect_text_and_a_tag(root): """ Collect node index, path and depth information of text tags and a tags :param root: lxml etree root object :return: A dict maps tag path to the corresponding tag info. For instance: {"html/div/div/p": [(34, "Best places to visit...", 4)], "html/div/div/div/p": [(40, "What's your problem?", 5)]} {"html/div/h/a": [(48, "back to top", "html/div/h/a")], "html/div/div/li/a": [(59, "python is fun", "html/div/div/li/a")]} """ # initialize dict to store info of link nodes and text nodes # initialize visit index and depth to 0 a_path = collections.defaultdict(list)
''' Created on Mar 12, 2012 @author: dsussman ''' import pyximport; pyximport.install() import numpy as np from scipy import sparse as sp import roi import fibergraph import zindex from scipy.io import loadmat, savemat from collections import Counter #from mayavi import mlab # DISA - I don't have import itertools as itt from matplotlib import pyplot as plt import fa #import mprage # DISA - I don't have import argparse import os class ConnectedComponent(object): vertexCC = None ccsize = None ncc = 0 n = 0 def __init__(self,G=None, fn=None): if G is not None:
from fixed import FixedImportanceSampler import numpy as n import geom import pyximport; pyximport.install(setup_args={"include_dirs":n.get_include()},reload_support=True) import fisher_util class FixedBinghamImportanceSampler(FixedImportanceSampler): def __init__(self,suffix,symmetry=None): FixedImportanceSampler.__init__(self,suffix) self.symmetry = symmetry # Compute symmetry operator if self.symmetry is not None: Rs = self.symmetry.get_rotations() self.symmetry_quats = n.array([geom.rotmat3D_to_quat(R) for R in Rs]) else: self.symmetry_quats = None def evaluate_kernel(self,inds,vals,odomain,params,logspace=False): """ Evaluate the kernel at all points in the current domain at the inds of odomain with value vals """ dirs1 = self.domain.get_dirs() dirs2 = odomain.get_dirs(inds) pscale = params.get('is_bingham_pscale'+self.suffix,params.get('is_bingham_pscale',1.0)) kappa = n.log((2**odomain.dim)*pscale)/(1-n.cos(odomain.resolution/2.0)**2) chiral_flip = params.get('is_bingham_chirality_flip'+self.suffix,params.get('is_bingham_chirality_flip',True))