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
1f019c20
Commit
1f019c20
authored
Dec 28, 2017
by
rusty1s
Browse files
fill value added
parent
10542ab2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
14 deletions
+34
-14
test/backward.json
test/backward.json
+2
-2
test/forward.json
test/forward.json
+19
-3
test/test_backward.py
test/test_backward.py
+5
-3
test/test_forward.py
test/test_forward.py
+8
-6
No files found.
test/backward.json
View file @
1f019c20
[
{
"name"
:
"add"
,
"output"
:
[[
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
]],
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
0
,
"grad"
:
[[
10
,
20
,
30
,
40
,
50
,
60
],
[
15
,
25
,
35
,
45
,
55
,
65
]],
"expected"
:
[[
50
,
60
,
50
,
30
,
40
],
[
15
,
15
,
35
,
35
,
25
]]
},
{
"name"
:
"max"
,
"output"
:
[[
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
]],
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
0
,
"grad"
:
[[
10
,
20
,
30
,
40
,
50
,
60
],
[
15
,
25
,
35
,
45
,
55
,
65
]],
"expected"
:
[[
50
,
60
,
0
,
30
,
40
],
[
0
,
15
,
0
,
35
,
25
]]
}
...
...
test/forward.json
View file @
1f019c20
[
{
"name"
:
"add"
,
"output"
:
[[
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
]],
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
0
,
"expected"
:
[[
0
,
0
,
4
,
3
,
3
,
0
],
[
2
,
4
,
4
,
0
,
0
,
0
]]
},
{
"name"
:
"sub"
,
"output"
:
[[
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
]],
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
0
,
"expected"
:
[[
0
,
0
,
-4
,
-3
,
-3
,
0
],
[
-2
,
-4
,
-4
,
0
,
0
,
0
]]
},
{
"name"
:
"mul"
,
"output"
:
[[
1
,
1
,
1
,
1
,
1
,
1
],
[
1
,
1
,
1
,
1
,
1
,
1
]],
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
1
,
"expected"
:
[[
1
,
1
,
4
,
3
,
2
,
0
],
[
0
,
4
,
3
,
1
,
1
,
1
]]
},
{
"name"
:
"div"
,
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
1
,
1
,
4
,
2
],
[
1
,
2
,
1
,
2
,
4
]],
"dim"
:
1
,
"fill_value"
:
1
,
"expected"
:
[[
1
,
1
,
0.25
,
0.5
,
0.5
,
1
],
[
0.5
,
0.25
,
0.5
,
1
,
1
,
1
]]
},
{
"name"
:
"mean"
,
"index"
:
[[
4
,
5
,
4
,
2
,
3
],
[
0
,
0
,
2
,
2
,
1
]],
"input"
:
[[
2
,
0
,
1
,
4
,
3
],
[
0
,
2
,
1
,
3
,
4
]],
"dim"
:
1
,
"fill_value"
:
0
,
"expected"
:
[[
0
,
0
,
4
,
3
,
1.5
,
0
],
[
1
,
4
,
2
,
0
,
0
,
0
]]
}
]
test/test_backward.py
View file @
1f019c20
...
...
@@ -17,11 +17,12 @@ f.close()
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
data
))))
def
test_backward_cpu
(
tensor
,
i
):
name
=
data
[
i
][
'name'
]
output
=
V
(
Tensor
(
tensor
,
data
[
i
][
'output'
]))
index
=
V
(
torch
.
LongTensor
(
data
[
i
][
'index'
]))
input
=
V
(
Tensor
(
tensor
,
data
[
i
][
'input'
]),
requires_grad
=
True
)
dim
=
data
[
i
][
'dim'
]
fill_value
=
data
[
i
][
'fill_value'
]
grad
=
Tensor
(
tensor
,
data
[
i
][
'grad'
])
output
=
V
(
grad
.
new
(
grad
.
size
()).
fill_
(
fill_value
))
expected
=
Tensor
(
tensor
,
data
[
i
][
'expected'
])
func
=
getattr
(
torch_scatter
,
'scatter_{}_'
.
format
(
name
))
...
...
@@ -34,11 +35,12 @@ def test_backward_cpu(tensor, i):
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
data
))))
def
test_backward_gpu
(
tensor
,
i
):
name
=
data
[
i
][
'name'
]
output
=
V
(
Tensor
(
tensor
,
data
[
i
][
'output'
])).
cuda
()
index
=
V
(
torch
.
LongTensor
(
data
[
i
][
'index'
])).
cuda
()
input
=
V
(
Tensor
(
tensor
,
data
[
i
][
'input'
]),
requires_grad
=
True
).
cu
a
d
()
input
=
V
(
Tensor
(
tensor
,
data
[
i
][
'input'
]),
requires_grad
=
True
).
cud
a
()
dim
=
data
[
i
][
'dim'
]
fill_value
=
data
[
i
][
'fill_value'
]
grad
=
Tensor
(
tensor
,
data
[
i
][
'grad'
]).
cuda
()
output
=
V
(
grad
.
new
(
grad
.
size
()).
fill_
(
fill_value
)).
cuda
()
expected
=
Tensor
(
tensor
,
data
[
i
][
'expected'
])
func
=
getattr
(
torch_scatter
,
'scatter_{}_'
.
format
(
name
))
...
...
test/test_forward.py
View file @
1f019c20
...
...
@@ -16,18 +16,19 @@ f.close()
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
data
))))
def
test_forward_cpu
(
tensor
,
i
):
name
=
data
[
i
][
'name'
]
output
=
Tensor
(
tensor
,
data
[
i
][
'output'
])
index
=
torch
.
LongTensor
(
data
[
i
][
'index'
])
input
=
Tensor
(
tensor
,
data
[
i
][
'input'
])
dim
=
data
[
i
][
'dim'
]
expected
=
Tensor
(
tensor
,
data
[
i
][
'expected'
])
fill_value
=
data
[
i
][
'fill_value'
]
expected
=
torch
.
FloatTensor
(
data
[
i
][
'expected'
]).
type_as
(
input
)
output
=
expected
.
new
(
expected
.
size
()).
fill_
(
fill_value
)
func
=
getattr
(
torch_scatter
,
'scatter_{}_'
.
format
(
name
))
func
(
output
,
index
,
input
,
dim
)
assert
output
.
tolist
()
==
expected
.
tolist
()
func
=
getattr
(
torch_scatter
,
'scatter_{}'
.
format
(
name
))
output
=
func
(
index
,
input
,
dim
)
output
=
func
(
index
,
input
,
dim
,
fill_value
=
fill_value
)
assert
output
.
tolist
()
==
expected
.
tolist
()
...
...
@@ -35,16 +36,17 @@ def test_forward_cpu(tensor, i):
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
data
))))
def
test_forward_gpu
(
tensor
,
i
):
name
=
data
[
i
][
'name'
]
output
=
Tensor
(
tensor
,
data
[
i
][
'output'
]).
cuda
()
index
=
torch
.
LongTensor
(
data
[
i
][
'index'
]).
cuda
()
input
=
Tensor
(
tensor
,
data
[
i
][
'input'
]).
cuda
()
dim
=
data
[
i
][
'dim'
]
expected
=
Tensor
(
tensor
,
data
[
i
][
'expected'
])
fill_value
=
data
[
i
][
'fill_value'
]
expected
=
torch
.
FloatTensor
(
data
[
i
][
'expected'
]).
type_as
(
input
)
output
=
expected
.
new
(
expected
.
size
()).
fill_
(
fill_value
).
cuda
()
func
=
getattr
(
torch_scatter
,
'scatter_{}_'
.
format
(
name
))
func
(
output
,
index
,
input
,
dim
)
assert
output
.
cpu
().
tolist
()
==
expected
.
tolist
()
func
=
getattr
(
torch_scatter
,
'scatter_{}'
.
format
(
name
))
output
=
func
(
index
,
input
,
dim
)
output
=
func
(
index
,
input
,
dim
,
fill_value
=
fill_value
)
assert
output
.
cpu
().
tolist
()
==
expected
.
tolist
()
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