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/09/29 02:48:27 UTC

[incubator-mxnet] branch master updated: Update ndarray.py (#8083)

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 198df2f  Update ndarray.py (#8083)
198df2f is described below

commit 198df2fb83ba282999ba1253a986458217d0bef7
Author: Eric Junyuan Xie <pi...@users.noreply.github.com>
AuthorDate: Thu Sep 28 19:48:22 2017 -0700

    Update ndarray.py (#8083)
---
 python/mxnet/ndarray/ndarray.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py
index 6077d0e..e9c9752 100644
--- a/python/mxnet/ndarray/ndarray.py
+++ b/python/mxnet/ndarray/ndarray.py
@@ -511,14 +511,25 @@ fixed-size items.
             assert len(shape) >= len(key), \
                 "Slicing dimensions exceeds array dimensions, %d vs %d"%(
                     len(key), len(shape))
-            if isinstance(key[0], (NDArray, np.ndarray, list)):
+            if isinstance(key[0], (NDArray, np.ndarray, list, tuple)):
                 indices = []
                 dtype = 'int32'
+                shape = None
                 for idx_i in key:
                     if not isinstance(idx_i, NDArray):
+                        assert isinstance(idx_i, (NDArray, np.ndarray, list, tuple)), \
+                            "Combining basic and advanced indexing is not supported " \
+                            "yet. Indices must be all NDArray or all slice, not a " \
+                            "mix of both."
                         idx_i = array(idx_i, ctx=self.context, dtype=dtype)
                     else:
                         dtype = idx_i.dtype
+                    if shape is None:
+                        shape = idx_i.shape
+                    else:
+                        assert shape == idx_i.shape, \
+                            "All index arrays must have the same shape: %s vs %s. " \
+                            "Broadcasting is not supported yet."%(shape, idx_i.shape)
                     indices.append(idx_i)
                 indices = op.stack(*indices)
                 return op.gather_nd(self, indices)
@@ -537,6 +548,11 @@ fixed-size items.
                         begin.append(0 if slice_i.start is None else slice_i.start)
                         end.append(shape[i] if slice_i.stop is None else slice_i.stop)
                         oshape.append(end[i] - begin[i])
+                    elif isinstance(slice_i, (NDArray, np.ndarray, list, tuple)):
+                        raise ValueError(
+                            "Combining basic and advanced indexing is not supported " \
+                            "yet. Indices must be all NDArray or all slice, not a " \
+                            "mix of both.")
                     else:
                         raise ValueError(
                             "NDArray does not support slicing with key %s of type %s."%(

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