xidulu opened a new pull request #15858: [Numpy] Numpy behavior random.uniform() URL: https://github.com/apache/incubator-mxnet/pull/15858 ## Description ## Current `mx.np.random.uniform` does not support parameters (low and high) as `Ndarray`, as the current version is implemented by wrapping `mxnet.ndarray.random.uniform`, which behaves in a different way **when the output shape is given by the user** compared with native Numpy. For example: ``` low = np.zeros((1,4)) high = np.ones((1,4)) shape = (2,4,4) ``` `mxnet.ndarray.random.uniform(low, high, shape)` would have output tensor of shape 1x4x2x4x4, however, result from `numpy.random.uniform(low, high, shape)` would have shape 2x4x4. Another major difference is that, numpy allows parameters to have different shapes as long as they are broadcastable. For example: ``` low = np.zeros((1,4)) high = np.ones((4,4)) shape = (2,4,4) ``` This setting would cause `Operator _sample_uniform inferring shapes failed.` with `mxnet.ndarray.random.uniform`. This pull request implements a uniform distribution generator with numpy behavior and GPU support. ## 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] New backend for random.uniform (np_uniform_op.*) implemented. - [x] Current np.random.uniform() in python frontend is renamed to __deprecated_uniform(). ## Comments ## - When both low and high are python scalars and `size` is not defined, a scalar tensor would be returned. This is different from native Numpy, which would return python scalar if both parameters are python scalar. For example: ``` >>>numpy.random.uniform() 0.1234 >>>mxnet.np.random.uniform() array(0.1234) ```
---------------------------------------------------------------- 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