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
c5045e2f
Commit
c5045e2f
authored
Oct 06, 2020
by
rusty1s
Browse files
fix numerical issues in nn
parent
24595a8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
+12
-10
torch_cluster/nearest.py
torch_cluster/nearest.py
+12
-10
No files found.
torch_cluster/nearest.py
View file @
c5045e2f
...
@@ -79,16 +79,18 @@ def nearest(x: torch.Tensor, y: torch.Tensor,
...
@@ -79,16 +79,18 @@ def nearest(x: torch.Tensor, y: torch.Tensor,
assert
y
.
size
(
0
)
==
batch_y
.
size
(
0
)
assert
y
.
size
(
0
)
==
batch_y
.
size
(
0
)
# Translate and rescale x and y to [0, 1].
# Translate and rescale x and y to [0, 1].
min_xy
=
min
(
x
.
min
().
item
(),
y
.
min
().
item
())
if
batch_x
is
not
None
and
batch_y
is
not
None
:
x
,
y
=
x
-
min_xy
,
y
-
min_xy
min_xy
=
min
(
x
.
min
().
item
(),
y
.
min
().
item
())
x
,
y
=
x
-
min_xy
,
y
-
min_xy
max_xy
=
max
(
x
.
max
().
item
(),
y
.
max
().
item
())
x
.
div_
(
max_xy
)
max_xy
=
max
(
x
.
max
().
item
(),
y
.
max
().
item
())
y
.
div_
(
max_xy
)
x
.
div_
(
max_xy
)
y
.
div_
(
max_xy
)
# Concat batch/features to ensure no cross-links between examples.
x
=
torch
.
cat
([
x
,
2
*
x
.
size
(
1
)
*
batch_x
.
view
(
-
1
,
1
).
to
(
x
.
dtype
)],
-
1
)
# Concat batch/features to ensure no cross-links between examples.
y
=
torch
.
cat
([
y
,
2
*
y
.
size
(
1
)
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
-
1
)
D
=
x
.
size
(
-
1
)
x
=
torch
.
cat
([
x
,
2
*
D
*
batch_x
.
view
(
-
1
,
1
).
to
(
x
.
dtype
)],
-
1
)
y
=
torch
.
cat
([
y
,
2
*
D
*
batch_y
.
view
(
-
1
,
1
).
to
(
y
.
dtype
)],
-
1
)
return
torch
.
from_numpy
(
return
torch
.
from_numpy
(
scipy
.
cluster
.
vq
.
vq
(
x
.
detach
().
cpu
(),
scipy
.
cluster
.
vq
.
vq
(
x
.
detach
().
cpu
(),
...
...
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