MCPcopy
hub / github.com/tinygrad/tinygrad / ansistrip

Function ansistrip

tinygrad/helpers.py:40–40  ·  view source on GitHub ↗
(s:str)

Source from the content-addressed store, hash-verified

38def time_to_str(t:float, w=8) -> str: return next((f"{t * d:{w}.2f}{pr}" for d,pr in [(1, "s "),(1e3, "ms")] if t > 10/d), f"{t * 1e6:{w}.2f}us")
39def size_to_str(s:int) -> str: return next((f"{s / d:.2f} {pr}" for d,pr in [(1<<30, "GB"),(1<<20, "MB"),(1<<10, "KB")] if s >= d), f"{s} B")
40def ansistrip(s:str): return re.sub('\x1b\\[(K|.*?m)', '', s)
41def ansilen(s:str): return len(ansistrip(s))
42def make_tuple(x:int|Sequence[int], cnt:int) -> tuple[int, ...]: return (x,)*cnt if isinstance(x, int) else tuple(x)
43def flatten(l:Iterable[Iterable[T]]): return [item for sublist in l for item in sublist]

Callers 11

getFunction · 0.90
render_eventFunction · 0.90
fmt_coloredFunction · 0.90
kernel_graph.pyFile · 0.90
test_colored_labelMethod · 0.90
test_sqtt_cliMethod · 0.90
ansilenFunction · 0.85
word_wrapFunction · 0.85
to_function_nameFunction · 0.85

Calls 1

subMethod · 0.45

Tested by 4

test_colored_labelMethod · 0.72
test_sqtt_cliMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…