haojin2 opened a new pull request #14966: add ctx argument for rand_ndarray and 
rand_sparse_ndarray test util funcs
URL: https://github.com/apache/incubator-mxnet/pull/14966
 
 
   ## Description ##
   As title. Improve usability of those 2 test utilities functions. Previously 
one has to do something like:
   ```Python
   a = rand_ndarray(shape, stype, density).as_in_context(ctx)
   ```
   With this change one only need to:
   ```Python
   a = rand_ndarray(shape, stype, density, ctx)
   ```
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [x] 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 ###
   - [x] Add ctx argument for `rand_ndarray` and `rand_sparse_ndarray` functions
   
   ## Comments ##
   Don't think this needs a dedicated unit test, but still got one small script 
in place to verify correctness of the change:
   ```Python
   import mxnet as mx
   from mxnet.test_utils import rand_ndarray
   
   shape = (1000, 1000)
   a = rand_ndarray(shape, stype='default')
   print(a.context)
   b = rand_ndarray(shape, stype='csr', density=0.01)
   print(b.context)
   c = rand_ndarray(shape, stype='row_sparse', density=0.01)
   print(c.context)
   ctx = mx.gpu(1)
   a = rand_ndarray(shape, stype='default', ctx=ctx)
   print(a.context)
   b = rand_ndarray(shape, stype='csr', density=0.01, ctx=ctx)
   print(b.context)
   c = rand_ndarray(shape, stype='row_sparse', density=0.01, ctx=ctx)
   print(c.context)
   ```
   Result of running this script:
   ```
   cpu(0)
   cpu(0)
   cpu(0)
   gpu(1)
   gpu(1)
   gpu(1)
   ```

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


With regards,
Apache Git Services

Reply via email to