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
c3bacf3b
Commit
c3bacf3b
authored
Dec 17, 2017
by
rusty1s
Browse files
added assertions
parent
0466dd06
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
torch_scatter/functions/scatter.py
torch_scatter/functions/scatter.py
+21
-0
No files found.
torch_scatter/functions/scatter.py
View file @
c3bacf3b
from
itertools
import
chain
import
torch
import
torch
from
torch.autograd
import
Function
from
torch.autograd
import
Function
...
@@ -5,6 +7,25 @@ from .._ext import ffi
...
@@ -5,6 +7,25 @@ from .._ext import ffi
def
_scatter
(
name
,
dim
,
*
data
):
def
_scatter
(
name
,
dim
,
*
data
):
a
,
b
,
c
=
data
[:
3
]
# Assert same dimensionality across all inputs.
assert
dim
>=
0
and
dim
<
a
.
dim
(),
'Index dimension is out of bounds'
assert
b
.
dim
()
==
c
.
dim
(),
(
'Index tensor must have same dimensions as '
'input tensor'
)
assert
a
.
dim
()
==
c
.
dim
(),
(
'Input tensor must have same dimensions as '
'output tensor'
)
# Assert same tensor length across index and input.
assert
b
.
numel
()
==
c
.
numel
(),
(
'Index tensor must have same size as '
'input tensor'
)
# Assert same tensor sizes across input and output apart from `dim`.
for
d
in
chain
(
range
(
dim
),
range
(
dim
+
1
,
a
.
dim
())):
assert
a
.
size
(
d
)
==
c
.
size
(
d
),
(
'Input tensor must have same size as output tensor apart from the '
'specified dimension'
)
typename
=
type
(
data
[
0
]).
__name__
.
replace
(
'Tensor'
,
''
)
typename
=
type
(
data
[
0
]).
__name__
.
replace
(
'Tensor'
,
''
)
func
=
getattr
(
ffi
,
'scatter_{}_{}'
.
format
(
name
,
typename
))
func
=
getattr
(
ffi
,
'scatter_{}_{}'
.
format
(
name
,
typename
))
func
(
dim
,
*
data
)
func
(
dim
,
*
data
)
...
...
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