<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>I'm new to Rcpp and RcppArmadillo---so far I like it a lot! &nbsp;Thanks to the developers for their good work.</div><div><br></div><div>I run into a peculiar kind of problem when I try to pass a "large" Armadillo object back to R. &nbsp;Here's some code to replicate the problem in stylized form:</div><div><br></div><div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">extern "C" SEXP testFun(SEXP L_)</font></div><div><font class="Apple-style-span" face="'Courier New'">{</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">const long L &nbsp;= Rcpp::as&lt;long&gt;(L_);</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">arma::mat X(L,1);</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">arma::mat Y(L,1);</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">X.fill(1);</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">Y.fill(2);</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">return Rcpp::List::create(</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">                </font></span><font class="Apple-style-span" face="'Courier New'">Rcpp::Named("X") = Rcpp::wrap(X),</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">                </font></span><font class="Apple-style-span" face="'Courier New'">Rcpp::Named("Y") = Rcpp::wrap(Y)</font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'Courier New'">        </font></span><font class="Apple-style-span" face="'Courier New'">);</font></div><div><font class="Apple-style-span" face="'Courier New'">}</font></div></div><div><br></div><div><div><br></div><div>I compile (both using g++ and the Intel Compiler --- choice of compiler makes no difference) and then call from R:</div><div><br></div><div><br></div><div><font class="Apple-style-span" face="'Courier New'">L = 1000000</font></div><div><font class="Apple-style-span" face="'Courier New'">ret &nbsp;= .Call("testFun", as.integer(L))</font></div><div><font class="Apple-style-span" face="'Courier New'">print(ret$X[1:5,])</font></div><div><font class="Apple-style-span" face="'Courier New'">print(ret$Y[1:5,])</font></div></div><div><br></div><div><br></div><div>Here's what I often get as output:</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">[1] 1 1 1 1 1</font></div><div><font class="Apple-style-span" face="'Courier New'">[1] 1 1 1 1 1</font></div></div><div><br></div><div>However, the second rows should be all 2's!</div><div><br></div><div>When I try to pass smaller matrices, for example by setting <font class="Apple-style-span" face="'Courier New'">L=100000</font>, the problem goes away:</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">[1] 1 1 1 1 1</font></div><div><font class="Apple-style-span" face="'Courier New'">[1] 2 2 2 2 2</font></div></div><div><br></div><div><br></div><div>Also, the problem does not arise when I create and pass pack objects of type Rcpp::NumericMatrix; &nbsp;so far I've see the problem only with Armadillo objects. &nbsp;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.</div><div><br></div><div>Help on this matter is appreciated!</div><div><br></div><div>Günter</div><div><br></div></body></html>