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
11974812
Unverified
Commit
11974812
authored
Jun 15, 2019
by
Da Zheng
Committed by
GitHub
Jun 15, 2019
Browse files
[Backend] use new split in MXNet (#660)
* use new split. * fix. * fix. * add zero copy from numpy.
parent
f3d3fdf8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
python/dgl/backend/mxnet/tensor.py
python/dgl/backend/mxnet/tensor.py
+11
-3
No files found.
python/dgl/backend/mxnet/tensor.py
View file @
11974812
...
@@ -125,8 +125,17 @@ def stack(seq, dim):
...
@@ -125,8 +125,17 @@ def stack(seq, dim):
return
nd
.
stack
(
*
seq
,
axis
=
dim
)
return
nd
.
stack
(
*
seq
,
axis
=
dim
)
def
split
(
x
,
sizes_or_sections
,
dim
):
def
split
(
x
,
sizes_or_sections
,
dim
):
if
isinstance
(
sizes_or_sections
,
list
)
and
len
(
sizes_or_sections
)
==
1
:
assert
len
(
x
)
==
sizes_or_sections
[
0
]
return
[
x
]
if
MX_VERSION
.
version
[
0
]
==
1
and
MX_VERSION
.
version
[
1
]
>=
5
:
if
isinstance
(
sizes_or_sections
,
(
np
.
ndarray
,
list
)):
sizes_or_sections1
=
tuple
(
np
.
cumsum
(
sizes_or_sections
)[:
-
1
])
return
nd
.
split_v2
(
x
,
sizes_or_sections1
,
axis
=
dim
)
if
isinstance
(
sizes_or_sections
,
list
)
or
isinstance
(
sizes_or_sections
,
np
.
ndarray
):
if
isinstance
(
sizes_or_sections
,
list
)
or
isinstance
(
sizes_or_sections
,
np
.
ndarray
):
#
TODO: fallback to numpy is unfortunate
#
Old MXNet doesn't support split with different section sizes.
np_arr
=
x
.
asnumpy
()
np_arr
=
x
.
asnumpy
()
indices
=
np
.
cumsum
(
sizes_or_sections
)[:
-
1
]
indices
=
np
.
cumsum
(
sizes_or_sections
)[:
-
1
]
res
=
np
.
split
(
np_arr
,
indices
,
axis
=
dim
)
res
=
np
.
split
(
np_arr
,
indices
,
axis
=
dim
)
...
@@ -249,8 +258,7 @@ def zerocopy_to_numpy(arr):
...
@@ -249,8 +258,7 @@ def zerocopy_to_numpy(arr):
return
arr
.
asnumpy
()
return
arr
.
asnumpy
()
def
zerocopy_from_numpy
(
np_data
):
def
zerocopy_from_numpy
(
np_data
):
# NOTE: not zerocopy
return
mx
.
nd
.
from_numpy
(
np_data
,
zero_copy
=
True
)
return
nd
.
array
(
np_data
,
dtype
=
np_data
.
dtype
)
def
zerocopy_to_dgl_ndarray
(
arr
):
def
zerocopy_to_dgl_ndarray
(
arr
):
return
dglnd
.
from_dlpack
(
arr
.
to_dlpack_for_read
())
return
dglnd
.
from_dlpack
(
arr
.
to_dlpack_for_read
())
...
...
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