blob: c83d953eaa6158d39f606afb409c537c5c2089cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
"Slightly adjust indentation
%s/^ / /g
" # -> len
%s/#\(\S*\) /len(\1)/g
" for loops
%s/for\( \)\{-\}\(\S*\)\( \)\{-\}=\( \)\{-\}\(\S*\),\( \)\{-\}\(\S*\)\( \)\{-\}do/for \2 in range(\5, \7+1)/g
" Change comments
%s/--\[\[/"""/g
%s/]]/"""/g
%s/--/#/g
" Add spacing between commas
%s/\(\S\),\(\S\)/\1, \2/g
%s/local //g
%s/ then/:/g
%s/ do/:/g
%s/end//g
%s/elseif/elif/g
%s/else/else:/g
%s/true/True/g
%s/false/False/g
%s/\~=/!=/g
%s/math\.min/min/g
%s/math\.max/max/g
%s/math\.abs/abs/g
%s/__init/__init__/g
" Rewrite function declarations
%s/function \w*:\(\w*\)/ def \1/g
%s/def \(.*\)$/def \1:/g
" class declaration
%s/\(\w*\), parent = torch\.class.*$/import torch\rfrom torch.legacy import nn\r\rclass \1(nn.Module):/g
%s/input\.THNN/self._backend/g
%s/\(self\.backend\w*$\)/\1\r self._backend.library_state,/g
%s/def \(\w*\)(/def \1(self, /g
%s/__init__(self)/__init__()/g
%s/:\(\S\)/.\1/g
%s/\.cdata()//g
%s/THNN\.optionalTensor(\(.*\))/\1/g
%s/parent\./super(##, self)./g
|