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
5549ef86
Commit
5549ef86
authored
Feb 12, 2019
by
rusty1s
Browse files
no sort
parent
79f67548
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
test/test_radius.py
test/test_radius.py
+11
-5
torch_cluster/radius.py
torch_cluster/radius.py
+1
-1
No files found.
test/test_radius.py
View file @
5549ef86
...
...
@@ -7,6 +7,13 @@ from torch_cluster import radius, radius_graph
from
.utils
import
grad_dtypes
,
devices
,
tensor
def
coalesce
(
index
):
N
=
index
.
max
().
item
()
+
1
tensor
=
torch
.
sparse_coo_tensor
(
index
,
index
.
new_ones
(
index
.
size
(
1
)),
torch
.
Size
([
N
,
N
]))
return
tensor
.
coalesce
().
indices
()
@
pytest
.
mark
.
parametrize
(
'dtype,device'
,
product
(
grad_dtypes
,
devices
))
def
test_radius
(
dtype
,
device
):
x
=
tensor
([
...
...
@@ -28,7 +35,7 @@ def test_radius(dtype, device):
batch_y
=
tensor
([
0
,
1
],
torch
.
long
,
device
)
out
=
radius
(
x
,
y
,
2
,
batch_x
,
batch_y
,
max_num_neighbors
=
4
)
assert
out
.
tolist
()
==
[[
0
,
0
,
0
,
0
,
1
,
1
],
[
0
,
1
,
2
,
3
,
5
,
6
]]
assert
coalesce
(
out
)
.
tolist
()
==
[[
0
,
0
,
0
,
0
,
1
,
1
],
[
0
,
1
,
2
,
3
,
5
,
6
]]
@
pytest
.
mark
.
parametrize
(
'dtype,device'
,
product
(
grad_dtypes
,
devices
))
...
...
@@ -40,7 +47,6 @@ def test_radius_graph(dtype, device):
[
+
1
,
-
1
],
],
dtype
,
device
)
row
,
col
=
radius_graph
(
x
,
r
=
(
2.0
+
1e-16
))
assert
row
.
tolist
()
==
[
0
,
0
,
1
,
1
,
2
,
2
,
3
,
3
]
assert
col
.
tolist
()
==
[
1
,
3
,
0
,
2
,
1
,
3
,
0
,
2
]
out
=
radius_graph
(
x
,
r
=
2
)
assert
coalesce
(
out
).
tolist
()
==
[[
0
,
0
,
1
,
1
,
2
,
2
,
3
,
3
],
[
1
,
3
,
0
,
2
,
1
,
3
,
0
,
2
]]
torch_cluster/radius.py
View file @
5549ef86
...
...
@@ -65,7 +65,7 @@ def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32):
y
=
torch
.
cat
([
y
,
2
*
r
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
dim
=-
1
)
tree
=
scipy
.
spatial
.
cKDTree
(
x
)
_
,
col
=
tree
.
query
(
y
,
k
=
max_num_neighbors
,
distance_upper_bound
=
r
)
_
,
col
=
tree
.
query
(
y
,
k
=
max_num_neighbors
,
distance_upper_bound
=
r
+
1e-8
)
col
=
[
torch
.
tensor
(
c
)
for
c
in
col
]
row
=
[
torch
.
full_like
(
c
,
i
)
for
i
,
c
in
enumerate
(
col
)]
row
,
col
=
torch
.
cat
(
row
,
dim
=
0
),
torch
.
cat
(
col
,
dim
=
0
)
...
...
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