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-cluster
Commits
63c0dad6
Commit
63c0dad6
authored
Mar 25, 2018
by
rusty1s
Browse files
added consecutive call
parent
cb1b4b1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
test/test_random.py
test/test_random.py
+2
-2
torch_cluster/functions/random.py
torch_cluster/functions/random.py
+14
-3
torch_cluster/functions/utils.py
torch_cluster/functions/utils.py
+1
-1
No files found.
test/test_random.py
View file @
63c0dad6
...
@@ -7,7 +7,7 @@ def test_random():
...
@@ -7,7 +7,7 @@ def test_random():
[
2
,
3
,
6
,
5
,
0
,
0
,
4
,
5
,
3
,
1
,
3
,
6
,
0
,
3
]])
[
2
,
3
,
6
,
5
,
0
,
0
,
4
,
5
,
3
,
1
,
3
,
6
,
0
,
3
]])
# edge_attr = torch.Tensor([2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2])
# edge_attr = torch.Tensor([2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2])
rid
=
torch
.
arange
(
edge_index
.
max
()
+
1
,
out
=
edge_index
.
new
())
rid
=
torch
.
arange
(
edge_index
.
max
()
+
1
,
out
=
edge_index
.
new
())
output
=
random_cluster
(
edge_index
,
rid
,
perm_edges
=
False
)
output
=
random_cluster
(
edge_index
,
rid
=
rid
,
perm_edges
=
False
)
expected_output
=
[
0
,
1
,
2
,
0
,
4
,
1
,
6
]
expected_output
=
[
0
,
1
,
2
,
0
,
3
,
1
,
4
]
assert
output
.
tolist
()
==
expected_output
assert
output
.
tolist
()
==
expected_output
torch_cluster/functions/random.py
View file @
63c0dad6
from
.utils
import
get_func
from
.utils
import
get_func
,
consecutive
from
.degree
import
node_degree
from
.degree
import
node_degree
from
.permute
import
permute
from
.permute
import
permute
def
random_cluster
(
edge_index
,
rid
=
None
,
perm_edges
=
True
,
num_nodes
=
None
):
def
random_cluster
(
edge_index
,
batch
=
None
,
rid
=
None
,
perm_edges
=
True
,
num_nodes
=
None
):
num_nodes
=
edge_index
.
max
()
+
1
if
num_nodes
is
None
else
num_nodes
num_nodes
=
edge_index
.
max
()
+
1
if
num_nodes
is
None
else
num_nodes
row
,
col
=
permute
(
edge_index
,
num_nodes
,
rid
,
perm_edges
)
row
,
col
=
permute
(
edge_index
,
num_nodes
,
rid
,
perm_edges
)
degree
=
node_degree
(
row
,
num_nodes
,
out
=
row
.
new
())
degree
=
node_degree
(
row
,
num_nodes
,
out
=
row
.
new
())
...
@@ -12,4 +17,10 @@ def random_cluster(edge_index, rid=None, perm_edges=True, num_nodes=None):
...
@@ -12,4 +17,10 @@ def random_cluster(edge_index, rid=None, perm_edges=True, num_nodes=None):
func
=
get_func
(
'random'
,
cluster
)
func
=
get_func
(
'random'
,
cluster
)
func
(
cluster
,
row
,
col
,
degree
)
func
(
cluster
,
row
,
col
,
degree
)
return
cluster
cluster
,
u
=
consecutive
(
cluster
)
if
batch
is
None
:
return
cluster
else
:
# TODO: Fix
return
cluster
,
batch
torch_cluster/functions/utils.py
View file @
63c0dad6
...
@@ -26,7 +26,7 @@ def get_type(max, cuda):
...
@@ -26,7 +26,7 @@ def get_type(max, cuda):
return
torch
.
cuda
.
LongTensor
if
cuda
else
torch
.
LongTensor
return
torch
.
cuda
.
LongTensor
if
cuda
else
torch
.
LongTensor
def
consecutive
(
tensor
,
return_batch
=
None
):
def
consecutive
(
tensor
):
size
=
tensor
.
size
()
size
=
tensor
.
size
()
u
=
unique
(
tensor
.
view
(
-
1
))
u
=
unique
(
tensor
.
view
(
-
1
))
len
=
u
[
-
1
]
+
1
len
=
u
[
-
1
]
+
1
...
...
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