Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-sparse
Commits
57852a66
Commit
57852a66
authored
May 06, 2020
by
rusty1s
Browse files
bandwidth implementation
parent
539e2068
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
torch_sparse/__init__.py
torch_sparse/__init__.py
+2
-0
torch_sparse/bandwidth.py
torch_sparse/bandwidth.py
+28
-0
No files found.
torch_sparse/__init__.py
View file @
57852a66
...
@@ -47,6 +47,7 @@ from .matmul import matmul # noqa
...
@@ -47,6 +47,7 @@ from .matmul import matmul # noqa
from
.cat
import
cat
,
cat_diag
# noqa
from
.cat
import
cat
,
cat_diag
# noqa
from
.rw
import
random_walk
# noqa
from
.rw
import
random_walk
# noqa
from
.metis
import
partition
# noqa
from
.metis
import
partition
# noqa
from
.bandwidth
import
reverse_cuthill_mckee
# noqa
from
.saint
import
saint_subgraph
# noqa
from
.saint
import
saint_subgraph
# noqa
from
.padding
import
padded_index
,
padded_index_select
# noqa
from
.padding
import
padded_index
,
padded_index_select
# noqa
...
@@ -90,6 +91,7 @@ __all__ = [
...
@@ -90,6 +91,7 @@ __all__ = [
'cat_diag'
,
'cat_diag'
,
'random_walk'
,
'random_walk'
,
'partition'
,
'partition'
,
'reverse_cuthill_mckee'
,
'saint_subgraph'
,
'saint_subgraph'
,
'padded_index'
,
'padded_index'
,
'padded_index_select'
,
'padded_index_select'
,
...
...
torch_sparse/bandwidth.py
0 → 100644
View file @
57852a66
import
scipy.sparse
as
sp
from
typing
import
Tuple
,
Optional
import
torch
from
torch_sparse.tensor
import
SparseTensor
from
torch_sparse.permute
import
permute
def
reverse_cuthill_mckee
(
src
:
SparseTensor
,
is_symmetric
:
Optional
[
bool
]
=
None
)
->
Tuple
[
SparseTensor
,
torch
.
Tensor
]:
if
is_symmetric
is
None
:
is_symmetric
=
src
.
is_symmetric
()
if
not
is_symmetric
:
src
=
src
.
to_symmetric
()
sp_src
=
src
.
to_scipy
(
layout
=
'csr'
)
perm
=
sp
.
csgraph
.
reverse_cuthill_mckee
(
sp_src
,
symmetric_mode
=
True
).
copy
()
perm
=
torch
.
from_numpy
(
perm
).
to
(
torch
.
long
).
to
(
src
.
device
())
out
=
permute
(
src
,
perm
)
return
out
,
perm
SparseTensor
.
reverse_cuthill_mckee
=
reverse_cuthill_mckee
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment