[Rcpp-devel] Problem passing Armadillo objects back to R

"Günter J. Hitsch" guenter.hitsch at mac.com
Mon Mar 7 23:03:38 CET 2011


I'm new to Rcpp and RcppArmadillo---so far I like it a lot!  Thanks to the developers for their good work.

I run into a peculiar kind of problem when I try to pass a "large" Armadillo object back to R.  Here's some code to replicate the problem in stylized form:


extern "C" SEXP testFun(SEXP L_)
{
	const long L  = Rcpp::as<long>(L_);
	
	arma::mat X(L,1);
	arma::mat Y(L,1);
	
	X.fill(1);
	Y.fill(2);
	
	return Rcpp::List::create(
		Rcpp::Named("X") = Rcpp::wrap(X),
		Rcpp::Named("Y") = Rcpp::wrap(Y)	
	);
}


I compile (both using g++ and the Intel Compiler --- choice of compiler makes no difference) and then call from R:


L = 1000000
ret  = .Call("testFun", as.integer(L))
print(ret$X[1:5,])
print(ret$Y[1:5,])


Here's what I often get as output:

[1] 1 1 1 1 1
[1] 1 1 1 1 1

However, the second rows should be all 2's!

When I try to pass smaller matrices, for example by setting L=100000, the problem goes away:

[1] 1 1 1 1 1
[1] 2 2 2 2 2


Also, the problem does not arise when I create and pass pack objects of type Rcpp::NumericMatrix;  so far I've see the problem only with Armadillo objects.  I've encountered this on two Macs running OS X 10.6.6, R 2.12.2, and I'm using the latest versions of Rcpp and RcppArmadillo.

Help on this matter is appreciated!

Günter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110307/e3ef1a9b/attachment.htm>


More information about the Rcpp-devel mailing list