MCPcopy
hub / github.com/tinygrad/tinygrad / gen_stats

Function gen_stats

sz.py:17–33  ·  view source on GitHub ↗
(base_path=".")

Source from the content-addressed store, hash-verified

15def is_js_token(s): return len(s) and not s.startswith('//')
16
17def gen_stats(base_path="."):
18 table = []
19 for path, _, files in os.walk(os.path.join(base_path, "tinygrad")):
20 for name in files:
21 if not (name.endswith(".py") or name.endswith(".js")): continue
22 if any(s in path.replace('\\', '/') for s in ['tinygrad/runtime/autogen', 'tinygrad/viz/assets']): continue
23 filepath = os.path.join(path, name)
24 relfilepath = os.path.relpath(filepath, base_path).replace('\\', '/')
25 if name.endswith(".js"):
26 with open(filepath) as file_: lines = [line.strip() for line in file_.readlines()]
27 token_count, line_count = sum(len(line.split()) for line in lines if is_js_token(line)), sum(1 for line in lines if is_js_token(line))
28 else:
29 with tokenize.open(filepath) as file_:
30 tokens = [t for t in tokenize.generate_tokens(file_.readline) if t.type in TOKEN_WHITELIST and not is_docstring(t)]
31 token_count, line_count = len(tokens), len(set([x for t in tokens for x in range(t.start[0], t.end[0]+1)]))
32 if line_count > 0: table.append([relfilepath, line_count, token_count/line_count])
33 return table
34
35def gen_diff(table_old, table_new):
36 table = []

Callers 1

sz.pyFile · 0.85

Calls 7

is_js_tokenFunction · 0.85
is_docstringFunction · 0.85
splitMethod · 0.80
appendMethod · 0.80
walkMethod · 0.45
replaceMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…