def _parse_formula(formula: deque) -> list: if not is_deque(formula): raise ParseError('Invalid formula: {}'.format(formula)) if len(formula) == 0: raise ParseError('Formula is empty') expr_lst = [] token = formula.popleft() if not is_string(token): raise ParseError('Invalid token for start of formula: {}'.format(token)) if token.lower() == 'and': # preconds and effects only use 'and' keyword exprs = _parse_expr_list(formula) expr_lst.extend(exprs) else: # parse single expression formula.appendleft(token) expr_lst.append(_parse_single_expr_string(formula)) return expr_lst
def _addTileIfAdmissible(deq:collections.deque, t: basic_map.Tile): if (_getPassable(t) and not t._has_been_visited): if t not in deq: deq.appendleft(t)
def _append_bothsides(deq: collections.deque) -> Generator[None, Any, None]: """Alternately add to each side of a deque.""" while True: deq.append((yield)) deq.appendleft((yield))
def move(snake: deque, dr: int, np: Pos = None, eat: bool = False): if np is None: np = next_pos(snake, dr) snake.appendleft(np) if not eat: snake.pop()
def _new_key(key: str, key_arr: deque) -> str: key_arr.appendleft(str(key)) return "_".join(key_arr)
def _finder_penalty_add_history(self, currentrunlength: int, runhistory: collections.deque) -> None: if runhistory[0] == 0: currentrunlength += self._size # Add white border to initial run runhistory.appendleft(currentrunlength)
def recursion(self, node: Node, que: collections.deque): if not node.visited: node.visited = True for directed_node in node.links: self.recursion(directed_node, que) que.appendleft(node.value)
def queueThreadInterpolator(framesQueue: collections.deque, outFramesQueue: Queue, inFramesList: list, gpuid, interpolatorConfig): ''' Loads frames from queue (Or from HDD if frame not in queue) to interpolate, based on frames specified in inFramesList Puts frameLists in output queue to save :param interpolatorConfig: ''' device, model = setupRIFE(installPath, gpuid) while True: listOfCompletedFrames = [] if len(framesQueue) == 0: freeVRAM(model,device) break currentQueuedFrameList: QueuedFrameList = framesQueue.popleft() # Comment out printing progress message - using TQDM now # print(currentQueuedFrameList.interpolationProgress.progressMessage) # Raise event interpolationProgressUpdate(currentQueuedFrameList.interpolationProgress) listOfAllFramesInterpolate: list = currentQueuedFrameList.frameList # Copy start and end files if not os.path.exists(currentQueuedFrameList.startFrameDest): shutil.copy(currentQueuedFrameList.startFrame, currentQueuedFrameList.startFrameDest) if not os.path.exists(currentQueuedFrameList.endFrameDest): shutil.copy(currentQueuedFrameList.endFrame, currentQueuedFrameList.endFrameDest) try: for frame in listOfAllFramesInterpolate: queuedFrame: QueuedFrame = frame success = False # Load begin frame from HDD or RAM beginFrame = None # If the current frame pair uses an original_frame - Then grab it from RAM if queuedFrame.beginFrame == currentQueuedFrameList.startFrameDest: with inFrameGetLock: for i in range(0,len(inFramesList)): if currentQueuedFrameList.startFrame == str(inFramesList[i]): beginFrame = inFramesList[i] break if beginFrame is None: for i in range(0, len(listOfCompletedFrames)): if str(listOfCompletedFrames[i]) == queuedFrame.beginFrame: beginFrame = listOfCompletedFrames[i] break if beginFrame is None: beginFrame = FrameFile(queuedFrame.beginFrame) beginFrame.loadImageData() # Load end frame from HDD or RAM endFrame = None # If the current frame pair uses an original_frame - Then grab it from RAM if queuedFrame.endFrame == currentQueuedFrameList.endFrameDest: with inFrameGetLock: for i in range(0,len(inFramesList)): if currentQueuedFrameList.endFrame == str(inFramesList[i]): endFrame = inFramesList[i] break if endFrame is None: for i in range(0, len(listOfCompletedFrames)): if str(listOfCompletedFrames[i]) == queuedFrame.endFrame: endFrame = listOfCompletedFrames[i] break if endFrame is None: endFrame = FrameFile(queuedFrame.endFrame) endFrame.loadImageData() # Initialise the mid frame with the output path midFrame = FrameFile(queuedFrame.middleFrame) midFrame = rifeInterpolate(device, model, beginFrame, endFrame, midFrame, queuedFrame.scenechangeSensitivity,scale=interpolatorConfig.getUhdScale()) listOfCompletedFrames.append(midFrame) # outFramesQueue.put(midFrame) except Exception as e: # Put current frame back into queue for another batch thread to process framesQueue.appendleft(currentQueuedFrameList) if hasattr(e, 'message'): print(e.message) else: print(e) # Kill batch thread freeVRAM(model,device) print("Freed VRAM from dead thread") break # Add interpolated frames to png save queue outputFramesList:SaveFramesList = SaveFramesList(listOfCompletedFrames,currentQueuedFrameList.startFrameDest,currentQueuedFrameList.endFrameDest) '''for midFrame1 in listOfCompletedFrames: outFramesQueue.put(midFrame1)''' outFramesQueue.put(outputFramesList) # Start frame is no-longer needed, remove from RAM with inFrameGetLock: for i in range(0,len(inFramesList)): if str(inFramesList[i]) == currentQueuedFrameList.startFrame: inFramesList.pop(i) break # Update progress bar global progressBar progressBar.update(1) print("END")
def _insert_dummy_tile(floor_deque: deque): floor_deque.appendleft(FloorTile(True)) return floor_deque
def padleft(state: deque, count: int): for i in range(count): state.appendleft(Pot(False, state[0].id - 1))
def section_to_div(sections: deque) -> deque: html_conversion_dict = { "#": ("<h1 class=\"blog_text\">", "</h1>"), "##": ("<h2 class=\"blog_text\">", "</h2>"), "###": ("<h3 class=\"blog_text\">", "</h3>"), "p": ("<p class=\"blog_text\">", "</p>"), "*": ("<li class=\"blog_text\">", "</li>"), "n": ("<li class=\"blog_text\">", "</li>"), } md_symbol_set = ("#", "##", "###", "*") stopping_set = ('<h1', '<h2', "<h3", "<p ", "<ol", "<ul", "<im") def md_type_identifier(chunk_to_parse: str) -> str: parsed_string = chunk_to_parse.split(" ") if parsed_string[0] in md_symbol_set: md_symbol = parsed_string.pop(0) return f'{html_conversion_dict[md_symbol][0]}{md_style_to_html(" ".join(parsed_string))}{html_conversion_dict[md_symbol][1]}' elif parsed_string[0][0] == '!': full_line = " ".join(parsed_string) ref_pattern = "\((.*?)\)" alt_pattern = "\[(.*?)\]" reference = re.search(ref_pattern, full_line).group(1) alt_text = re.search(alt_pattern, full_line).group(1) return f'<img class="blog_image" src="/media/blog_images/{reference}.png" alt="{alt_text}"><br>' elif re.search("^[0-9]+[.]", chunk_to_parse): parsed_string.pop(0) return f'<li class=\"blog_text\">{md_style_to_html(" ".join(parsed_string))}</li>' else: return f'<p class=\"blog_text\">{md_style_to_html(" ".join(parsed_string))}</p>' current_section = sections.popleft() while current_section[0:3] not in stopping_set: if current_section[0] == "*": sections.append("<ul class=\"blog_text\">") while current_section[0] == "*": sections.append(md_type_identifier(current_section)) current_section = sections.popleft() sections.append("</ul>") else: if re.search("^[0-9]+[.]", current_section): sections.append("<ol class=\"blog_text\">") while re.search("^[0-9]+[.]", current_section): sections.append(md_type_identifier(current_section)) current_section = sections.popleft() sections.append("</ol>") else: if current_section[0:3] == "```": sections.append("<div class=\"code_snippet\">") current_section = sections.popleft() while current_section[0:3] != "```": sections.append( f'<p class=\"code\">{current_section}</p>') current_section = sections.popleft() sections.append("</div>") current_section = sections.popleft() else: if current_section == "!!NEWLINE!!": sections.append("<br>") current_section = sections.popleft() else: sections.append(md_type_identifier(current_section)) current_section = sections.popleft() sections.appendleft(current_section) return sections
def reverse(x: deque, y): x.appendleft(y) return x
def build_dq(self, left_ptr, right_ptr, queue: deque): if right_ptr: queue.appendleft(right_ptr) if left_ptr: queue.appendleft(left_ptr)
def _addTileIfAdmissible(deq: collections.deque, t: basic_map.Tile): if (_getPassable(t) and not t._has_been_visited): if t not in deq: deq.appendleft(t)