Caffe2 - Python API
A deep learning, cross platform ML framework
extract_cwrap.py
1 from optparse import OptionParser
2 
3 parser = OptionParser()
4 parser.add_option('-o', '--output', help='where to write the result file.',
5  action='store', default='.')
6 options, _ = parser.parse_args()
7 
8 files = [
9  # '../../csrc/cudnn/cuDNN.cwrap',
10  '../../csrc/generic/TensorMethods.cwrap',
11  # '../../csrc/generic/methods/SparseTensor.cwrap',
12  '../../csrc/generic/methods/Tensor.cwrap',
13  '../../csrc/generic/methods/TensorApply.cwrap',
14  '../../csrc/generic/methods/TensorCompare.cwrap',
15  '../../csrc/generic/methods/TensorCuda.cwrap',
16  '../../csrc/generic/methods/TensorMath.cwrap',
17  '../../csrc/generic/methods/TensorRandom.cwrap',
18  # '../../csrc/generic/methods/TensorSerialization.cwrap',
19 ]
20 
21 declaration_lines = []
22 
23 for filename in files:
24  with open(filename, 'r') as file:
25  in_declaration = False
26  for line in file.readlines():
27  line = line.rstrip()
28  if line == '[[':
29  in_declaration = True
30  declaration_lines.append(line)
31  elif line == ']]':
32  in_declaration = False
33  declaration_lines.append(line)
34  elif in_declaration:
35  declaration_lines.append(line)
36 
37 with open(options.output, 'w') as output:
38  output.write('\n'.join(declaration_lines) + '\n')