当前位置: 首页>>代码示例>>Python>>正文


Python Constants类代码示例

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


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

示例1: exec_getvar

def exec_getvar(inst):
    func_addr = Memory.read_plain(Registers.read_fp() - 4)
    rs_val = Registers.get_reg(inst['rs'])
    while True:
        arg_field = Memory.get_field(func_addr, Constants.get_str('arguments'))
        arg_obj = Memory.get_prop(arg_field)['value']
        var_field = Memory.get_field(arg_obj, rs_val)
        if var_field:  # The field is found in arguments.
            offset_addr = Memory.get_prop(var_field)['value']
            offset = Memory.get_int(offset_addr)
            Registers.set_reg(inst['rd'], Memory.read_plain(Registers.read_fp() + offset))
            break
        scope_field = Memory.get_field(func_addr, Constants.get_str('scope'))
        scope_obj = Memory.get_prop(scope_field)['value']
        var_field = Memory.get_field(scope_obj, rs_val)
        if var_field:  # The field is found in scope.
            var_obj = Memory.get_prop(var_field)['value']
            Registers.set_reg(inst['rd'], var_obj)
            break
        outer_field = Memory.get_field(func_addr, Constants.get_str('outer'))
        outer_obj = Memory.get_prop(outer_field)['value']
        if not outer_obj:  # The field 'outer' is empty.
            func_addr = Memory.read_plain(Registers.read_fp() - 4)
            scope_field = Memory.get_field(func_addr, Constants.get_str('scope'))
            scope_obj = Memory.get_prop(scope_field)['value']
            prop_addr = Memory.new_field(scope_obj, rs_val)
            obj_addr = Memory.new_obj()
            Memory.set_prop(prop_addr, value=obj_addr)
            Registers.set_reg(inst['rd'], obj_addr)
            break
        else:
            func_addr = outer_obj
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:33,代码来源:Processor.py

示例2: exec_getfield

