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


Python memory.Memory类代码示例

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


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

示例1: _determine_blockshape

    def _determine_blockshape(self, outputSlot):
        """
        Choose a blockshape using the slot metadata (if available) or an arbitrary guess otherwise.
        """
        input_shape = outputSlot.meta.shape
        ideal_blockshape = outputSlot.meta.ideal_blockshape
        ram_usage_per_requested_pixel = outputSlot.meta.ram_usage_per_requested_pixel

        num_channels = 1
        tagged_shape = outputSlot.meta.getTaggedShape()
        
        # Generally, we don't want to split requests across channels.
        if 'c' in tagged_shape.keys():
            num_channels = tagged_shape['c']
            channel_index = tagged_shape.keys().index('c')
            input_shape = input_shape[:channel_index] + input_shape[channel_index+1:]
            if ideal_blockshape:
                # Never enlarge 'ideal' in the channel dimension.
                num_channels = ideal_blockshape[channel_index]
                ideal_blockshape = ideal_blockshape[:channel_index] + ideal_blockshape[channel_index+1:]

        max_blockshape = input_shape
        available_ram = Memory.getAvailableRamComputation()
        
        if ram_usage_per_requested_pixel is None:
            # Make a conservative guess: 2*(bytes for dtype) * (num channels) + (fudge factor=4)
            ram_usage_per_requested_pixel = 2*outputSlot.meta.dtype().nbytes*num_channels + 4
            warnings.warn( "Unknown per-pixel RAM requirement.  Making a guess." )

        # Safety factor (fudge factor): Double the estimated RAM usage per pixel
        safety_factor = 2.0
        logger.info("Estimated RAM usage per pixel is {} * safety factor ({})"
                    .format( Memory.format(ram_usage_per_requested_pixel), safety_factor ) )
        ram_usage_per_requested_pixel *= safety_factor
        
        if ideal_blockshape is None:
            blockshape = determineBlockShape( input_shape, available_ram/(self._num_threads*ram_usage_per_requested_pixel) )
            if 'c' in outputSlot.meta.getAxisKeys():
                blockshape = blockshape[:channel_index] + (num_channels,) + blockshape[channel_index:]
            warnings.warn( "Chose an arbitrary request blockshape {}".format( blockshape ) )
        else:
            logger.info("determining blockshape assuming available_ram is {}"
                        ", split between {} threads"
                        .format(Memory.format(available_ram), self._num_threads))
            
            # By convention, ram_usage_per_requested_pixel refers to the ram used when requesting ALL channels of a 'pixel'
            # Therefore, we do not include the channel dimension in the blockshapes here.
            blockshape = determine_optimal_request_blockshape( max_blockshape,
                                                               ideal_blockshape,
                                                               ram_usage_per_requested_pixel, 
                                                               self._num_threads, 
                                                               available_ram )
            if 'c' in outputSlot.meta.getAxisKeys():
                blockshape = blockshape[:channel_index] + (num_channels,) + blockshape[channel_index:]
            logger.info( "Chose blockshape: {}".format( blockshape ) )
            fmt = Memory.format(ram_usage_per_requested_pixel *
                                numpy.prod(blockshape[:-1]))
            logger.info("Estimated RAM usage per block is {}".format(fmt))

        return blockshape
开发者ID:satishgoda,项目名称:lazyflow,代码行数:60,代码来源:bigRequestStreamer.py

示例2: Context

class Context(object):

    def __init__(self, instructions):
        self.registers = Registers()
        self.flags = Flags()
        self.instructions = instructions
        self.heap = Memory(size=40, mode=HEAP, start_address=0x0000)
        self.stack = Memory(size=40, mode=STACK, start_address=0xFFFF)
        self.registers.set(SP, 0xFFFF)

    def run(self):
        """
        initialize the context and execute the first instruction
        """
        self.registers.reset()

    def step(self):
        """
        execute the next instruction whose address in the EIP value
        :return:
        """
        self.registers.tick()
        self.flags.tick()
        self.heap.tick()
        self.stack.tick()
        next_address = self.registers.get(IP).value
        if next_address < len(self.instructions):
            next_instruction = self.instructions[next_address]
            next_instruction.execute(self)
            self.registers.set(IP, next_address + 1)
            return True
        else:
            return False
开发者ID:Groutcho,项目名称:exii,代码行数:33,代码来源:context.py

示例3: __init__

 def __init__(self, instructions):
     self.registers = Registers()
     self.flags = Flags()
     self.instructions = instructions
     self.heap = Memory(size=40, mode=HEAP, start_address=0x0000)
     self.stack = Memory(size=40, mode=STACK, start_address=0xFFFF)
     self.registers.set(SP, 0xFFFF)
