Skip to content

Commit

Permalink
removed self loops in graclus
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty1s committed Apr 18, 2018
1 parent d2ee152 commit 7985cdd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '1.0.1'
__version__ = '1.0.2'
url = 'https://github.com/rusty1s/pytorch_cluster'

install_requires = ['cffi']
Expand Down
2 changes: 1 addition & 1 deletion torch_cluster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .graclus import graclus_cluster
from .grid import grid_cluster

__version__ = '1.0.1'
__version__ = '1.0.2'

__all__ = ['graclus_cluster', 'grid_cluster', '__version__']
3 changes: 2 additions & 1 deletion torch_cluster/graclus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .utils.loop import remove_self_loops
from .utils.perm import randperm, sort_row, randperm_sort_row
from .utils.ffi import graclus

Expand All @@ -19,7 +20,6 @@ def graclus_cluster(row, col, weight=None, num_nodes=None):
>>> weight = torch.Tensor([1, 1, 1, 1])
>>> cluster = graclus_cluster(row, col, weight)
"""

num_nodes = row.max() + 1 if num_nodes is None else num_nodes

if row.is_cuda: # pragma: no cover
Expand All @@ -28,6 +28,7 @@ def graclus_cluster(row, col, weight=None, num_nodes=None):
row, col = randperm(row, col)
row, col = randperm_sort_row(row, col, num_nodes)

row, col = remove_self_loops(row, col)
cluster = row.new(num_nodes)
graclus(cluster, row, col, weight)

Expand Down
3 changes: 3 additions & 0 deletions torch_cluster/utils/loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def remove_self_loops(row, col):
mask = row != col
return row[mask], col[mask]

0 comments on commit 7985cdd

Please sign in to comment.