Skip to content

Commit 4c6b482

Browse files
authored
Merge pull request #1 from weiyx15/master
refatory contiguous_hyedge_idx
2 parents 7938176 + fe4270a commit 4c6b482

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

SuperMoon/hyedge/utils/verify.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
from .degree import degree_hyedge
44

55

6-
def contiguous_hyedge_idx(H, hyedge_num=None):
6+
def contiguous_hyedge_idx(H):
77
node_idx, hyedge_idx = H
8-
DE = degree_hyedge(H, hyedge_num)
9-
zero_idx = torch.where(DE == 0)[0]
10-
11-
bias = torch.zeros_like(hyedge_idx)
12-
for _idx in zero_idx:
13-
bias[hyedge_idx > _idx] -= 1
14-
15-
hyedge_idx += bias
8+
unorder_pairs = [(hyedge_id, sequence_id) for sequence_id, hyedge_id in enumerate(hyedge_idx.numpy().tolist())]
9+
unorder_pairs.sort(key=lambda x: x[0])
10+
new_hyedge_id = -1
11+
pre_hyedge_id = None
12+
new_hyedge_idx = list()
13+
sequence_idx = list()
14+
for (hyedge_id, sequence_id) in unorder_pairs:
15+
if hyedge_id != pre_hyedge_id:
16+
new_hyedge_id += 1
17+
pre_hyedge_id = hyedge_id
18+
new_hyedge_idx.append(new_hyedge_id)
19+
sequence_idx.append(sequence_id)
20+
hyedge_idx[sequence_idx] = torch.LongTensor(new_hyedge_idx)
1621
return torch.stack([node_idx, hyedge_idx])
1722

1823

0 commit comments

Comments
 (0)