This is an automated email from the ASF dual-hosted git repository.

the 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 43f0e4d  [MXNET-212] [R] Fix Random Samplers from Uniform and Gaussian 
distribution in R bindings (#10450)
43f0e4d is described below

commit 43f0e4d9a1f7fad9826a47b664ad70f7d7b1a11e
Author: Anirudh <2778341+anirudhacha...@users.noreply.github.com>
AuthorDate: Mon Apr 9 10:34:03 2018 -0700

    [MXNET-212] [R] Fix Random Samplers from Uniform and Gaussian distribution 
in R bindings (#10450)
    
    * fix random samplers-uniform and gaussian
    
    * add tests for gaussian and uniform distributions
    
    * fix precision issues that may cause flakiness.
---
 R-package/R/random.R                   |  4 ++--
 R-package/tests/testthat/test_random.R | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/R-package/R/random.R b/R-package/R/random.R
index 1badce8..6d01592 100644
--- a/R-package/R/random.R
+++ b/R-package/R/random.R
@@ -49,7 +49,7 @@ mx.runif <- function(shape, min=0, max=1, ctx=NULL) {
   if (!is.numeric(min)) stop("mx.rnorm only accept numeric min")
   if (!is.numeric(max)) stop("mx.rnorm only accept numeric max")
   ret <- mx.nd.internal.empty(shape, ctx)
-  return (mx.nd.internal.sample.uniform(min, max, shape=shape, out=ret))
+  return (mx.nd.internal.random.uniform(min, max, shape=shape, out=ret))
 }
 
 #' Generate nomal distribution with mean and sd.
@@ -73,5 +73,5 @@ mx.rnorm <- function(shape, mean=0, sd=1, ctx=NULL) {
   if (!is.numeric(mean)) stop("mx.rnorm only accept numeric mean")
   if (!is.numeric(sd)) stop("mx.rnorm only accept numeric sd")
   ret <- mx.nd.internal.empty(shape, ctx)
-  return (mx.nd.internal.sample.normal(mean, sd, shape=shape, out=ret))
+  return (mx.nd.internal.random.normal(mean, sd, shape=shape, out=ret))
 }
diff --git a/R-package/tests/testthat/test_random.R 
b/R-package/tests/testthat/test_random.R
new file mode 100644
index 0000000..411d0c7
--- /dev/null
+++ b/R-package/tests/testthat/test_random.R
@@ -0,0 +1,19 @@
+require(mxnet)
+
+context("random")
+
+test_that("mx.runif", {
+  X <- mx.runif(shape=50000, min=0, max=1, ctx=mx.ctx.default())
+  expect_equal(X>=0, mx.nd.ones(50000))
+  expect_equal(X<=1, mx.nd.ones(50000))
+  sample_mean = mean(as.array(X))
+  expect_equal(sample_mean, 0.5, tolerance=1e-2)
+})
+
+test_that("mx.rnorm", {
+  X <- mx.rnorm(shape=50000, mean=5, sd=0.1, ctx=mx.ctx.default())
+  sample_mean = mean(as.array(X))
+  sample_sd = sd(as.array(X))
+  expect_equal(sample_mean, 5, tolerance=1e-2)
+  expect_equal(sample_sd, 0.1, tolerance=1e-2)
+})

-- 
To stop receiving notification emails like this one, please contact
t...@apache.org.

Reply via email to