def test_remove_none(): """Test whether remove_none removes Nones correctly.""" assert len(tuple(range(5))) == len(tuple(remove_none(range(5)))) for (initial, filtered) in zip(range(5), remove_none(range(5))): assert initial == filtered assert len(tuple(remove_none([1, 2, None, 3]))) == 3 assert tuple(remove_none([1, 2, None, 3])) == (1, 2, 3)
def update_clock_request(self, event): """Update the next clock request based on the event.""" clock_requests = [self._next_clock_request, event] clock_requests = list(remove_none(clock_requests)) try: self._next_clock_request = min(clock_requests) except ValueError: self._next_clock_request = None
def next_clock_request(self): """Return the next clock update requested by the pipeline.""" clock_requests = list(remove_none( pipe.next_clock_request for pipe in self.pipes_clocked )) if not clock_requests: return None # print('Next clock request for pipeline {}: {}'.format(self, min(clock_requests))) return min(clock_requests)
def next_clock_request(self): """Return the next clock update requested by the pipeline.""" clock_requests = [self._next_clock_request] clock_requests.extend( remove_none(clocked.next_clock_request for clocked in itertools.chain(self.bottom_clocked, self.top_clocked))) if not clock_requests: return None # print('Next clock request for pipe {}: {}'.format(self, min(clock_requests))) return min(clock_requests)
def sync_down(self): """Synchronize the queues or buffers from the top layer to the bottom layer. The to_send() of top will be passed down to the send() of bottom. Returns the earliest clock update requested by the sender of any link in the top layer. """ clock_requests = list( remove_none(self._sync_down(top) for top in self.top)) if clock_requests: self.update_clock_request(min(clock_requests)) return self.next_clock_request
def sync_up(self): """Synchronize the queues or buffers from the bottom layer to the top layer. The receive() of bottom will be passed up to the to_receive() of top. Returns the earliest clock update requested by the receiver of any link in the bottom layer. """ clock_requests = list( remove_none(self._sync_up(bottom) for bottom in self.bottom)) if clock_requests: self.update_clock_request(min(clock_requests)) return self.next_clock_request