You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/08/30 22:43:03 UTC

[incubator-mxnet] branch master updated: add -1 indexing to ndarray (#7668)

This is an automated email from the ASF dual-hosted git repository.

jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new de4c6e4  add -1 indexing to ndarray (#7668)
de4c6e4 is described below

commit de4c6e401379a49bab46c68dbbf275991e682560
Author: Eric Junyuan Xie <pi...@users.noreply.github.com>
AuthorDate: Wed Aug 30 15:43:00 2017 -0700

    add -1 indexing to ndarray (#7668)
---
 python/mxnet/ndarray/ndarray.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py
index e497ea6..d5d4bb2 100644
--- a/python/mxnet/ndarray/ndarray.py
+++ b/python/mxnet/ndarray/ndarray.py
@@ -599,8 +599,25 @@ fixed-size items.
         array([], shape=(0, 2), dtype=float32)
         """
         handle = NDArrayHandle()
-        start = mx_uint(start) if start else mx_uint(0)
-        stop = mx_uint(stop) if stop else mx_uint(self.shape[0])
+        if start is None:
+            start = mx_uint(0)
+        elif start < 0:
+            length = self.shape[0]
+            start += length
+            assert start >= 0, "Slicing start %d exceeds limit of %d"%(start-length, length)
+            start = mx_uint(start)
+        else:
+            start = mx_uint(start)
+        if stop is None:
+            stop = mx_uint(self.shape[0])
+        elif stop < 0:
+            length = self.shape[0]
+            stop += length
+            assert stop >= 0, "Slicing end %d exceeds limit of %d"%(stop-length, length)
+            stop = mx_uint(stop)
+        else:
+            stop = mx_uint(stop)
+
         check_call(_LIB.MXNDArraySlice(
             self.handle, start, stop, ctypes.byref(handle)))
         return NDArray(handle=handle, writable=self.writable)

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].