• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python cache.clear_cache函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.core.cache.clear_cache函数的典型用法代码示例。如果您正苦于以下问题:Python clear_cache函数的具体用法?Python clear_cache怎么用?Python clear_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了clear_cache函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: write_in_chunks

def write_in_chunks(lines, mainfile, deffile, name, chunk_size):
	funcname = "definitions_" + name
	
	first_chunk = []
	try:
		for i in range(chunk_size+1):
			first_chunk.append(next(lines))
	except StopIteration:
		for line in first_chunk:
			mainfile.write(line)
	else:
		lines = chain(first_chunk, lines)
		
		while True:
			mainfile.write(funcname + "();\n")
			deffile.write("void " + funcname + "(void){\n")
			
			try:
				for i in range(chunk_size):
					deffile.write(next(lines))
			except StopIteration:
				break
			finally:
				deffile.write("}\n")
			
			funcname = count_up(funcname)
			clear_cache()
开发者ID:kiaderouiche,项目名称:jitcode,代码行数:27,代码来源:_helpers.py


示例2: alt_enumerate

 def alt_enumerate(self, cross_sections=None):
   '''only works when the set is a generating set for sortables and the top layer has all the same length!!!'''
   ml = max([len(s) for s in self])
   PPS = PegPermSet([s for s in self if len(s) == ml])
   (gf, cross_sections) = PPS.alt_cross_sections()
   gc.collect()
   print('\tDone computing cross_sections. There are',len(cross_sections),'cross sections.')
   print('Starting to compute generating function for uncleans.')
   i = 0
   n = len(cross_sections)
   t = time.time()
   # print 'clean gf:',gf.simplify()
   for clean_perm in cross_sections.keys():
     if i % 10000 == 0 and i > 0:
       gf = gf.simplify()
     if i % 50000 == 0 and i > 0:
       clear_cache()
     if i % 10000 == 0 and i > 0:
       print('\t\t',i,'of',n,'\ttook',(time.time()-t),'seconds.')
       t = time.time()
     # gf -= clean_perm.csgf([])
     # print 'subtracting gf for',clean_perm,'with basis []'
     # print 'adding gf for',clean_perm,'with basis',cross_sections[clean_perm]
     gf += clean_perm.csgf(cross_sections[clean_perm])
     i += 1
   print('\tDone!')
   return gf.simplify()
开发者ID:engenmt,项目名称:permpy,代码行数:27,代码来源:pegpermset.py


示例3: main

def main(results):
    testholder = []
    for (test, dropsize) in testparams:
        datasrc = sprinkler(dropsize, files)
        testholder += [(test, datasrc)]
    failcount = 0
    while failcount != len(testparams) * len(files):
        for (test, datasrc) in testholder:
            fails = []
            for (fname, Drip) in datasrc.items():
                block = Drip.drip()
                if block == []:
                    fails += [(fname, datasrc)]
                    failcount += 1
                else:
                    print('Testing', fname, 'with', test.__name__, 'drip no.', Drip.dripno)
                    if not results.hasresult(Drip.dripno, fname, test.__name__):
                        while True:
                            try:
                                pvalue = test(block)
                                break
                            except(MemoryError):
                                clear_cache()
                        try:
                            for i, pval in enumerate(pvalue):
                                results.store(Drip.dripno, fname, test.__name__, i, pval)
                        except(TypeError):
                            results.store(Drip.dripno, fname, test.__name__, 1, pvalue)
            remfails(fails)
开发者ID:alephu5,项目名称:Soundbyte,代码行数:29,代码来源:main.py


