hetong007 commented on a change in pull request #10450: [MXNET-212] [R] Fix Random Samplers from Uniform and Gaussian distribution in R bindings URL: https://github.com/apache/incubator-mxnet/pull/10450#discussion_r179979144
########## File path: 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=4, ctx=mx.ctx.default()) + expect_equal(X>=0, mx.nd.ones(50000)) + expect_equal(X<=4, mx.nd.ones(50000)) + sample_mean = mean(as.array(X)) + expect_equal(sample_mean, 2, tolerance=1e-2) +}) + +test_that("mx.rnorm", { + X <- mx.rnorm(shape=50000, mean=5, sd=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) Review comment: From 50k samples, the variance of the mean is `1/sqrt(50000)`, roughly 0.0044, this means that the probability of failing the `1e-2` tolerance from a correct implementation is around 2.5%. Considering the number of test being run, this probability is too high and may annoy the others. A simple fix will be setting `sd=0.1`. The `runif` case has the same issue. The fix can be `max=1`, and expect equal to `0.5`. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services