ONE - On-device Neural Engine
Loading...
Searching...
No Matches
export_constant Namespace Reference

Functions

 main ()
 

Function Documentation

◆ main()

export_constant.main ( void  )

Definition at line 23 of file export_constant.py.

23def main():
24 parser = argparse.ArgumentParser(
25 description='Export CONSTANT value with given file format.')
26 parser.add_argument('-c',
27 '--constant',
28 type=str,
29 required=True,
30 help='Constant name to export')
31 parser.add_argument(
32 '-f',
33 '--format',
34 type=str,
35 required=True,
36 choices=['cfg', 'txt'],
37 help=
38 'File format to export. The created cfg file contains CONSTANT under the one-optimize section.'
39 )
40 parser.add_argument(
41 '--exclusive',
42 action='store_true',
43 help='Exports the rest of the options except for the given constant')
44 parser.add_argument('-o',
45 '--output_path',
46 type=str,
47 required=True,
48 help='Path to output')
49
50 args = parser.parse_args()
51
52 if not hasattr(CONSTANT, args.constant):
53 raise NameError('Not found given constant name')
54
55 if args.exclusive:
56 constant_to_exclude = getattr(CONSTANT, args.constant)
57 constant_to_export = []
58 for opt in CONSTANT.OPTIMIZATION_OPTS:
59 if opt[0] in constant_to_exclude:
60 continue
61 constant_to_export.append(opt[0])
62 else:
63 constant_to_export = getattr(CONSTANT, args.constant)
64
65 if args.format == 'cfg':
66 SECTION_TO_EXPORT = 'one-optimize'
67 config = configparser.ConfigParser()
68 config[SECTION_TO_EXPORT] = dict()
69 for constant in constant_to_export:
70 config[SECTION_TO_EXPORT][constant] = 'True'
71
72 with open(args.output_path, 'w') as f:
73 config.write(f)
74
75 if args.format == 'txt':
76 with open(args.output_path, 'w') as f:
77 for constant in constant_to_export:
78 f.write(f"{constant}\n")
79
80
int main(void)

References main().

Referenced by main().