File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change 33from .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
You can’t perform that action at this time.
0 commit comments