Skip to content

Commit a90c8d4

Browse files
committed
use regex to find njit functions
1 parent 9bf37f7 commit a90c8d4

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

fastmath.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,44 @@
22

33
import argparse
44
import importlib
5+
import pathlib
6+
import re
57

6-
from stumpy.cache import get_njit_funcs
8+
9+
def get_njit_funcs():
10+
"""
11+
Retrieve a list of all njit functions
12+
13+
Parameters
14+
----------
15+
None
16+
17+
Returns
18+
-------
19+
njit_funcs : list
20+
A list of all njit functions, where each element is a tuple of the form
21+
(module_name, func_name)
22+
"""
23+
pattern = r"@njit.*?def\s+\w+\("
24+
25+
stumpy_path = pathlib.Path(__file__).parent / "stumpy"
26+
filepaths = sorted(f for f in pathlib.Path(stumpy_path).iterdir() if f.is_file())
27+
28+
out = []
29+
ignore = ["__init__.py", "__pycache__"]
30+
for filepath in filepaths:
31+
fname = filepath.name
32+
if fname not in ignore and fname.endswith(".py"):
33+
file_contents = ""
34+
with open(filepath, encoding="utf8") as f:
35+
file_contents = f.read()
36+
37+
matches = re.findall(pattern, file_contents, re.DOTALL)
38+
for match in matches:
39+
func_name = match.split("def ")[-1].split("(")[0]
40+
out.append((fname.removesuffix(".py"), func_name))
41+
42+
return out
743

844

945
def check_fastmath():

0 commit comments

Comments
 (0)