示例4: compute_psi_stats

    def compute_psi_stats(self):
        # define some normal distributions
        mus = [sp.var("mu_%i" % i, real=True) for i in range(self.input_dim)]
        Ss = [sp.var("S_%i" % i, positive=True) for i in range(self.input_dim)]
        normals = [
            (2 * sp.pi * Si) ** (-0.5) * sp.exp(-0.5 * (xi - mui) ** 2 / Si) for xi, mui, Si in zip(self._sp_x, mus, Ss)
        ]

        # do some integration!
        # self._sp_psi0 = ??
        self._sp_psi1 = self._sp_k
        for i in range(self.input_dim):
            print "perfoming integrals %i of %i" % (i + 1, 2 * self.input_dim)
            sys.stdout.flush()
            self._sp_psi1 *= normals[i]
            self._sp_psi1 = sp.integrate(self._sp_psi1, (self._sp_x[i], -sp.oo, sp.oo))
            clear_cache()
        self._sp_psi1 = self._sp_psi1.simplify()

        # and here's psi2 (eek!)
        zprime = [sp.Symbol("zp%i" % i) for i in range(self.input_dim)]
        self._sp_psi2 = self._sp_k.copy() * self._sp_k.copy().subs(zip(self._sp_z, zprime))
        for i in range(self.input_dim):
            print "perfoming integrals %i of %i" % (self.input_dim + i + 1, 2 * self.input_dim)
            sys.stdout.flush()
            self._sp_psi2 *= normals[i]
            self._sp_psi2 = sp.integrate(self._sp_psi2, (self._sp_x[i], -sp.oo, sp.oo))
            clear_cache()
        self._sp_psi2 = self._sp_psi2.simplify()
开发者ID:rajivsam,项目名称:GPy,代码行数:29,代码来源:sympykern.py


示例5: __init__

    def __init__(self):

        # Upon creating a new model, clear the cache
        # Otherwise creating multiple models creates
        # problems because sympy() will not reevaluate
        # functions and the series accessor will not
        # get created.  Because sympy keeps this cache
        # around, will have to be careful if using these
        # models in a multi-threaded context.
        clear_cache()

        self.variables = collections.OrderedDict()
        self.parameters = collections.OrderedDict()
        self.solutions = list()
        self.equations = list()

        self._private_parameters = collections.OrderedDict()
        self._local_context = dict()
        self._var_default = None
        self._param_default = None

        self._need_function_update = True

        _add_functions(self._local_context)

        # Variables used to lambdify the expressions
        self._arg_list = None
        self._private_funcs = None

        self._solvers = dict()
        self._solvers['newton-raphson'] = NewtonRaphsonSolver(self)
        self._solvers['gauss-seidel'] = GaussSeidelSolver(self)
        self._solvers['broyden'] = BroydenSolver(self)
开发者ID:kennt,项目名称:pylinsolve,代码行数:33,代码来源:model.py


示例6: test_dielectric

def test_dielectric(ctx_getter, qbx_order, op_class, mode, visualize=False):
    cl_ctx = ctx_getter()
    queue = cl.CommandQueue(cl_ctx)

    import logging
    logging.basicConfig(level=logging.INFO)

    from pytools.convergence import EOCRecorder
    eoc_rec = EOCRecorder()

    for nelements in [30, 50, 70]:
        # prevent sympy cache 'splosion
        from sympy.core.cache import clear_cache
        clear_cache()

        errs = run_dielectric_test(
                cl_ctx, queue,
                nelements=nelements, qbx_order=qbx_order,
                op_class=op_class, mode=mode,
                visualize=visualize)

        eoc_rec.add_data_point(1/nelements, la.norm(list(errs), np.inf))

    print(eoc_rec)
    assert eoc_rec.order_estimate() > qbx_order - 0.5
开发者ID:inducer,项目名称:pytential,代码行数:25,代码来源:too_slow_test_helmholtz.py


示例7: test_issue_7688

def test_issue_7688():
    from sympy.core.function import Function, UndefinedFunction

    f = Function('f')  # actually an UndefinedFunction
    clear_cache()
    class A(UndefinedFunction):
        pass
    a = A('f')
    assert isinstance(a, type(f))
开发者ID:Lenqth,项目名称:sympy,代码行数:9,代码来源:test_function.py


示例8: main

def main(n, bench):
    func = globals()['bench_' + bench]
    l = []
    for i in range(n):
        clear_cache()
        t0 = time.time()
        func()
        l.append(time.time() - t0)
    return l
开发者ID:kmod,项目名称:icbd,代码行数:9,代码来源:bm_sympy.py


