kohr-h opened a new pull request #13143: [Python] Support NDArray indexing with 
None and Ellipsis
URL: https://github.com/apache/incubator-mxnet/pull/13143
 
 
   ## Description ##
   
   This PR adds the capability of indexing `NDArray` with `None` to create new 
axes, and with `...` (`Ellipsis`) as a shorthand for an adequate number of `:` 
(`slice(None)`).
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to 
the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) 
created (except PRs with tiny changes)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding 
a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing 
distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a 
new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - Check the API doc at 
http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [x] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - `NDArray.__getitem__` and `NDArray.__setitem__` now first expand `None` 
and `Ellipsis` entries in indices.
   - `__setitem__` ignores `None` entries, which corresponds to the behavior of 
NumPy.
   
   ## Comments ##
   - I've noted that indexing is not as copy-free as it could be. For instance:
     ```py
     >>> x = nd.ones(3)
     >>> y = x[:2]  # same as y = x[slice(2)]
     >>> y[:] = 0
     >>> x  # as expected
     [0. 0. 1.]
     <NDArray 3 @cpu(0)>
     >>> y = x[(slice(2),)]  # Should be equivalent
     >>> y[:] = -17
     >>> x  # unchanged!
     [0. 0. 1.]
     <NDArray 3 @cpu(0)>
     ```
   - Another nifty case is this one:
     ```py
     >>> x = nd.ones((2, 3))
     >>> y = x[:2]
     >>> y[:] = 0
     >>> x  # as expected
     [[0. 0. 0.]
      [1. 1. 1.]]
     <NDArray 2x3 @cpu(0)>
     >>> y = x[:2, :]
     >>> y[:] = -17
     >>> x  # unchanged!
     [[0. 0. 0.]
      [1. 1. 1.]]
     <NDArray 2x3 @cpu(0)>
     ```
   I think that the implementation does not live up to the promise of the 
documentation:
   ```
   Returns a sliced view of this array if the elements fetched are contiguous 
in memory;
   otherwise, returns a newly created NDArray.
   ```
   In particular, the "detection" of contiguousness is not good.
   
   I'll make that an extra issue, but it's related to this PR, so I mention it 
here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to