-
Notifications
You must be signed in to change notification settings - Fork 0
/
candidate_op.py
74 lines (60 loc) · 1.63 KB
/
candidate_op.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Created on Sat May 8 15:18:42 2021
@author: HP
"""
import torch.nn as nn
class BasicOp(nn.Module):
def __init__(self, **kwargs):
super(BasicOp, self).__init__()
def forward(self, inputs, **kwargs):
raise NotImplementedError
def __repr__(self):
cfg = []
for (key, value) in self.setting:
cfg += [str(key) + ': ' + str(value)]
return str(self.type) + '(' + ', '.join(cfg) + ')'
@property
def type(self):
raise NotImplementedError
@property
def setting(self):
raise NotImplementedError
class pos_calucution(nn.Module):
def __init__(self, adj_id):
super(pos_calucution, self).__init__()
self.adj_id = adj_id
def forward(self, adj_list):
adj = adj_list[self.adj_id]
out = adj
return out
def create_op_first(op_name):
pre_adj_v1 = 0
pre_adj_v2 = 1
pre_adj_v3 = 2
pre_adj_v4 = 3
name2op = {
'TG':
lambda: pos_calucution(pre_adj_v1),
'SG':
lambda: pos_calucution(pre_adj_v2),
'TG+SG':
lambda: pos_calucution(pre_adj_v3),
'SG+TG':
lambda: pos_calucution(pre_adj_v4),
}
op = name2op[op_name]()
return op
def create_op_second(op_name):
pre_adj_v1 = 0
pre_adj_v2 = 1
pre_adj_v3 = 2
name2op = {
'TG':
lambda: pos_calucution(pre_adj_v1),
'SG':
lambda: pos_calucution(pre_adj_v2),
'TC':
lambda: pos_calucution(pre_adj_v3),
}
op = name2op[op_name]()
return op