You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/09/13 14:42:43 UTC

[GitHub] marcoabreu closed pull request #12391: [MXNET-851] Test coverage metrics for R-package

marcoabreu closed pull request #12391: [MXNET-851] Test coverage metrics for R-package
URL: https://github.com/apache/incubator-mxnet/pull/12391
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/Makefile b/Makefile
index 7aa7867f7c1..6c1d96ef9c4 100644
--- a/Makefile
+++ b/Makefile
@@ -565,7 +565,6 @@ rcpplint:
 	3rdparty/dmlc-core/scripts/lint.py mxnet-rcpp ${LINT_LANG} R-package/src
 
 rpkg:
-	mkdir -p R-package/inst
 	mkdir -p R-package/inst/libs
 	cp src/io/image_recordio.h R-package/src
 	cp -rf lib/libmxnet.so R-package/inst/libs
@@ -579,16 +578,15 @@ rpkg:
 	echo "import(methods)" >> R-package/NAMESPACE
 	R CMD INSTALL R-package
 	Rscript -e "require(mxnet); mxnet:::mxnet.export('R-package')"
-	rm -rf R-package/NAMESPACE
 	Rscript -e "if (!require('roxygen2')||packageVersion('roxygen2')!= '5.0.1'){\
 	devtools::install_version('roxygen2',version='5.0.1',\
 	repo='https://cloud.r-project.org/',quiet=TRUE)}"
 	Rscript -e "require(roxygen2); roxygen2::roxygenise('R-package')"
 	R CMD INSTALL R-package
-	rm -rf R-package/src/image_recordio.h
 
 rpkgtest:
