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

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hetong007 committed Nov 2, 2015
2 parents dc775e0 + 98b68b3 commit 6b920f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
18 changes: 12 additions & 6 deletions R-package/R/ndarray.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
#'
#' @examples
#' mat = mx.nd.array(1:3)
#' mx.nd.save(list(mat), 'temp.mat')
#' mx.nd.save(mat, 'temp.mat')
#' mat2 = mx.nd.load('temp.mat')
#' as.array(mat)
#' as.array(mat2)
#'
#' @export
mx.nd.load <- function(filename) {
filename <- path.expand(filename)
mx.nd.internal.load(filename)
ndarray <- mx.nd.internal.load(filename)
if (length(ndarray) == 1) {
return(ndarray[[1]])
} else {
return(ndarray)
}
}

#' Save an mx.nd.array object
Expand All @@ -22,18 +27,19 @@ mx.nd.load <- function(filename) {
#'
#' @examples
#' mat = mx.nd.array(1:3)
#' mx.nd.save(list(mat), 'temp.mat')
#' mx.nd.save(mat, 'temp.mat')
#' mat2 = mx.nd.load('temp.mat')
#' as.array(mat)
#' as.array(mat2)
#'
#' @export
mx.nd.save <- function(ndarray, filename) {
filename <- path.expand(filename)
if (!is.list(ndarray)) {
stop("Only list of ndarrays support")
mx.nd.internal.save(list(ndarray), filename)
} else {
mx.nd.internal.save(ndarray, filename)
}
filename <- path.expand(filename)
mx.nd.internal.save(ndarray, filename)
}

mx.nd.internal.empty <- function(shape, ctx=NULL) {
Expand Down
6 changes: 3 additions & 3 deletions R-package/tests/testthat/test_ndarray.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test_that("ndarray ones, zeros, save and load", {
expect_equal(rep(1, 10), as.array(mx.nd.ones(10)))
expect_equal(matrix(1, 10, 5), as.array(mx.nd.ones(c(10, 5))))
mat = mx.nd.array(1:20)
mx.nd.save(list(mat), 'temp.mat')
mx.nd.save(mat, 'temp.mat')
mat2 = mx.nd.load('temp.mat')
expect_true(is.mx.ndarray(mat2[[1]]))
expect_equal(as.array(mat), as.array(mat2[[1]]))
expect_true(is.mx.ndarray(mat2))
expect_equal(as.array(mat), as.array(mat2))
})
5 changes: 4 additions & 1 deletion tests/travis/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ if [ ${TASK} == "r_test" ]; then

wget https://cran.rstudio.com/bin/macosx/R-latest.pkg -O /tmp/R-latest.pkg
sudo installer -pkg "/tmp/R-latest.pkg" -target /
Rscript -e "install.packages(c('Rcpp', 'testthat', 'DiagrammeR', 'data.table', 'jsonlite', 'magrittr', 'stringr'), repo = 'https://cran.rstudio.com')"
Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
cd R-package
Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
cd ..
R CMD check --no-examples --no-vignettes --no-manual R-package
exit 0
fi
Expand Down

0 comments on commit 6b920f7

Please sign in to comment.