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
c7aeb8d2
Commit
c7aeb8d2
authored
Oct 29, 2019
by
rusty1s
Browse files
randomly sample entries if entries exceed max_num_neighbors
parent
73412857
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
test/test_radius.py
test/test_radius.py
+2
-0
torch_cluster/radius.py
torch_cluster/radius.py
+9
-8
No files found.
test/test_radius.py
View file @
c7aeb8d2
...
@@ -6,6 +6,8 @@ from torch_cluster import radius, radius_graph
...
@@ -6,6 +6,8 @@ from torch_cluster import radius, radius_graph
from
.utils
import
grad_dtypes
,
devices
,
tensor
from
.utils
import
grad_dtypes
,
devices
,
tensor
grad_dtypes
=
[
torch
.
float
]
def
coalesce
(
index
):
def
coalesce
(
index
):
N
=
index
.
max
().
item
()
+
1
N
=
index
.
max
().
item
()
+
1
...
...
torch_cluster/radius.py
View file @
c7aeb8d2
...
@@ -5,6 +5,12 @@ if torch.cuda.is_available():
...
@@ -5,6 +5,12 @@ if torch.cuda.is_available():
import
torch_cluster.radius_cuda
import
torch_cluster.radius_cuda
def
sample
(
col
,
count
):
if
col
.
size
(
0
)
>
count
:
col
=
col
[
torch
.
randperm
(
col
.
size
(
0
))][:
count
]
return
col
def
radius
(
x
,
y
,
r
,
batch_x
=
None
,
batch_y
=
None
,
max_num_neighbors
=
32
):
def
radius
(
x
,
y
,
r
,
batch_x
=
None
,
batch_y
=
None
,
max_num_neighbors
=
32
):
r
"""Finds for each element in :obj:`y` all points in :obj:`x` within
r
"""Finds for each element in :obj:`y` all points in :obj:`x` within
distance :obj:`r`.
distance :obj:`r`.
...
@@ -64,20 +70,15 @@ def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32):
...
@@ -64,20 +70,15 @@ 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
)
y
=
torch
.
cat
([
y
,
2
*
r
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
dim
=-
1
)
tree
=
scipy
.
spatial
.
cKDTree
(
x
.
detach
().
numpy
())
tree
=
scipy
.
spatial
.
cKDTree
(
x
.
detach
().
numpy
())
_
,
col
=
tree
.
query
(
col
=
tree
.
query_ball_point
(
y
.
detach
().
numpy
(),
r
)
y
.
detach
().
numpy
(),
k
=
max_num_neighbors
,
distance_upper_bound
=
r
+
1e-8
)
col
=
[
sample
(
torch
.
tensor
(
c
),
max_num_neighbors
)
for
c
in
col
]
col
=
[
torch
.
from_numpy
(
c
).
to
(
torch
.
long
)
for
c
in
col
]
row
=
[
torch
.
full_like
(
c
,
i
)
for
i
,
c
in
enumerate
(
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
)
row
,
col
=
torch
.
cat
(
row
,
dim
=
0
),
torch
.
cat
(
col
,
dim
=
0
)
mask
=
col
<
int
(
tree
.
n
)
mask
=
col
<
int
(
tree
.
n
)
return
torch
.
stack
([
row
[
mask
],
col
[
mask
]],
dim
=
0
)
return
torch
.
stack
([
row
[
mask
],
col
[
mask
]],
dim
=
0
)
def
radius_graph
(
x
,
def
radius_graph
(
x
,
r
,
batch
=
None
,
loop
=
False
,
max_num_neighbors
=
32
,
r
,
batch
=
None
,
loop
=
False
,
max_num_neighbors
=
32
,
flow
=
'source_to_target'
):
flow
=
'source_to_target'
):
r
"""Computes graph edges to all points within a given distance.
r
"""Computes graph edges to all points within a given distance.
...
...
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