-	Rscript -e "require(testthat);res<-test_dir('R-package/tests/testthat');if(!testthat:::all_passed(res)){stop('Test failures', call. = FALSE)}"
+	Rscript -e 'require(testthat);res<-test_dir("R-package/tests/testthat");if(!testthat:::all_passed(res)){stop("Test failures", call. = FALSE)}'
+	Rscript -e 'res<-covr:::package_coverage("R-package");fileConn<-file("r-package_coverage.json");writeLines(covr:::to_codecov(res), fileConn);close(fileConn)'
 
 scalaclean:
 	(cd $(ROOTDIR)/scala-package; \
diff --git a/R-package/DESCRIPTION b/R-package/DESCRIPTION
index ff70a97d017..bd6a84d55be 100644
--- a/R-package/DESCRIPTION
+++ b/R-package/DESCRIPTION
@@ -26,7 +26,8 @@ Suggests:
     mlbench,
     knitr,
     rmarkdown,
-    imager
+    imager,
+    covr
 Depends:
     R (>= 3.3.0)
 LinkingTo: Rcpp
diff --git a/R-package/tests/testthat/test_img_seg.R b/R-package/tests/testthat/test_img_seg.R
index 9b63f5078fa..c19e8dc727f 100644
--- a/R-package/tests/testthat/test_img_seg.R
+++ b/R-package/tests/testthat/test_img_seg.R
@@ -79,7 +79,7 @@ get_unet <- function() {
   net <- convolution_module(net, kernel_size, pad_size, filter_count = filter_count * 
     4, up_pool = TRUE)
   
-  net <- mx.symbol.Concat(c(pool2, net), num.args = 2)
+  net <- mx.symbol.concat(c(pool2, net), num.args = 2)
   net <- mx.symbol.Dropout(net)
   net <- convolution_module(net, kernel_size, pad_size, filter_count = filter_count * 
     4)
@@ -87,7 +87,7 @@ get_unet <- function() {
     4, up_pool = TRUE)
   convolution_module(net, kernel_size, pad_size, filter_count = filter_count * 
     4)
-  net <- mx.symbol.Concat(c(pool1, net), num.args = 2)
+  net <- mx.symbol.concat(c(pool1, net), num.args = 2)
   net <- mx.symbol.Dropout(net)
   net <- convolution_module(net, kernel_size, pad_size, filter_count = filter_count * 
     2)
diff --git a/R-package/tests/testthat/test_initializer.R b/R-package/tests/testthat/test_initializer.R
index c005244d02b..9ce41ab6a0b 100644
--- a/R-package/tests/testthat/test_initializer.R
+++ b/R-package/tests/testthat/test_initializer.R
@@ -2,35 +2,35 @@ require(mxnet)
 
 context("initializer")
 
-testthat("mx.init.uniform", {
+test_that("mx.init.uniform", {
   uniform_init <- mx.init.uniform(scale = 1)
   expect_equal(typeof(uniform_init), "closure")
   
-  X_bias <- uniform_init("X_bias", c(1, 10000), ctx = mx.ctx.default())
-  expect_equal(X_bias, mx.nd.zeros(c(1, 10000)))
+  X_bias <- uniform_init("X_bias", c(1, 100), ctx = mx.ctx.default())
+  expect_equal(X_bias, mx.nd.zeros(c(1, 100)))
   
-  X_weight <- uniform_init("X_weight", c(5, 10, 10000), ctx = mx.ctx.default())
-  expect_equal(X_weight >= -1, mx.nd.ones(c(5, 10, 10000)))
-  expect_equal(X_weight <= 1, mx.nd.ones(c(5, 10, 10000)))
+  X_weight <- uniform_init("X_weight", c(5, 10, 1000), ctx = mx.ctx.default())
+  expect_equal(X_weight >= -1, mx.nd.ones(c(5, 10, 1000)))
+  expect_equal(X_weight <= 1, mx.nd.ones(c(5, 10, 1000)))
   mean_weight <- mean(as.array(X_weight))
   expect_equal(mean_weight, 0, tolerance = 0.01)
 })
 
-testthat("mx.init.normal", {
+test_that("mx.init.normal", {
   normal_init <- mx.init.normal(sd = 0.1)
   expect_equal(typeof(normal_init), "closure")
   
-  X_bias <- normal_init("X_bias", c(1, 10000), ctx = mx.ctx.default())
-  expect_equal(X_bias, mx.nd.zeros(c(1, 10000)))
+  X_bias <- normal_init("X_bias", c(1, 100), ctx = mx.ctx.default())
+  expect_equal(X_bias, mx.nd.zeros(c(1, 100)))
   
-  X_weight <- normal_init("X_weight", c(5, 10, 10000), ctx = mx.ctx.default())
+  X_weight <- normal_init("X_weight", c(5, 10, 1000), ctx = mx.ctx.default())
   weight_mean <- mean(as.array(X_weight))
   weight_sd <- sd(as.array(X_weight))
   expect_equal(weight_mean, 0, tolerance = 0.01)
   expect_equal(weight_sd, 0.1, tolerance = 0.01)
 })
 
-testthat("mx.init.Xavier", {
+test_that("mx.init.Xavier", {
   xavier_init <- mx.init.Xavier()
   expect_equal(typeof(xavier_init), "closure")
   
@@ -75,7 +75,7 @@ testthat("mx.init.Xavier", {
   }
 })
 
-testthat("mx.init.internal.default", {
+test_that("mx.init.internal.default", {
   sample_bias <- mxnet:::mx.init.internal.default("X_bias", c(5, 10, 100), ctx = mx.ctx.default())
   expect_equal(sample_bias, mx.nd.zeros(c(5, 10, 100)))
   
@@ -97,7 +97,7 @@ testthat("mx.init.internal.default", {
     "Unkown initialization pattern for  X")
 })
 
-testthat("mx.init.create", {
+test_that("mx.init.create", {
   uniform_init <- mx.init.uniform(scale = 1)
   expect_equal(typeof(uniform_init), "closure")
   arrs <- setNames(as.list(c(50000, 100)), c("X_weight", "X_bias"))
diff --git a/R-package/tests/testthat/test_model.R b/R-package/tests/testthat/test_model.R
index f4be49d5fdd..916380bfc1b 100644
--- a/R-package/tests/testthat/test_model.R
+++ b/R-package/tests/testthat/test_model.R
@@ -50,7 +50,7 @@ test_that("MNIST", {
     return(sum((as.array(label) + 1) == ypred)/length(label))
   }
   
-  expect_equal(accuracy(label, pred), accuracy(label, pred2))
+  expect_equal(accuracy(label, pred), accuracy(label, pred2), tolerance = 0.1)
   
   file.remove("chkpt-0001.params")
   file.remove("chkpt-symbol.json")
@@ -235,7 +235,7 @@ test_that("Captcha", {
   fc22 <- mx.symbol.FullyConnected(data = fc1, num_hidden = 10)
   fc23 <- mx.symbol.FullyConnected(data = fc1, num_hidden = 10)
   fc24 <- mx.symbol.FullyConnected(data = fc1, num_hidden = 10)
-  fc2 <- mx.symbol.Concat(c(fc21, fc22, fc23, fc24), dim = 0, num.args = 4)
+  fc2 <- mx.symbol.concat(c(fc21, fc22, fc23, fc24), dim = 0, num.args = 4)
   label <- mx.symbol.transpose(data = label)
   label <- mx.symbol.Reshape(data = label, target_shape = c(0))
   captcha_net <- mx.symbol.SoftmaxOutput(data = fc2, label = label, name = "softmax")
diff --git a/R-package/tests/testthat/test_symbol.R b/R-package/tests/testthat/test_symbol.R
index 4a253fbd3e7..d7a97d9c8ad 100644
--- a/R-package/tests/testthat/test_symbol.R
+++ b/R-package/tests/testthat/test_symbol.R
@@ -106,7 +106,7 @@ test_that("symbol concat", {
   expect_equal(outputs(children(s3)), c("data1", "data2"))
   expect_equal(arguments(s3), c("data1", "data2"))
   
-  s4 <- mx.symbol.Concat(data = c(s1, s2), num.args = 2, name = "concat")
+  s4 <- mx.symbol.concat(data = c(s1, s2), num.args = 2, name = "concat")
   expect_equal(outputs(s3), outputs(s4))
   expect_equal(outputs(children(s3)), outputs(children(s4)))
   expect_equal(arguments(s3), arguments(s4))


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services