示例9: _lambdify

 def _lambdify(self):
     lambda_list = []
     vars = [range_[0] for range_ in self._ranges[1:]]
     for sym_sol in self.sym_sols:
         lambda_list.append(lambdify(vars,sym_sol))
     self.__call__.__func__.__doc__ += ('Function signature is f('
                                        +','.join([str(var) for var in vars]
                                                  )+')\n')
     clear_cache()
     return vars,lambda_list
开发者ID:woodscn,项目名称:BACL-MMS,代码行数:10,代码来源:integration.py


示例10: test_Basic_keep_sign

def test_Basic_keep_sign():
    Basic.keep_sign = True
    assert Mul(x - 1, x + 1) == (x - 1)*(x + 1)
    assert (1/(x - 1)).as_coeff_terms()[0] == +1

    clear_cache()

    Basic.keep_sign = False
    assert Mul(x - 1, x + 1) == -(1 - x)*(1 + x)
    assert (1/(x - 1)).as_coeff_terms()[0] == -1
开发者ID:bibile,项目名称:sympy,代码行数:10,代码来源:test_expr.py


示例11: test_file

    def test_file(self, filename):
        clear_cache()

        import unittest
        from StringIO import StringIO

        rel_name = filename[len(self._root_dir)+1:]
        module = rel_name.replace(os.sep, '.')[:-3]
        setup_pprint()
        try:
            module = pdoctest._normalize_module(module)
            tests = SymPyDocTestFinder().find(module)
        except:
            self._reporter.import_error(filename, sys.exc_info())
            return

        tests = [test for test in tests if len(test.examples) > 0]
        # By default (except for python 2.4 in which it was broken) tests
        # are sorted by alphabetical order by function name. We sort by line number
        # so one can edit the file sequentially from bottom to top...HOWEVER
        # if there are decorated functions, their line numbers will be too large
        # and for now one must just search for these by text and function name.
        tests.sort(key=lambda x: -x.lineno)

        if not tests:
            return
        self._reporter.entering_filename(filename, len(tests))
        for test in tests:
            assert len(test.examples) != 0
            runner = SymPyDocTestRunner(optionflags=pdoctest.ELLIPSIS | \
                    pdoctest.NORMALIZE_WHITESPACE)
            old = sys.stdout
            new = StringIO()
            sys.stdout = new
            # If the testing is normal, the doctests get importing magic to
            # provide the global namespace. If not normal (the default) then
            # then must run on their own; all imports must be explicit within
            # a function's docstring. Once imported that import will be
            # available to the rest of the tests in a given function's
            # docstring (unless clear_globs=True below).
            if not self._normal:
                test.globs = {}
                # if this is uncommented then all the test would get is what
                # comes by default with a "from sympy import *"
                #exec('from sympy import *') in test.globs
            try:
                f, t = runner.run(test, out=new.write, clear_globs=False)
            finally:
                sys.stdout = old
            if f > 0:
                self._reporter.doctest_fail(test.name, new.getvalue())
            else:
                self._reporter.test_pass()
        self._reporter.leaving_filename()
开发者ID:mattcurry,项目名称:sympy,代码行数:54,代码来源:runtests.py


示例12: test_issue_7687

def test_issue_7687():
    from sympy.core.function import Function
    from sympy.abc import x
    f = Function('f')(x)
    ff = Function('f')(x)
    match_with_cache = ff.matches(f)
    assert isinstance(f, type(ff))
    clear_cache()
    ff = Function('f')(x)
    assert isinstance(f, type(ff))
    assert match_with_cache == ff.matches(f)
开发者ID:Lenqth,项目名称:sympy,代码行数:11,代码来源:test_function.py


示例13: bench_sympy

def bench_sympy(loops, func):
    timer = perf.perf_counter
    dt = 0

    for _ in xrange(loops):
        # Don't benchmark clear_cache(), exclude it of the benchmark
        clear_cache()

        t0 = timer()
        func()
        dt += (timer() - t0)

    return dt
开发者ID:Yaspee,项目名称:performance,代码行数:13,代码来源:bm_sympy.py


示例14: test_pow_eval_subs_no_cache

