3 from .nested_dict
import nested_dict
7 'CodeTemplate',
'IDENT_REGEX',
'YamlLoader',
'nested_dict',
8 'split_name_params',
'write',
12 from src.ATen.code_template
import CodeTemplate
15 CodeTemplate = import_module(
'code_template',
'aten/src/ATen/code_template.py').CodeTemplate
25 from yaml
import CLoader
as YamlLoader
27 from yaml
import Loader
as YamlLoader
29 GENERATED_COMMENT = CodeTemplate(
30 "@" +
"generated from ${filename}")
34 IDENT_REGEX =
r'(^|\W){}($|\W)' 39 def split_name_params(prototype):
40 name, params = re.match(
r'(\w+)\((.*)\)', prototype).groups()
41 return name, params.split(
', ')
49 def uninplace_api_name(api_name):
50 if api_name.endswith(
'_')
and not api_name.endswith(
'__'):
51 api_name = api_name[:-1]
52 if api_name.endswith(
'_out'):
53 api_name = api_name[:-4]
57 def write(dirname, name, template, env):
58 env[
'generated_comment'] = GENERATED_COMMENT.substitute(filename=template.filename)
59 path = os.path.join(dirname, name)
62 with open(path,
'r') as f: 66 new_val = template.substitute(env)
67 if old_val != new_val:
68 with open(path,
'w')
as f:
69 print(
"Writing {}".format(path))
72 print(
"Skipped writing {}".format(path))