aksnzhy opened a new pull request #12810: Add index_copy() operator
URL: https://github.com/apache/incubator-mxnet/pull/12810
 
 
   ## Description ##
   This is a PR to add a index_copy() tensor operator, which will be used in 
the DGL project.
   
   `output = mx.nd.contrib.index_copy(old_tensor, index, new_tensor)`
   
   This op copies the elements of a `new_tensor` into the `old_tensor` by 
   selecting the indices in the order given in `index`. The output will be a 
new tensor 
   contains the rest elements of old tensor and the copied elements of new 
tensor. 
   For example, if `index[i] == j`, then the `i`th row of `new_tensor` is 
copied to the 
   `j`th row of output.
   
   The `index` must be a vector and it must have the same size with the `0`th 
dimimention of 
   `new_tensor`. Also, the `0`th dimimention of old_tensor must `>=` the `0`th 
dimimention of 
   `new_tensor`, or an error will be raised.
   
   Examples:
   
   ```
   x = mx.nd.zeros((5,3))
   t = mx.nd.array([[1,2,3],[4,5,6],[7,8,9]])
   index = mx.nd.array([0,4,2])
   
   mx.nd.contrib.index_copy(x, index, t)
   
   [[1. 2. 3.]
    [0. 0. 0.]
    [7. 8. 9.]
    [0. 0. 0.]
    [4. 5. 6.]]
   <NDArray 5x3 @cpu(0)>
   ```
   
   Note that, so far we don't need the backward function for this operator.
   
   ## 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)
   - [x] 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)
   - [x] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments 
are documented. 
   - For new examples, README.md is added to explain the what the example does, 
the source of the dataset, expected performance on test set and reference to 
the original paper if applicable
   - 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 ###
   - Add index_copy-inl.h, index_copy.cc, and index_copy.cu for index_copy 
operator.
   - Add test_index_copy() in Python unitest.
   
   

----------------------------------------------------------------
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