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
dgl
Commits
05f464f8
Commit
05f464f8
authored
Nov 15, 2018
by
Gan Quan
Committed by
Minjie Wang
Nov 15, 2018
Browse files
[Bugfix] fix args with incontiguous node and edge tensor (#153)
parent
ed1854e8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletion
+14
-1
python/dgl/backend/pytorch/tensor.py
python/dgl/backend/pytorch/tensor.py
+1
-1
tests/pytorch/test_index.py
tests/pytorch/test_index.py
+13
-0
No files found.
python/dgl/backend/pytorch/tensor.py
View file @
05f464f8
...
...
@@ -137,7 +137,7 @@ def arange(start, stop):
return
th
.
arange
(
start
,
stop
,
dtype
=
th
.
int64
)
def
zerocopy_to_dlpack
(
input
):
return
dlpack
.
to_dlpack
(
input
)
return
dlpack
.
to_dlpack
(
input
.
contiguous
()
)
def
zerocopy_from_dlpack
(
dlpack_tensor
):
return
dlpack
.
from_dlpack
(
dlpack_tensor
)
...
...
tests/pytorch/test_index.py
View file @
05f464f8
...
...
@@ -28,8 +28,21 @@ def test_dlpack():
x
[
0
]
=
1
assert
np
.
allclose
(
y
.
asnumpy
(),
ans
)
def
th2nd_incontiguous
():
import
dgl.backend
as
F
x
=
th
.
LongTensor
([[
0
,
1
],
[
2
,
3
]])
ans
=
np
.
array
([
0
,
2
])
y
=
x
[:
2
,
0
]
# Uncomment this line and comment the one below to observe error
#dl = dlpack.to_dlpack(y)
dl
=
F
.
zerocopy_to_dlpack
(
y
)
z
=
nd
.
from_dlpack
(
dl
)
assert
np
.
allclose
(
z
.
asnumpy
(),
ans
)
nd2th
()
th2nd
()
th2nd_incontiguous
()
def
test_index
():
ans
=
np
.
ones
((
10
,),
dtype
=
np
.
int64
)
*
10
...
...
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