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
b9a7f326
Commit
b9a7f326
authored
Mar 28, 2018
by
rusty1s
Browse files
cuda tests
parent
b8ece051
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
6 deletions
+36
-6
test/utils/test_consecutive.py
test/utils/test_consecutive.py
+16
-2
test/utils/test_degree.py
test/utils/test_degree.py
+19
-4
torch_cluster/functions/utils/degree.py
torch_cluster/functions/utils/degree.py
+1
-0
No files found.
test/utils/test_consecutive.py
View file @
b9a7f326
import
pytest
import
torch
import
torch
from
torch_cluster.functions.utils.consecutive
import
consecutive
from
torch_cluster.functions.utils.consecutive
import
consecutive
...
@@ -10,5 +11,18 @@ def test_consecutive():
...
@@ -10,5 +11,18 @@ def test_consecutive():
assert
consecutive
(
vec
).
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
assert
consecutive
(
vec
).
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
vec
=
torch
.
LongTensor
([
0
,
3
,
2
,
2
,
3
])
vec
=
torch
.
LongTensor
([
0
,
3
,
2
,
2
,
3
])
assert
consecutive
(
vec
,
return_unique
=
True
)[
0
].
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
assert
consecutive
(
vec
,
True
)[
0
].
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
assert
consecutive
(
vec
,
return_unique
=
True
)[
1
].
tolist
()
==
[
0
,
2
,
3
]
assert
consecutive
(
vec
,
True
)[
1
].
tolist
()
==
[
0
,
2
,
3
]
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
def
test_consecutive_gpu
():
# pragma: no cover
vec
=
torch
.
cuda
.
LongTensor
([
0
,
2
,
3
])
assert
consecutive
(
vec
).
cpu
().
tolist
()
==
[
0
,
1
,
2
]
vec
=
torch
.
cuda
.
LongTensor
([
0
,
3
,
2
,
2
,
3
])
assert
consecutive
(
vec
).
cpu
().
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
vec
=
torch
.
cuda
.
LongTensor
([
0
,
3
,
2
,
2
,
3
])
assert
consecutive
(
vec
,
True
)[
0
].
cpu
().
tolist
()
==
[
0
,
2
,
1
,
1
,
2
]
assert
consecutive
(
vec
,
True
)[
1
].
cpu
().
tolist
()
==
[
0
,
2
,
3
]
test/utils/test_degree.py
View file @
b9a7f326
import
pytest
import
torch
import
torch
from
torch_cluster.functions.utils.degree
import
node_degree
from
torch_cluster.functions.utils.degree
import
node_degree
def
test_node_degree
():
def
test_node_degree
_cpu
():
row
=
torch
.
LongTensor
([
0
,
1
,
1
,
0
,
0
,
3
,
0
])
row
=
torch
.
LongTensor
([
0
,
1
,
1
,
0
,
0
,
3
,
0
])
expected_degree
=
[
4
,
2
,
0
,
1
]
expected_degree
=
[
4
,
2
,
0
,
1
]
degree
=
node_degree
(
row
,
4
)
degree
=
node_degree
(
row
,
4
)
assert
degree
.
type
()
==
torch
.
Float
Tensor
().
type
()
assert
degree
.
type
()
==
torch
.
Long
Tensor
().
type
()
assert
degree
.
tolist
()
==
expected_degree
assert
degree
.
tolist
()
==
expected_degree
degree
=
node_degree
(
row
,
4
,
out
=
torch
.
Long
Tensor
())
degree
=
node_degree
(
row
,
4
,
out
=
torch
.
Float
Tensor
())
assert
degree
.
type
()
==
torch
.
Long
Tensor
().
type
()
assert
degree
.
type
()
==
torch
.
Float
Tensor
().
type
()
assert
degree
.
tolist
()
==
expected_degree
assert
degree
.
tolist
()
==
expected_degree
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
def
test_node_degree_gpu
():
# pragma: no cover
row
=
torch
.
cuda
.
LongTensor
([
0
,
1
,
1
,
0
,
0
,
3
,
0
])
expected_degree
=
[
4
,
2
,
0
,
1
]
degree
=
node_degree
(
row
,
4
)
assert
degree
.
type
()
==
torch
.
cuda
.
LongTensor
().
type
()
assert
degree
.
cpu
().
tolist
()
==
expected_degree
degree
=
node_degree
(
row
,
4
,
out
=
torch
.
cuda
.
FloatTensor
())
assert
degree
.
type
()
==
torch
.
cuda
.
FloatTensor
().
type
()
assert
degree
.
cpu
().
tolist
()
==
expected_degree
torch_cluster/functions/utils/degree.py
View file @
b9a7f326
...
@@ -2,6 +2,7 @@ import torch
...
@@ -2,6 +2,7 @@ import torch
def
node_degree
(
row
,
num_nodes
,
out
=
None
):
def
node_degree
(
row
,
num_nodes
,
out
=
None
):
out
=
row
.
new
()
if
out
is
None
else
out
zero
=
torch
.
zeros
(
num_nodes
,
out
=
out
)
zero
=
torch
.
zeros
(
num_nodes
,
out
=
out
)
one
=
torch
.
ones
(
row
.
size
(
0
),
out
=
zero
.
new
())
one
=
torch
.
ones
(
row
.
size
(
0
),
out
=
zero
.
new
())
return
zero
.
scatter_add_
(
0
,
row
,
one
)
return
zero
.
scatter_add_
(
0
,
row
,
one
)
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