def test_pow_eval_subs_no_cache():
    # Tests pull request 9376 is working
    from sympy.core.cache import clear_cache

    s = 1/sqrt(x**2)
    # This bug only appeared when the cache was turned off.
    # We need to approximate running this test without the cache.
    # This creates approximately the same situation.
    clear_cache()

    # This used to fail with a wrong result.
    # It incorrectly returned 1/sqrt(x**2) before this pull request.
    result = s.subs(sqrt(x**2), y)
    assert result == 1/y
开发者ID:Lenqth,项目名称:sympy,代码行数:14,代码来源:test_subs.py


示例15: __call__

    def __call__(self,*args):
        if len(args) != len(self.sympy_variables):
            print 'args = ',args
            print 'sympy_vars = ',self.sympy_variables
            raise Error('invalid argument list given in call to Integrand!')
        import pdb;pdb.set_trace()
        out = self.lambdified(*args)
        out1 = self.ctypesified(len(args),tuple(args))
        print out - out1
        import pdb;pdb.set_trace()
#        print (out-out2)**2
#        exit()
        clear_cache()
        return out
开发者ID:woodscn,项目名称:BACL-MMS,代码行数:14,代码来源:integration.py


示例16: test_integral_equation

def test_integral_equation(ctx_getter, case, visualize=False):
    logging.basicConfig(level=logging.INFO)

    cl_ctx = ctx_getter()
    queue = cl.CommandQueue(cl_ctx)

    if USE_SYMENGINE and case.fmm_backend is None:
        pytest.skip("https://gitlab.tiker.net/inducer/sumpy/issues/25")

    # prevent cache 'splosion
    from sympy.core.cache import clear_cache
    clear_cache()

    from pytools.convergence import EOCRecorder
    print("qbx_order: %d, %s" % (case.qbx_order, case))

    eoc_rec_target = EOCRecorder()
    eoc_rec_td = EOCRecorder()

    have_error_data = False
    for resolution in case.resolutions:
        result = run_int_eq_test(cl_ctx, queue, case, resolution,
                visualize=visualize)

        if result.rel_err_2 is not None:
            have_error_data = True
            eoc_rec_target.add_data_point(result.h_max, result.rel_err_2)

        if result.rel_td_err_inf is not None:
            eoc_rec_td.add_data_point(result.h_max, result.rel_td_err_inf)

    if case.bc_type == "dirichlet":
        tgt_order = case.qbx_order
    elif case.bc_type == "neumann":
        tgt_order = case.qbx_order-1
    else:
        assert False

    if have_error_data:
        print("TARGET ERROR:")
        print(eoc_rec_target)
        assert eoc_rec_target.order_estimate() > tgt_order - 1.3

        if case.check_tangential_deriv:
            print("TANGENTIAL DERIVATIVE ERROR:")
            print(eoc_rec_td)
            assert eoc_rec_td.order_estimate() > tgt_order - 2.3
开发者ID:inducer,项目名称:pytential,代码行数:47,代码来源:test_scalar_int_eq.py


示例17: test_integral_equation

def test_integral_equation(
        ctx_getter, curve_name, curve_f, qbx_order, bc_type, loc_sign, k,
        target_order=7, source_order=None):
    logging.basicConfig(level=logging.INFO)

    cl_ctx = ctx_getter()
    queue = cl.CommandQueue(cl_ctx)

    # prevent cache 'splosion
    from sympy.core.cache import clear_cache
    clear_cache()

    from pytools.convergence import EOCRecorder
    print(("curve_name: %s, qbx_order: %d, bc_type: %s, loc_sign: %s, "
            "helmholtz_k: %s"
            % (curve_name, qbx_order, bc_type, loc_sign, k)))

    eoc_rec_target = EOCRecorder()
    eoc_rec_td = EOCRecorder()

    for nelements in [30, 40, 50]:
        result = run_int_eq_test(
                cl_ctx, queue, curve_f, nelements, qbx_order,
                bc_type, loc_sign, k, target_order=target_order,
                source_order=source_order)

        eoc_rec_target.add_data_point(1/nelements, result.rel_err_2)
        eoc_rec_td.add_data_point(1/nelements, result.rel_td_err_inf)

    if bc_type == "dirichlet":
        tgt_order = qbx_order
    elif bc_type == "neumann":
        tgt_order = qbx_order-1
    else:
        assert False

    print("TARGET ERROR:")
    print(eoc_rec_target)
    assert eoc_rec_target.order_estimate() > tgt_order - 1.3

    print("TANGENTIAL DERIVATIVE ERROR:")
    print(eoc_rec_td)
    assert eoc_rec_td.order_estimate() > tgt_order - 2.3
