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
645f3ddf
Commit
645f3ddf
authored
Mar 27, 2018
by
rusty1s
Browse files
clean up
parent
59121c84
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
29 additions
and
27 deletions
+29
-27
test/test_serial.py
test/test_serial.py
+7
-6
torch_cluster/__init__.py
torch_cluster/__init__.py
+2
-2
torch_cluster/functions/grid.py
torch_cluster/functions/grid.py
+2
-1
torch_cluster/functions/serial.py
torch_cluster/functions/serial.py
+6
-5
torch_cluster/functions/utils/consecutive.py
torch_cluster/functions/utils/consecutive.py
+0
-13
torch_cluster/functions/utils/degree.py
torch_cluster/functions/utils/degree.py
+0
-0
torch_cluster/functions/utils/ffi.py
torch_cluster/functions/utils/ffi.py
+12
-0
torch_cluster/functions/utils/normalized_cut.py
torch_cluster/functions/utils/normalized_cut.py
+0
-0
torch_cluster/functions/utils/permute.py
torch_cluster/functions/utils/permute.py
+0
-0
No files found.
test/test_
random
.py
→
test/test_
serial
.py
View file @
645f3ddf
import
torch
#
import torch
from
torch_cluster
import
random
_cluster
#
from torch_cluster import
serial
_cluster
def
test_random
():
def
test_serial
():
edge_index
=
torch
.
LongTensor
([[
0
,
0
,
0
,
1
,
2
,
3
,
3
,
3
,
4
,
5
,
5
,
5
,
6
,
6
],
pass
[
2
,
3
,
6
,
5
,
0
,
0
,
4
,
5
,
3
,
1
,
3
,
6
,
0
,
3
]])
# ed_index = torch.LongTensor([[0, 0, 0, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6],
# [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=rid, perm_edges=False)
# output = random_cluster(edge_index, rid=rid, perm_edges=False)
# expected_output = [0, 1, 2, 0, 3, 1, 4]
# expected_output = [0, 1, 2, 0, 3, 1, 4]
...
...
torch_cluster/__init__.py
View file @
645f3ddf
from
.functions.grid
import
sparse_grid_cluster
,
dense_grid_cluster
from
.functions.grid
import
sparse_grid_cluster
,
dense_grid_cluster
from
.functions.
random
import
random
_cluster
from
.functions.
serial
import
serial
_cluster
__version__
=
'0.2.6'
__version__
=
'0.2.6'
__all__
=
[
__all__
=
[
'sparse_grid_cluster'
,
'dense_grid_cluster'
,
'
random
_cluster'
,
'sparse_grid_cluster'
,
'dense_grid_cluster'
,
'
serial
_cluster'
,
'__version__'
'__version__'
]
]
torch_cluster/functions/grid.py
View file @
645f3ddf
...
@@ -2,7 +2,8 @@ from __future__ import division
...
@@ -2,7 +2,8 @@ from __future__ import division
import
torch
import
torch
from
.utils
import
get_dynamic_func
,
consecutive
from
.utils.ffi
import
get_dynamic_func
from
.utils.consecutive
import
consecutive
def
_preprocess
(
position
,
size
,
batch
=
None
,
start
=
None
):
def
_preprocess
(
position
,
size
,
batch
=
None
,
start
=
None
):
...
...
torch_cluster/functions/
random
.py
→
torch_cluster/functions/
serial
.py
View file @
645f3ddf
from
.utils
import
get_func
,
consecutive
from
.utils.permute
import
random_permute
from
.degree
import
node_degree
from
.utils.degree
import
node_degree
from
.permute
import
permute
from
.utils.ffi
import
get_func
from
.utils.consecutive
import
consecutive
def
random
_cluster
(
edge_index
,
batch
=
None
,
num_nodes
=
None
):
def
serial
_cluster
(
edge_index
,
batch
=
None
,
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
)
row
,
col
=
random_
permute
(
edge_index
,
num_nodes
)
degree
=
node_degree
(
row
,
num_nodes
,
out
=
row
.
new
())
degree
=
node_degree
(
row
,
num_nodes
,
out
=
row
.
new
())
cluster
=
edge_index
.
new
(
num_nodes
).
fill_
(
-
1
)
cluster
=
edge_index
.
new
(
num_nodes
).
fill_
(
-
1
)
...
...
torch_cluster/functions/utils.py
→
torch_cluster/functions/utils
/consecutive
.py
View file @
645f3ddf
import
torch
import
torch
from
torch_unique
import
unique
from
torch_unique
import
unique
from
.._ext
import
ffi
def
get_func
(
name
,
tensor
):
cuda
=
'_cuda'
if
tensor
.
is_cuda
else
''
return
getattr
(
ffi
,
'cluster_{}{}'
.
format
(
name
,
cuda
))
def
get_dynamic_func
(
name
,
tensor
):
typename
=
type
(
tensor
).
__name__
.
replace
(
'Tensor'
,
''
)
cuda
=
'cuda_'
if
tensor
.
is_cuda
else
''
return
getattr
(
ffi
,
'cluster_{}_{}{}'
.
format
(
name
,
cuda
,
typename
))
def
get_type
(
max
,
cuda
):
def
get_type
(
max
,
cuda
):
if
max
<=
255
:
if
max
<=
255
:
...
...
torch_cluster/functions/degree.py
→
torch_cluster/functions/
utils/
degree.py
View file @
645f3ddf
File moved
torch_cluster/functions/utils/ffi.py
0 → 100644
View file @
645f3ddf
from
..._ext
import
ffi
def
get_func
(
name
,
tensor
):
cuda
=
'_cuda'
if
tensor
.
is_cuda
else
''
return
getattr
(
ffi
,
'cluster_{}{}'
.
format
(
name
,
cuda
))
def
get_dynamic_func
(
name
,
tensor
):
typename
=
type
(
tensor
).
__name__
.
replace
(
'Tensor'
,
''
)
cuda
=
'cuda_'
if
tensor
.
is_cuda
else
''
return
getattr
(
ffi
,
'cluster_{}_{}{}'
.
format
(
name
,
cuda
,
typename
))
torch_cluster/functions/
max_weigh
t.py
→
torch_cluster/functions/
utils/normalized_cu
t.py
View file @
645f3ddf
File moved
torch_cluster/functions/permute.py
→
torch_cluster/functions/
utils/
permute.py
View file @
645f3ddf
File moved
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