in experiments/codes/model/gat/layers.py [0:0]
def forward(self, x, edge_index, edge_attr, params, param_name_dict, size=None):
self.att = get_param(params, param_name_dict, "att")
self.edge_update = get_param(params, param_name_dict, "edge_update")
self.bias = None
if self.use_bias:
self.bias = get_param(params, param_name_dict, "bias")
if size is None and torch.is_tensor(x):
edge_index, _ = remove_self_loops(edge_index)
edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))
# edge_index = add_self_loops(edge_index, num_nodes=x.size(0))
self_loop_edges = torch.zeros(x.size(0), edge_attr.size(1)).to(
edge_index.device
)
edge_attr = torch.cat([edge_attr, self_loop_edges], dim=0) # (500, 10)
# Note: we need to add blank edge attributes for self loops
weight = get_param(params, param_name_dict, "weight")
if torch.is_tensor(x):
x = torch.matmul(x, weight)
else:
x = (
None if x[0] is None else torch.matmul(x[0], weight),
None if x[1] is None else torch.matmul(x[1], weight),
)
# x = x.view(-1, self.heads, self.out_channels)
# x = torch.mm(x, weight).view(-1, self.heads, self.out_channels)
return self.propagate(
edge_index, size=size, x=x, num_nodes=x.size(0), edge_attr=edge_attr
)