开发者ID:Groutcho,项目名称:exii,代码行数:7,代码来源:context.py

示例4: __init__

 def __init__(self, parent, name, address, device_info=None, auto_update=False):
     self.auto_update = auto_update
     self.parent = parent
     self.last_values = {}
     Memory.__init__(self, name=name, width_bits=32, address=address, length_bytes=4)
     self.process_info(device_info)
     LOGGER.debug('New Register %s' % self)
开发者ID:james-smith-za,项目名称:casperfpga,代码行数:7,代码来源:register.py

示例5: try_alf_word

 def try_alf_word(self):
     if self.get() == '"':
         # exactly five mix-chars in inverted or
         self.next()
         if self.get() == '"':
             s = ""
         else:
             s = self.get()
             if self.look() != '"':
                 raise UnquotedStringError(self.line.argument)
             self.next()
     else:
         # less than six mix-chars not in inverted
         s = self.line.argument.rstrip('\n\r')
         self.ct = len(self.tokens) - 1
         if s is None:
             s = ""
     s = s[:5]
     while len(s) < 5:
         s += " "
     # now s - string with len = 5
     word = Memory.positive_zero()
     for i in xrange(1, 6):
         word[i] = charset.ord(s[i - 1])
         if word[i] is None:
             raise InvalidCharError(s[i - 1])
     return Memory.mix2dec(word)
开发者ID:JulienPalard,项目名称:mix-machine,代码行数:27,代码来源:parse_argument.py

示例6: try_w_exp

 def try_w_exp(self):
     """This function DO SELF.NEXT()"""
     word = Memory.positive_zero()
     value = self.try_exp()
     if value is None:
         return None
     if self.look() == "(":
         self.next()
         field = self.try_f_part()
     else:
         # it's property of w-exp that empty f-part means not default value
         # but 0:5
         field = 5
         self.next()
     if Memory.apply_to_word(value, word, field) is None:
         raise InvalidFieldSpecError(field)
     while True:
         if self.get() != ",":
             break
         self.next()
         value = self.try_exp()
         if value is None:
             raise ExpectedExpError(self.get_all_before_this())
         if self.look() == "(":
             self.next()
             field = self.try_f_part()
         else:
             field = get_codes(self.line.operation)[1]
             self.next()
         if Memory.apply_to_word(value, word, field) is None:
             raise InvalidFieldSpecError(field)
     return Memory.mix2dec(word)
开发者ID:JulienPalard,项目名称:mix-machine,代码行数:32,代码来源:parse_argument.py

示例7: __init__

	def __init__(self, env, model, epsilon=.9, min_epsilon=.1, epsilon_decay=1e-3):
		self.env = env
		self.model = model
		self.epsilon = epsilon
		self.min_epsilon = min_epsilon
		self.epsilon_decay = epsilon_decay
		self.episode = 0
		self.positiveMemory = Memory(model=self.model, episode_max_size=20)
		self.negativeMemory = Memory(model=self.model, episode_max_size=10)
开发者ID:blazer82,项目名称:ai,代码行数:9,代码来源:agent.py

示例8: memory

def memory():
    """
    Create Memory instance for testing.
    :return: new memory instance
    """
    from gb import GB
    from memory import Memory
    gb = GB()
    mem = Memory(gb)
    mem.load_cartridge(cartridge_data=bytes.fromhex("00")*0x8000)
    return mem
开发者ID:geosohh,项目名称:pgbe,代码行数:11,代码来源:test_memory.py

示例9: _build_memory

def _build_memory(screen):
    """ Initialize CPC464 memory map """
    memory = Memory(screen)
    memory.add_chunk(0x0000, RomChunk(_get_data_from_file('6128L.rom')))
    memory.add_chunk(0xC000, UpperRomChunk(0, _get_data_from_file('6128U-basic.rom')))
    memory.apply_ram_map(0)
    memory.dump_map()
    return memory
开发者ID:mxsscott,项目名称:cpyc,代码行数:8,代码来源:cpc6128.py

示例10: __init__

    def __init__(self, parent, name, address, length_bytes, device_info=None):
        """

        :param parent: Parent object who owns this TenGbe instance
        :param name: Unique name of the instance
        :param address:
        :param length_bytes:
        :param device_info: Information about this device
        :return:
        """
        Memory.__init__(self, name, 32, address, length_bytes)
        Gbe.__init__(self, parent, name, address, length_bytes, device_info)
开发者ID:ska-sa,项目名称:casperfpga,代码行数:12,代码来源:tengbe.py

示例11: run