开发者ID:sj90101,项目名称:pytential,代码行数:43,代码来源:test_layer_pot.py


示例18: alt_cross_sections

 def alt_cross_sections(self):
   print('Starting to compute downset.')
   (gf, uc) = self.alt_downset()
   unclean = PegPermSet()
   uncleanlist = list()
   for PP in uc.keys():
     uncleanlist.extend(uc[PP])
   unclean = set(uncleanlist )
   print('\tDownset done. Contains',len(unclean),'unclean peg permutations.')
   # print 'Starting to compactify.'
   # unclean.compactify()
   # print '\tDone compactifying. Now contains',len(unclean),'peg permutations.'
   print('Starting to compute cross sections of UNCLEAN peg permutations.')
   cross_sections = dict()
   i = 1
   pairs = list()
   print('\tCleaning, finding bases, and loading pairs.')
   n = len(unclean)
   for P in unclean:
     if i % 20000 == 0:
       print('\t\t',i,'of',n,'...')
     cp = P.clean()
     b = P.clean_basis()
     pairs.append((cp,b))
     cross_sections[cp] = VectorSet([-1])
     i += 1
   i = 1
   del unclean
   clear_cache()
   print('\tUnioning bases.')
   for (cleaned_perm, V) in pairs:
     if i % 200000 == 0:
       print('\t\t',i,'of',n,'... dict_size =',len(cross_sections))
     # if cleaned_perm in cross_sections.keys():
     cross_sections[cleaned_perm] = V.basis_union(cross_sections[cleaned_perm])
     # else:
       # cross_sections[cleaned_perm] = V
     i += 1
   del pairs
   clear_cache()
   return (gf.simplify(), cross_sections)
开发者ID:engenmt,项目名称:permpy,代码行数:41,代码来源:pegpermset.py


示例19: enumerate

 def enumerate(self, cross_sections=None):
   if cross_sections is None:
     cross_sections = self.cross_sections()
   gc.collect()
   print('\tDone computing cross_sections. There are',len(cross_sections),'cross sections.')
   print('Starting to compute generating function.')
   gf = 0
   i = 0
   n = len(cross_sections)
   t = time.time()
   for clean_perm in cross_sections.keys():
     if i % 10000 == 0 and i > 0:
       gf = gf.simplify()
     if i % 50000 == 0 and i > 0:
       clear_cache()
     if i % 1000 == 0 and i > 0:
       print('\t\t',i,'of',n,'\ttook',(time.time()-t),'seconds.')
       t = time.time()
     gf += clean_perm.csgf(cross_sections[clean_perm])
     i += 1
   print('\tDone!')
   return gf.simplify()
开发者ID:engenmt,项目名称:permpy,代码行数:22,代码来源:pegpermset.py


示例20: sum_gfs_no_basis

 def sum_gfs_no_basis(self, S, only_clean=False):
   i = 0
   gf = 0
   n = len(S)
   t = time.time()
   print('\t\tComputing GF.')
   for PP in S:
     i += 1
     if i % 100000 == 0 and i > 0:
       print('\t\t\t',i,'of',n,'\ttook',(time.time()-t),'seconds.')
       t = time.time()
     if not PP.is_compact():
       continue
     if only_clean and not PP.is_compact_and_clean():
       continue
     if i % 10000 == 0 and i > 0:
       gf = gf.simplify()
     if i % 50000 == 0 and i > 0:
       clear_cache()
     gf += PP.csgf([])
     # print 'adding gf for',PP,'with basis []'
     
   return gf
开发者ID:engenmt,项目名称:permpy,代码行数:23,代码来源:pegpermset.py



注:本文中的sympy.core.cache.clear_cache函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compatibility.as_int函数代码示例发布时间:2022-05-27
下一篇:
Python basic.C类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap