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
28f42bdc
Commit
28f42bdc
authored
Dec 17, 2017
by
rusty1s
Browse files
cleaner
parent
416a2603
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
18 deletions
+13
-18
torch_scatter/functions/__init__.py
torch_scatter/functions/__init__.py
+4
-16
torch_scatter/functions/utils.py
torch_scatter/functions/utils.py
+9
-2
No files found.
torch_scatter/functions/__init__.py
View file @
28f42bdc
import
torch
from
torch.autograd
import
Variable
from
.scatter
import
scatter
from
.utils
import
gen_output
from
.utils
import
gen_filled_tensor
,
gen_output
def
scatter_add_
(
output
,
index
,
input
,
dim
=
0
):
...
...
@@ -42,10 +39,7 @@ def scatter_div(index, input, dim=0, max_index=None, fill_value=1):
def
scatter_mean_
(
output
,
index
,
input
,
dim
=
0
):
if
torch
.
is_tensor
(
input
):
output_count
=
output
.
new
(
output
.
size
()).
fill_
(
0
)
else
:
output_count
=
Variable
(
output
.
data
.
new
(
output
.
size
()).
fill_
(
0
))
output_count
=
gen_filled_tensor
(
output
,
output
.
size
(),
fill_value
=
0
)
scatter
(
'mean'
,
dim
,
output
,
index
,
input
,
output_count
)
output_count
[
output_count
==
0
]
=
1
output
/=
output_count
...
...
@@ -58,10 +52,7 @@ def scatter_mean(index, input, dim=0, max_index=None, fill_value=0):
def
scatter_max_
(
output
,
index
,
input
,
dim
=
0
):
if
torch
.
is_tensor
(
input
):
output_index
=
index
.
new
(
output
.
size
()).
fill_
(
-
1
)
else
:
output_index
=
Variable
(
index
.
data
.
new
(
output
.
size
()).
fill_
(
-
1
))
output_index
=
gen_filled_tensor
(
index
,
output
.
size
(),
fill_value
=-
1
)
return
scatter
(
'max'
,
dim
,
output
,
index
,
input
,
output_index
)
...
...
@@ -71,10 +62,7 @@ def scatter_max(index, input, dim=0, max_index=None, fill_value=0):
def
scatter_min_
(
output
,
index
,
input
,
dim
=
0
):
if
torch
.
is_tensor
(
input
):
output_index
=
index
.
new
(
output
.
size
()).
fill_
(
-
1
)
else
:
output_index
=
Variable
(
index
.
data
.
new
(
output
.
size
()).
fill_
(
-
1
))
output_index
=
gen_filled_tensor
(
index
,
output
.
size
(),
fill_value
=-
1
)
return
scatter
(
'min'
,
dim
,
output
,
index
,
input
,
output_index
)
...
...
torch_scatter/functions/utils.py
View file @
28f42bdc
...
...
@@ -2,13 +2,20 @@ import torch
from
torch.autograd
import
Variable
def
gen_filled_tensor
(
input
,
size
,
fill_value
):
if
torch
.
is_tensor
(
input
):
return
input
.
new
(
size
).
fill_
(
fill_value
)
else
:
return
Variable
(
input
.
data
.
new
(
size
).
fill_
(
fill_value
))
def
gen_output
(
index
,
input
,
dim
,
max_index
,
fill_value
):
max_index
=
index
.
max
()
+
1
if
max_index
is
None
else
max_index
size
=
list
(
index
.
size
())
if
torch
.
is_tensor
(
input
):
size
[
dim
]
=
max_index
return
input
.
new
(
torch
.
Size
(
size
)).
fill_
(
fill_value
)
else
:
size
[
dim
]
=
max_index
.
data
[
0
]
return
Variable
(
input
.
data
.
new
(
torch
.
Size
(
size
)).
fill_
(
fill_value
))
return
gen_filled_tensor
(
input
,
torch
.
Size
(
size
),
fill_value
)
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