def test_function(self):
    in_features = self.x.shape[1]
    out_features = self.x.shape[1]

    def get_round_sum(tens, n_digits=3):
        val = torch.sum(tens, dim=int((not self.opt['attention_norm_idx'])))
        return ((val * (10 ** n_digits)).round() / (10 ** n_digits))
    att_layer = SpGraphAttentionLayer(in_features, out_features, self.opt, self.device, concat=True)
    (attention, _) = att_layer(self.x, self.edge)
    self.assertTrue((attention.shape == (self.edge.shape[1], self.opt['heads'])))
    dense_attention1 = to_dense_adj(self.edge, edge_attr=attention[:, 0]).squeeze()
    dense_attention2 = to_dense_adj(self.edge, edge_attr=attention[:, 1]).squeeze()
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention1), 1.0)))
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention2), 1.0)))
    self.assertTrue(torch.all((attention > 0.0)))
    self.assertTrue(torch.all((attention <= 1.0)))
    dataset = get_dataset(self.opt, '../data', False)
    data = dataset.data
    in_features = data.x.shape[1]
    out_features = data.x.shape[1]
    att_layer = SpGraphAttentionLayer(in_features, out_features, self.opt, self.device, concat=True)
    (attention, _) = att_layer(data.x, data.edge_index)
    self.assertTrue((attention.shape == (data.edge_index.shape[1], self.opt['heads'])))
    dense_attention1 = to_dense_adj(data.edge_index, edge_attr=attention[:, 0]).squeeze()
    dense_attention2 = to_dense_adj(data.edge_index, edge_attr=attention[:, 1]).squeeze()
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention1), 1.0)))
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention2), 1.0)))
    self.assertTrue(torch.all((attention > 0.0)))
    self.assertTrue(torch.all((attention <= 1.0)))
def test_function(self):
    in_features = self.x.shape[1]
    out_features = self.x.shape[1]

    def get_round_sum(tens, n_digits=3):
        val = torch.sum(tens, dim=int((not self.opt['attention_norm_idx'])))
        return ((val * (10 ** n_digits)).round() / (10 ** n_digits))
    att_layer = SpGraphAttentionLayer(in_features, out_features, self.opt, self.device, concat=True)
    (attention, _) = att_layer(self.x, self.edge)
    self.assertTrue((attention.shape == (self.edge.shape[1], self.opt['heads'])))
    dense_attention1 = to_dense_adj(self.edge, edge_attr=attention[:, 0]).squeeze()
    dense_attention2 = to_dense_adj(self.edge, edge_attr=attention[:, 1]).squeeze()
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention1), 1.0)))
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention2), 1.0)))
    self.assertTrue(torch.all((attention > 0.0)))
    self.assertTrue(torch.all((attention <= 1.0)))
    dataset = get_dataset(self.opt, '../data', False)
    data = dataset.data
    in_features = data.x.shape[1]
    out_features = data.x.shape[1]
    att_layer = SpGraphAttentionLayer(in_features, out_features, self.opt, self.device, concat=True)
    (attention, _) = att_layer(data.x, data.edge_index)
    self.assertTrue((attention.shape == (data.edge_index.shape[1], self.opt['heads'])))
    dense_attention1 = to_dense_adj(data.edge_index, edge_attr=attention[:, 0]).squeeze()
    dense_attention2 = to_dense_adj(data.edge_index, edge_attr=attention[:, 1]).squeeze()
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention1), 1.0)))
    self.assertTrue(torch.all(torch.eq(get_round_sum(dense_attention2), 1.0)))
    self.assertTrue(torch.all((attention > 0.0)))
    self.assertTrue(torch.all((attention <= 1.0)))