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
34f083a9
Commit
34f083a9
authored
Apr 08, 2019
by
rusty1s
Browse files
potential windows/numpy conversion fix
parent
7aee6467
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
9 deletions
+14
-9
torch_cluster/knn.py
torch_cluster/knn.py
+6
-4
torch_cluster/nearest.py
torch_cluster/nearest.py
+3
-1
torch_cluster/radius.py
torch_cluster/radius.py
+5
-4
No files found.
torch_cluster/knn.py
View file @
34f083a9
...
...
@@ -67,10 +67,12 @@ def knn(x, y, k, batch_x=None, batch_y=None):
x
=
torch
.
cat
([
x
,
2
*
x
.
size
(
1
)
*
batch_x
.
view
(
-
1
,
1
).
to
(
x
.
dtype
)],
dim
=-
1
)
y
=
torch
.
cat
([
y
,
2
*
y
.
size
(
1
)
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
dim
=-
1
)
tree
=
scipy
.
spatial
.
cKDTree
(
x
)
dist
,
col
=
tree
.
query
(
y
,
k
=
k
,
distance_upper_bound
=
x
.
size
(
1
))
dist
,
col
=
torch
.
tensor
(
dist
),
torch
.
tensor
(
col
)
row
=
torch
.
arange
(
col
.
size
(
0
)).
view
(
-
1
,
1
).
repeat
(
1
,
k
)
tree
=
scipy
.
spatial
.
cKDTree
(
x
.
detach
().
numpy
())
dist
,
col
=
tree
.
query
(
y
.
detach
().
cpu
(),
k
=
k
,
distance_upper_bound
=
x
.
size
(
1
))
dist
=
torch
.
from_numpy
(
dist
).
to
(
x
.
dtype
)
col
=
torch
.
from_numpy
(
col
).
to
(
torch
.
long
)
row
=
torch
.
arange
(
col
.
size
(
0
),
dtype
=
torch
.
long
).
view
(
-
1
,
1
).
repeat
(
1
,
k
)
mask
=
1
-
torch
.
isinf
(
dist
).
view
(
-
1
)
row
,
col
=
row
.
view
(
-
1
)[
mask
],
col
.
view
(
-
1
)[
mask
]
...
...
torch_cluster/nearest.py
View file @
34f083a9
...
...
@@ -64,4 +64,6 @@ def nearest(x, y, batch_x=None, batch_y=None):
x
=
torch
.
cat
([
x
,
2
*
x
.
size
(
1
)
*
batch_x
.
view
(
-
1
,
1
).
to
(
x
.
dtype
)],
dim
=-
1
)
y
=
torch
.
cat
([
y
,
2
*
y
.
size
(
1
)
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
dim
=-
1
)
return
torch
.
from_numpy
(
scipy
.
cluster
.
vq
.
vq
(
x
,
y
)[
0
]).
to
(
torch
.
long
)
return
torch
.
from_numpy
(
scipy
.
cluster
.
vq
.
vq
(
x
.
detach
().
cpu
(),
y
.
detach
().
cpu
())[
0
]).
to
(
torch
.
long
)
torch_cluster/radius.py
View file @
34f083a9
...
...
@@ -64,12 +64,13 @@ def radius(x, y, r, batch_x=None, batch_y=None, max_num_neighbors=32):
x
=
torch
.
cat
([
x
,
2
*
r
*
batch_x
.
view
(
-
1
,
1
).
to
(
x
.
dtype
)],
dim
=-
1
)
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
+
1e-8
)
col
=
[
torch
.
tensor
(
c
)
for
c
in
col
]
tree
=
scipy
.
spatial
.
cKDTree
(
x
.
detach
().
numpy
())
_
,
col
=
tree
.
query
(
y
.
detach
().
numpy
(),
k
=
max_num_neighbors
,
distance_upper_bound
=
r
+
1e-8
)
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
,
col
=
torch
.
cat
(
row
,
dim
=
0
),
torch
.
cat
(
col
,
dim
=
0
)
mask
=
col
<
tree
.
n
mask
=
col
<
int
(
tree
.
n
)
return
torch
.
stack
([
row
[
mask
],
col
[
mask
]],
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