def notnone(*args): seq,ref,method = args[0],fun.first(args[1:] or [0]),fun.first(args[2:] or [average]) print 'notnone from %s'%ref try: if np: return method(*((v for v in seq if v is not None and not np.isnan(v)),ref)) else: return method(*((v for v in seq if v is not None),ref)) except: traceback.print_exc() return ref
def test_first_tuple(): test_data = ( 1, 2, 3, 4, 5, ) assert functional.first(test_data) == 1
def dispatch(self, STATE): # Check if any functional/execution units are available to dispatch FU = first(lambda fu: not fu.isOccupied(STATE), self.functional_units) if FU is None: return # Filter all RS Entries whos instruction is ready to be dispatched readyRSIDS = [rs_entry.get_inst_seq_id() for rs_entry in self.RSEntries if rs_entry.Busy and rs_entry.isReady()] if len(readyRSIDS) == 0: return # Find oldest RS Entry and dispatch to appropriate FU oldestRSID = reduce(lambda oldest_inst_seq_id, inst_seq_id: min(oldest_inst_seq_id, inst_seq_id), readyRSIDS) oldestRS = self.findRSEntry(oldestRSID) # Reset RS entry oldestRS.dispatch(STATE, FU)
def findLSQEntry(self, inst_seq_id): return first(lambda entry: entry.inst_seq_id == inst_seq_id, self.entries)
def findRSEntry(self, inst_seq_id): return first(lambda rs: rs.get_inst_seq_id() == inst_seq_id, self.RSEntries)
def test_first_none(): test_data = range(0) assert functional.first(test_data) is None
def test_first_string(): test_data = 'qwerty' assert functional.first(test_data) == 'q'
def test_first_list(): test_data = [1, 2, 3, 4, 5] assert functional.first(test_data) == 1