def run(path, debug, max_cycles):
    with open(path, "rb") as rom_file:
        debug_title = debug == "TITLE"
        debug_header = debug == "HEADER" or debug == "ALL"
        debug_mem = debug == "MEMORY" or debug == "ALL"
        debug_instructions = debug == "INSTRUCTIONS" or debug == "ALL"
        debug_registers = debug == "REGISTERS" or debug == "ALL"
        rom = [i for i in rom_file.read()]
        
        header = Header(rom, debug_header)
        mem = Memory(rom, header)
        if debug_title:
            print("Title: " + header.name)
        if debug_instructions:
            print("PC:    Operation")
        
        interrupts = Interrupts()
        cpu = CPU(mem, interrupts, debug_instructions, debug_registers)
        timer = Timer(interrupts)
        sound = Sound()
        link = Link()
        joypad = Joypad()
        lcdc = LCDC(mem, interrupts)
        mem.setupIO(lcdc, interrupts, timer, sound, link, joypad)
        total_cycles = 0

        try:
            pygame.init()
            while cpu.run_state != "QUIT":
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        cpu.run_state = "QUIT"
                    if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
                        joypad.keyEvent(event)

                interrupts.update()
                if cpu.run_state == "RUN":
                    cpu.run()
                else:
                    cpu.cycles += 1

                timer.update(cpu.cycles)
                lcdc.update(cpu.cycles)

                total_cycles += cpu.popCycles()
                if max_cycles >= 0 and total_cycles > max_cycles:
                    cpu.run_state = "QUIT"
        except AssertionError as e:
            if debug_mem:
                mem.display()
            traceback.print_tb(e.__traceback__)
        except KeyboardInterrupt as e:
            if debug_mem:
                mem.display()
        else:
            if debug_mem:
                mem.display()
开发者ID:rukai,项目名称:GameToy,代码行数:57,代码来源:gametoy.py

示例12: test

def test(test_iter, folds, training_folds):
    results = []
    mem = Memory()
    for i in range(test_iter):
        print "iteration %d ..." % (i + 1)
        ini_set = split_set2(folds, senseval.instances()[0:])
        for j in range(folds):
            print"...fold %d ..." % (j + 1)
            sets = partition_set(training_folds, ini_set, j)
            print "-$$Train time$$-"
            mem.train(sets[0])
            print "-$$results time$$-"
            results.append(mem.test(sets[1]))
    return results
开发者ID:jdesch,项目名称:MM-Algorithm,代码行数:14,代码来源:main.py

示例13: test_main

def test_main():
    mem = Memory()
    print "loading data_set"
    ini_set = split_set2(5, senseval.instances()[0:10000])
    data_set = partition_set(4, ini_set, 0)
    #Serializer.save("/tmp/portioned_data", data_set)
    #data_set = Serializer.load("/tmp/portioned_data")
    print "training data"
    mem.train(data_set[0])
    #print "saving data"
    #mem.save_values("/tmp/mem_internals")
    #mem.load_values("/tmp/mem_internals")
    print "------*********testing**********------"
    results = mem.test(data_set[1])
    print "%3.1f %% accuracy" %(sum(results)/len(results) * 100)
开发者ID:jdesch,项目名称:MM-Algorithm,代码行数:15,代码来源:main.py

示例14: __init__

    def __init__(self, queuetype, memtype, t_cs_val = 13):
        self.t_cs = t_cs_val 
        self.t_slice = 80 # in ms
        self.t_memmove = 10 # in ms
        if queuetype == "FCFS":
            self.process_queue = FCFSQueue() 
        elif queuetype == "SRT":
            self.process_queue = SRTQueue() 
        elif queuetype == "PWA":
            self.process_queue = PWAQueue() 
        elif queuetype == "RR":
            self.process_queue = FCFSQueue() 
 
        self.mem = Memory(memtype) 
        self.queueType = queuetype
        self.CPUIdle = True
        self.n = 0
        self.active_n = 0
        self.maxID = 1 
        self.processInCPU = None #Note: processInCPU is the process in use of CPU, NOT in content switch
        self.burstTimeSum = 0
        self.waitTimeSum = 0
        self.waitTimeNum = 0
        self.turnaroundTimeSum = 0
        self.contentSwitchSum = 0
        self.processInCPU_tobe = None 
        self.defragtime = 0
        self.p_list = []
开发者ID:xil12008,项目名称:operatingsystemproject,代码行数:28,代码来源:CPU.py

示例15: __init__

 def __init__(self, size_state, nr_actions, memorySize, discountFactor, learningRate, learnStart):
     self.input_size = size_state
     self.output_size = nr_actions
     self.memory = Memory(memorySize)
     self.discountFactor = discountFactor
     self.learnStart = learnStart
     self.learningRate = learningRate
开发者ID:vyraun,项目名称:deep-q-learning,代码行数:7,代码来源:deepq.py


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