Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion R-package/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Description: MXNet is a deep learning framework designed for both efficiency and
License: Apache-2.0
URL: https://github.com/dmlc/mxnet
BugReports: https://github.com/dmlc/mxnet/issues
Imports: Rcpp (>= 0.11.1)
Imports: methods, Rcpp (>= 0.11.1)
LinkingTo: Rcpp
1 change: 1 addition & 0 deletions R-package/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
exportPattern("^[[:alpha:]]+")
import(Rcpp)
import(methods)
16 changes: 14 additions & 2 deletions R-package/R/ndarray.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
mx.nd.load <- function(filename) {
filename <- path.expand(filename)
mx.nd.internal.load(filename)
}

mx.nd.save <- function(ndarray, filename) {
filename <- path.expand(filename)
mx.nd.internal.save(ndarray, filename)
}

is.MXNDArray <- function(x)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe is.mx.nd.array?

inherits(x, "Rcpp_MXNDArray")


#' NDArray
#'
#' Additional NDArray related operations
init.ndarray.methods <- function() {
require(methods)
setMethod("+", signature(e1 = "Rcpp_MXNDArray", e2 = "numeric"), function(e1, e2) {
mx.nd.internal.plus.scalar(e1, e2)
})
Expand Down Expand Up @@ -43,4 +56,3 @@ init.ndarray.methods <- function() {
x$as.array()
})
}

1 change: 0 additions & 1 deletion R-package/R/base.R → R-package/R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require(methods)

.onLoad <- function(libname, pkgname) {
library.dynam("libmxnet", pkgname, libname, local=FALSE)
Expand Down
4 changes: 1 addition & 3 deletions R-package/demo/basic_ndarray.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
require(mxnet)
require(methods)


x = as.array(c(1,2,3))
mat = mx.nd.array(x, mx.cpu(0))
mat = mat + 1.0
mat = mat + mat
mat = mat - 5
mat = 10 / mat
mat = 7*mat
mat = 7 * mat
mat = 1 - mat + (2 * mat)/(mat + 0.5)
as.array(mat)

Expand Down
7 changes: 4 additions & 3 deletions R-package/src/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void NDArray::Save(const Rcpp::RObject &sxptr,
MX_CALL(MXNDArraySave(filename.c_str(), num_args,
dmlc::BeginPtr(handles),
dmlc::BeginPtr(keys)));
} else if (TYPEOF(sxptr) == EXTPTRSXP) {
} else if (TYPEOF(sxptr) == EXTPTRSXP) { // TODO this line is wrong??
MX_CALL(MXNDArraySave(filename.c_str(), 1,
&(NDArray::XPtr(sxptr)->handle_), nullptr));
} else {
Expand Down Expand Up @@ -220,8 +220,9 @@ void NDArray::InitRcppModule() {
using namespace Rcpp; // NOLINT(*)
class_<NDArray>("MXNDArray")
.method("as.array", &NDArray::AsNumericVector);
function("mx.nd.load", &NDArray::Load);
function("mx.nd.save", &NDArray::Save);
// don't call load/save directly, let R provides the completed file path first
function("mx.nd.internal.load", &NDArray::Load);
function("mx.nd.internal.save", &NDArray::Save);
function("mx.nd.array", &NDArray::Array);
}

Expand Down
2 changes: 1 addition & 1 deletion R-package/src/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class NDArrayFunction : public ::Rcpp::CppFunction {
} // namespace mxnet


RCPP_EXPOSED_CLASS_NODECL(::mxnet::R::NDArray);
RCPP_EXPOSED_CLASS_NODECL(::mxnet::R::NDArray)

namespace mxnet {
namespace R {
Expand Down