def covers_range(self, rng): if len(rng) != len(self.shape): return False for s, (rb, re, rs) in zip(self.shape, rng): # Shape has to be positive if isinstance(s, sp.Basic): olds = s if 'positive' in s.assumptions0: s = sp.Symbol(str(s), **s.assumptions0) else: s = sp.Symbol(str(s), positive=True, **s.assumptions0) if isinstance(rb, sp.Basic): rb = rb.subs({olds: s}) if isinstance(re, sp.Basic): re = re.subs({olds: s}) if isinstance(rs, sp.Basic): rs = rs.subs({olds: s}) try: if rb < 0: # Negative offset return False except TypeError: # cannot determine truth value of Relational pass #print('WARNING: Cannot evaluate relational expression %s, assuming true.' % (rb > 0), # 'If this expression is false, please refine symbol definitions in the program.') try: if re > s: # Beyond shape return False except TypeError: # cannot determine truth value of Relational pass #print('WARNING: Cannot evaluate relational expression %s, assuming true.' % (re < s), # 'If this expression is false, please refine symbol definitions in the program.') return True
def replace(self, repl_dict): for i, ((rb, re, rs), ts) in enumerate(zip(self.ranges, self.tile_sizes)): self.ranges[i] = ( rb.subs(repl_dict) if symbolic.issymbolic(rb) else rb, re.subs(repl_dict) if symbolic.issymbolic(re) else re, rs.subs(repl_dict) if symbolic.issymbolic(rs) else rs) self.tile_sizes[i] = (ts.subs(repl_dict) if symbolic.issymbolic(ts) else ts)
def case_highlight(seq, subseq): """ Highlights all instances of subseq in seq by making them uppercase and everything else lowercase. """ return re.subs(subseq.lower(), subseq.upper(), seq.lower())
while not q.empty(): print(q.get()) import sys sys.version sys.version_info sys.path import re re.compile(r'') re.search(pattern, string) re.match(pattern, string).group(2) re.findall() re.split(pattern, string[, maxsplit=0, flags=0]) re.sub('', '', s) re.subs('', '', s) import random random.random() random.randint(1,20) random.uniform(10,20) random.seed(4) random.choice([1,2,3,4,5,6]) random.shuffle([1,2,3,4,5,7]) random.sample(range(10),3) import time time.sleep(3) list(time.localtime()) time.time()