def exec_getfield(inst):
    name_addr = Registers.get_reg(inst['rt'])
    obj_addr = Registers.get_reg(inst['rs'])
    while True:
        try:
            field = Memory.get_field(obj_addr, name_addr)
        except Exception as e:
            Memory.print_obj(obj_addr)
            Memory.print_obj(name_addr)
            raise e
        if not field:  # The field cannot be found.
            ctor_addr = Memory.get_field(obj_addr, Constants.get_str('constructor'))
            if not ctor_addr:  # There is no constructor field
                new_field = Memory.new_field(Registers.get_reg(inst['rs']), name_addr)
                Memory.set_prop(new_field, value=Memory.new_obj())
                res = Memory.get_prop(new_field)
                break
            ctor_obj = Memory.get_prop(ctor_addr)['value']
            proto_addr = Memory.get_field(ctor_obj, Constants.get_str('prototype'))
            if not proto_addr:  # There is no prototype field
                new_field = Memory.new_field(Registers.get_reg(inst['rs']), name_addr)
                Memory.set_prop(new_field, value=Memory.new_obj())
                res = Memory.get_prop(new_field)
                break
            obj_addr = Memory.get_prop(proto_addr)['value']  # Find field in the prototype
        else:
            res = Memory.get_prop(field)
            break
    Registers.set_reg(inst['rd'], res['value'])
    inc_pc(4)
    """
开发者ID:SundongCandy,项目名称:lift-js,代码行数:31,代码来源:Processor.py

示例3: gen_function_expression

def gen_function_expression(ast):
    assert ast[0] == 'FunctionExpression'
    label = Labels.function()
    func, temp = Registers.allocate(2)
    builder.inst_newfunc(func, label)
    context['function'].append(func)
    if ast[2] != '(':
        # The function has an identifier
        identifier = gen_identifier(ast[2], True)
        builder.inst_getvar(temp, identifier)
        builder.inst_move(temp, func)
        Registers.free([identifier])
    args, t1, t2 = Registers.allocate(3)
    builder.inst_la(t1, Constants.string('arguments'))
    builder.inst_getfield(args, func, t1)
    if ast[-3] != '(':
        # The function has arguments
        offset = -16
        for node in ast[-3]:
            if type(node) == list:
                arg = gen_identifier(node, True)
                builder.inst_getfield(t1, args, arg)
                builder.inst_la(t2, Constants.integer(offset))
                builder.inst_move(t1, t2)
                Registers.free([arg])
                offset -= 4
    Registers.free([t1, t2])
    # The function body starts.
    builder.enter(label)
    gen_function_body(ast[-1])
    builder.exit(label)
    context['function'].pop()
    return func
开发者ID:SundongCandy,项目名称:lift-js,代码行数:33,代码来源:Generator.py

示例4: Getkperphitmiss

    def Getkperphitmiss(self,string): # to be used within the string decay class
        ''' function used to generate a sensible kperp value based on a hit or miss rejection basis '''
        ''' Find the suitable range (min - max) of kperp values based on the given string '''
        sigma = Constants.kperpsigma()
        g_sigma = Constants.gsigma() # this value is for g(x) such that g(x) > f(x). If edited, needs to be recalculated (c.f. finding a suitable.... generation)
        #g_sigma = Constants.kperpsigma()
        B = 1/(g_sigma*g_sigma)
        A = Constants.g_kperpA()
        M = string.Getstringmass()
        kperpmin = 0
        kperpmax = M/2 # where M is the invariant mass of the string decaying
        # g_kperp = Aexp(-kperp/(gsigma*gsigma) = Aexp(-Bkperp)            #numpy.exp(-M*M/(sigma1*sigma1)) - this factor can be omited as it cancels when creating testvalue (its essentially a constant)
        G_kperp_max = -(A/B)*numpy.exp(-B*kperpmax)
        G_kperp_min = -(A/B)*numpy.exp(-B*kperpmin)
        
        while True:      
            rand_1 = numpy.random.uniform(0,1) #(kperpmin,kperpmax)
            rand_2 = numpy.random.uniform(0,1) #(kperpmin,kperpmax)
            kperp_test = -(1/B)*numpy.log(rand_1*(numpy.exp(-kperpmax*B)-1) + 1) # working inverse function
            #kperp_test = -(1/B)*numpy.log(rand_1*(1-numpy.exp(kperpmax*B)) - 1) # bfroken inverse function
            #kperp_test = -(1/B)*numpy.log(rand_1 - 1 +numpy.exp(-kperpmax*B)) # dans inverse function

            f_kperptest = numpy.exp(-kperp_test*kperp_test/(sigma*sigma))     # system designed such that gx is always greater than fx
            g_kperptest = A*numpy.exp(-B*kperp_test)
            testvalue = f_kperptest/g_kperptest
        
            if rand_2 <= testvalue:
                return kperp_test
                break
            else:
                continue
开发者ID:PyLund-MC,项目名称:PyLund,代码行数:31,代码来源:Stringdecay.py

示例5: exec_cmp

def exec_cmp(inst):
    rs_obj = Memory.get_obj(Registers.get_reg(inst['rs']))
    rt_obj = Memory.get_obj(Registers.get_reg(inst['rt']))
    if rs_obj['type'] == rt_obj['type'] and rs_obj['data'] == rt_obj['data']:
        Registers.set_reg(inst['rd'], Constants.get_int(1))
    else:
        Registers.set_reg(inst['rd'], Constants.get_int(0))
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:8,代码来源:Processor.py

示例6: exec_newfunc

def exec_newfunc(inst):
    func_addr = Memory.new_func()
    address_prop = Memory.get_field(func_addr, Constants.get_str('address'))
    Memory.set_prop(address_prop, value=Memory.new_int(Labels.query(inst['label'])))
    outer_func = Memory.read_plain(Registers.read_fp() - 4)
    outer_prop = Memory.get_field(func_addr, Constants.get_str('outer'))
    Memory.set_prop(outer_prop, value=outer_func)
    Registers.set_reg(inst['rd'], func_addr)
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:9,代码来源:Processor.py

示例7: Fixlowenergy

def Fixlowenergy(lop): # If gluon has too small an energy that it cannot be fed into PyLund after decaying, its absorbed into its neighbours.

    maxqmass = 0.6 # mass of the ud diquark pair WAS
    no_parts = len(lop)
    finished = False
    while True:
        if finished == True:
            #print "final number of particles", len(lop)
            return lop
            break
        no_parts = len(lop)
        #rint no_parts, "number particles"
        # go over the list. combine the low energy gluons absorbed into their neighbours.
        for i in range(no_parts):
            #print i, "i nubmer"
            if lop[i].Checkgluon() == True:
                vec_g = copy.deepcopy(lop[i].Getvector4D())
                vecleft = copy.deepcopy(lop[i-1].Getvector4D())
                vecright = copy.deepcopy(lop[i+1].Getvector4D())
                testleft = numpy.sqrt((vec_g + vecleft) * (vec_g + vecleft)) # invariant mass of the gluon and the partner on the left
                testright = numpy.sqrt((vec_g + vecright) * (vec_g + vecright)) # invariant mass of the gluon and the partner on the right
                Eg = vec_g.Getvector()[0]
                x = Constants.gmm() * maxqmass / Eg
                #print testleft, "testleft"
                #print testright, "testright"

                #print vec_g, "vec g into the code"
                
                if 1 < x:
                    newgluons = Absorbgluons(lop[i-1],lop[i],lop[i+1])
                    lop[i-1] = newgluons[0]
                    lop[i+1] = newgluons[1]
                    lop.pop(i) # remove the quark from the list. then need to go back to start of while to get the newest len (as it has changed)
                    #print "list popped, check if we go back to start"
                    break
                
                if testleft < (Constants.gcc()*maxqmass): # inv mass with left too small. GEt absorbed into neighbours
                    newgluons = Absorbgluons(lop[i-1],lop[i],lop[i+1])
                    lop[i-1] = newgluons[0]
                    lop[i+1] = newgluons[1]
                    lop.pop(i) # remove the quark from the list. then need to go back to start of while to get the newest len (as it has changed)
                    #print "list popped, check if we go back to start"
                    break
                if testright < (Constants.gcc()*maxqmass): # inv mass with the right too small. Get absorbed into neighbours
                    newgluons = Absorbgluons(lop[i-1],lop[i],lop[i+1])
                    lop[i-1] = newgluons[0]
                    lop[i+1] = newgluons[1]
                    lop.pop(i) # remove the quark from the list. then need to go back to start of while to get the newest len (as it has changed)
                    #print "list popped, check if we go back to start"
                    break
                else: # inv mass with neightbours is high enough. move to next gluon.
                    pass
        # get to this point once finished the lot?
            if i == (no_parts-1):
                finished = True
开发者ID:PyLund-MC,项目名称:PyLund,代码行数:55,代码来源:Hepmcconverter.py

示例8: impulse

def impulse(phys, forces, io, steps, cyclelength, fg, nextinteg, *args):
   """
   Verlet/r-RESPA propagation method.
   Implements the multiple-timestepping Verlet/r-RESPA method, also
   known as Impulse.  This propagator invokes an 'inner' propagator
   for a specific number of cycles per iteration, then computes its
   own forces.
   cf. H. Grubmuller, H. Heller, A. Windemuth and K. Schulten.
   Generalized Verlet Algorithm for Efficient Molecular Dyanmics
   Simulatiosn with Long-Range Interactions.  Molecular Simulation,
   vol. 6, pages 121-142, 1991.
   
   @type phys: Physical
   @param phys: The physical system.

   @type forces: Forces
   @param forces: MDL Forces object.

   @type io: IO
   @param io: MDL IO object.

   @type steps: int
   @param steps: Number of steps to run.

   @type cyclelength: float
   @param cyclelength: Number of iterations of inner method.

   @type fg: ForceField
   @param fg: MDL force field for evaluation.

   @type nextinteg: function handle
   @param nextinteg: Method handle for next propagator in the chain

   @type args: tuple
   @param args: Parameters for the next propagator in the chain

   """
   # Calculate initial forces
   step = 0
   # For all steps
   timestep = cyclelength*args[0]
   args2 = (args[0]*Constants.invTimeFactor(),)+args[1:len(args)]

   while (step < steps):
      # Update velocities by half a step
      phys.velocities += forces.force*0.5*timestep*phys.invmasses   # half kick
      # Run the next integrator in the chain, and store its results
      # in an array
      nextinteg(phys, forces, io, cyclelength/Constants.invTimeFactor(), *args2)
      # Calculate new forces
      fg.calculateForces(phys, forces)
      # Update velocities by another half step
      phys.velocities += forces.force*0.5*timestep*phys.invmasses   # half kick
      step = step + 1
开发者ID:badi,项目名称:protomol-mirror,代码行数:54,代码来源:impulse.py

示例9: exec_slt

def exec_slt(inst):
    rs_obj = Memory.get_obj(Registers.get_reg(inst['rs']))
    rt_obj = Memory.get_obj(Registers.get_reg(inst['rt']))
    if (rs_obj['type'] == 0 and rt_obj['type'] == 0) or \
       (rs_obj['type'] == 2 and rt_obj['type'] == 2):
        if rs_obj['data'] < rt_obj['data']:
           Registers.set_reg(inst['rd'], Constants.get_int(1))
        else:
            Registers.set_reg(inst['rd'], Constants.get_int(0))
    else:
        raise Exception('The following object are not comparable yet.\n' +
                        '%s\n%s' % (str(rs_obj), str(rt_obj)))
    inc_pc(4)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:13,代码来源:Processor.py

示例10: gen_literal

def gen_literal(ast):
    assert ast[0] == 'Literal'
    if type(ast[1]) == int:
        label = Constants.integer(ast[1])
        rd = Registers.allocate(1)[0]
        builder.inst_la(rd, label)
        return rd
    elif type(ast[1]) == str:
        return gen_string_literal(ast[1])
    elif type(ast[1]) == bool:
        label = Constants.integer(1 if ast[1] else 0)
        rd = Registers.allocate(1)[0]
        builder.inst_la(rd, label)
        return rd
开发者ID:SundongCandy,项目名称:lift-js,代码行数:14,代码来源:Generator.py

示例11: Decayparticlelist

    def Decayparticlelist(self,particlelist):
        
        stableparticles = []
        templist = particlelist # use a psudeo third list to get around pythons inability to edits lists that its iterating over.
        c = Constants.speedoflight()
        unstableparticles = particlelist # guilty until proven innocent!
        twobodyclass = Twobodydecay.twobodydecay4D()
        numberdecays = 1 # if a particle decays and forms products - then the products may decay further. this counter tells whether to keep looping or not.
        
        while numberdecays != 0:
            particlelist = templist
            templist = [] # reinitialise the templist to contain the next set of prodcut
            numberdecays = 0 # set to zero. if different that means that somethihng has decayed
            for i in range(len(particlelist)):
                
                self.Checkforkaons(particlelist[i])
                
                particlecode = particlelist[i].Getcode()
                print particlecode, "PARTICLECODE"
                
                
                
                if abs(particlecode) <= 100:
                    stableparticles.append(particlelist[i])
                    continue
                
                particlelifetime = particlelist[i].Getlifetime()
                Time = Radioactivedecay.radioactivedecay4D(particlelifetime)
                
                distance = Time * c
                #print distance, "Distacne"
                
                
                if distance >= Constants.detector_limit():  #check particle stability. if the particle gets past the detector 10CM, LIMIT, then it doesnt decay. add it to the final list.
                    stableparticles.append(particlelist[i])
                    continue
                    
                ''' If the particle decays quick enough, it will create some products. Kinematics held using standard 2/3 body decayers '''

                particledecayproducts = self.Choosehadrondecay(particlecode) # choose one of the decay routes for the unstable particle
                
                
                decayedproductlist = self.Performhadrondecay(particlelist[i],particledecayproducts)
                
                templist += decayedproductlist
                numberdecays += 1
        
        return stableparticles
开发者ID:PyLund-MC,项目名称:PyLund,代码行数:48,代码来源:Hadrondecay.py

示例12: getPRMLadder

def getPRMLadder(seq, ambigAA='X', addEnds=True, ambigEdges=None):
    prmLadder = []
    nodeGen = Constants.nodeInfoGen(seq, considerTerminalMods=True, addTerminalNodes=addEnds, ambigEdges=ambigEdges, ambigAA=ambigAA)
    for node in nodeGen:
        prmLadder.extend([node['prm']])
    
    return prmLadder
开发者ID:adevabhaktuni,项目名称:LADS,代码行数:7,代码来源:Analytics.py

示例13: gen_identifier

def gen_identifier(ast, as_literal=False):
    assert ast[0] == 'Identifier'
    ret = Registers.allocate(1)[0]
    builder.inst_la(ret, Constants.string(ast[1]))
    if not as_literal:
        builder.inst_getvar(ret, ret)  # TODO: getvar/findvar?
    return ret
开发者ID:SundongCandy,项目名称:lift-js,代码行数:7,代码来源:Generator.py

示例14: use

 def use(self, pokemonA, pokemonT):
     damage = Constants.calcDamage(self.hit_chance, self.amount, pokemonA, pokemonT, False, True);
     if damage < 0:
         damage = 1;
     
     print "%s used %s." % (pokemonA.name, self.name);
     pokemonT.health = pokemonT.health - damage;
开发者ID:nickyrayray,项目名称:IntroPythonProj,代码行数:7,代码来源:PMoves.py

示例15: exec_jalr

def exec_jalr(inst):
    Memory.write_plain(Registers.read_fp(), read_pc())  # set return address
    func_obj = Memory.get_obj(Registers.get_reg(inst['rd']))
    if func_obj['type'] == 7:  # panel.readInt()
        num = int(raw_input('Please enter an integer.\n'))
        num_addr = Memory.new_int(num)
        Memory.write_plain(Registers.read_fp() - 12, num_addr)
        inc_pc(4)
    elif func_obj['type'] == 8:  # panel.readStr()
        string = raw_input('Please enter an string.\n')
        str_addr = Memory.new_str(string)
        Memory.write_plain(Registers.read_fp() - 12, str_addr)
        inc_pc(4)
    elif func_obj['type'] == 9:  # panel.show()
        arg = Memory.read_plain(Registers.read_fp() - 16)
        Memory.print_obj(arg)
        inc_pc(4)
    else:
        assert func_obj['type'] == 4
        func_addr = Registers.get_reg(inst['rd'])
        address_field = Memory.get_field(func_addr, Constants.get_str('address'))
        address_addr = Memory.get_prop(address_field)['value']
        address = Memory.get_int(address_addr)
        Memory.write_plain(Registers.read_fp(), read_pc() + 4)
        write_pc(address)
开发者ID:SundongCandy,项目名称:lift-js,代码行数:25,代码来源:Processor.py


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