File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 4747from .cat import cat , cat_diag # noqa
4848from .rw import random_walk # noqa
4949from .metis import partition # noqa
50+ from .bandwidth import reverse_cuthill_mckee # noqa
5051from .saint import saint_subgraph # noqa
5152from .padding import padded_index , padded_index_select # noqa
5253
9091 'cat_diag' ,
9192 'random_walk' ,
9293 'partition' ,
94+ 'reverse_cuthill_mckee' ,
9395 'saint_subgraph' ,
9496 'padded_index' ,
9597 'padded_index_select' ,
Original file line number Diff line number Diff line change 1+ import scipy .sparse as sp
2+ from typing import Tuple , Optional
3+
4+ import torch
5+ from torch_sparse .tensor import SparseTensor
6+ from torch_sparse .permute import permute
7+
8+
9+ def reverse_cuthill_mckee (src : SparseTensor ,
10+ is_symmetric : Optional [bool ] = None
11+ ) -> Tuple [SparseTensor , torch .Tensor ]:
12+
13+ if is_symmetric is None :
14+ is_symmetric = src .is_symmetric ()
15+
16+ if not is_symmetric :
17+ src = src .to_symmetric ()
18+
19+ sp_src = src .to_scipy (layout = 'csr' )
20+ perm = sp .csgraph .reverse_cuthill_mckee (sp_src , symmetric_mode = True ).copy ()
21+ perm = torch .from_numpy (perm ).to (torch .long ).to (src .device ())
22+
23+ out = permute (src , perm )
24+
25+ return out , perm
26+
27+
28+ SparseTensor .reverse_cuthill_mckee = reverse_cuthill_mckee
You can’t perform that action at this time.
0 commit comments