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-scatter
Commits
28fce4cd
Commit
28fce4cd
authored
Sep 13, 2021
by
rusty1s
Browse files
use in-place exp() + remove eps
parent
6a1525b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
torch_scatter/composite/softmax.py
torch_scatter/composite/softmax.py
+4
-4
No files found.
torch_scatter/composite/softmax.py
View file @
28fce4cd
...
@@ -4,8 +4,8 @@ from torch_scatter import scatter_sum, scatter_max
...
@@ -4,8 +4,8 @@ from torch_scatter import scatter_sum, scatter_max
from
torch_scatter.utils
import
broadcast
from
torch_scatter.utils
import
broadcast
def
scatter_softmax
(
src
:
torch
.
Tensor
,
index
:
torch
.
Tensor
,
dim
:
int
=
-
1
,
def
scatter_softmax
(
src
:
torch
.
Tensor
,
index
:
torch
.
Tensor
,
eps
:
floa
t
=
1e
-1
2
)
->
torch
.
Tensor
:
dim
:
in
t
=
-
1
)
->
torch
.
Tensor
:
if
not
torch
.
is_floating_point
(
src
):
if
not
torch
.
is_floating_point
(
src
):
raise
ValueError
(
'`scatter_softmax` can only be computed over tensors '
raise
ValueError
(
'`scatter_softmax` can only be computed over tensors '
'with floating point data types.'
)
'with floating point data types.'
)
...
@@ -16,10 +16,10 @@ def scatter_softmax(src: torch.Tensor, index: torch.Tensor, dim: int = -1,
...
@@ -16,10 +16,10 @@ def scatter_softmax(src: torch.Tensor, index: torch.Tensor, dim: int = -1,
max_per_src_element
=
max_value_per_index
.
gather
(
dim
,
index
)
max_per_src_element
=
max_value_per_index
.
gather
(
dim
,
index
)
recentered_scores
=
src
-
max_per_src_element
recentered_scores
=
src
-
max_per_src_element
recentered_scores_exp
=
recentered_scores
.
exp
()
recentered_scores_exp
=
recentered_scores
.
exp
_
()
sum_per_index
=
scatter_sum
(
recentered_scores_exp
,
index
,
dim
)
sum_per_index
=
scatter_sum
(
recentered_scores_exp
,
index
,
dim
)
normalizing_constants
=
sum_per_index
.
add_
(
eps
).
gather
(
dim
,
index
)
normalizing_constants
=
sum_per_index
.
gather
(
dim
,
index
)
return
recentered_scores_exp
.
div
(
normalizing_constants
)
return
recentered_scores_exp
.
div
(
normalizing_constants
)
...
...
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