Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-212] [R] Fix Random Samplers from Uniform and Gaussian distribution in R bindings #10450

Merged
merged 3 commits into from
Apr 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix precision issues that may cause flakiness.
  • Loading branch information
Anirudh Acharya committed Apr 9, 2018
commit 8cfad21e9ce15c5b2b09089236031e945d1f82f8
10 changes: 5 additions & 5 deletions R-package/tests/testthat/test_random.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ require(mxnet)
context("random")

test_that("mx.runif", {
X <- mx.runif(shape=50000, min=0, max=4, ctx=mx.ctx.default())
X <- mx.runif(shape=50000, min=0, max=1, ctx=mx.ctx.default())
expect_equal(X>=0, mx.nd.ones(50000))
expect_equal(X<=4, mx.nd.ones(50000))
expect_equal(X<=1, mx.nd.ones(50000))
sample_mean = mean(as.array(X))
expect_equal(sample_mean, 2, tolerance=1e-2)
expect_equal(sample_mean, 0.5, tolerance=1e-2)
})

test_that("mx.rnorm", {
X <- mx.rnorm(shape=50000, mean=5, sd=1, ctx=mx.ctx.default())
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)
anirudhacharya marked this conversation as resolved.
Show resolved Hide resolved
expect_equal(sample_sd, 1, tolerance=1e-2)
expect_equal(sample_sd, 0.1, tolerance=1e-2)
})