c++ - Allocating a large 2D array of NumericVectors in Rcpp -


i trying allocate large(ish) 2d array of numericvectors (the total memory should around 16mb barring overhead), stack overflow. here smallest reproducible example can come with:

require(rcpp) require(inline) testfun = cxxfunction(     signature(x="list"),     body='using namespace std;         vector<vector<numericvector> > rs=as< vector<vector<numericvector> > >( x );         return wrap(rs);',     plugin="rcpp") x=lapply(1:1000,function(g) lapply(1:1000, function(h) runif(3))) testfun(x) 

profiling gdb tells me deep in libr.so recursion. note while here arrays rectangular use numericmatrix instead in actual problem jagged. thoughts.

edit: solution using (fairly new) listof<t> template class:

require(rcpp) require(inline) testfun = cxxfunction(   signature(x="list"),   body='using namespace std;         listof<listof<numericvector> > rs=as< listof<listof<numericvector> > >( x );         return wrap(rs);',   plugin="rcpp") x=lapply(1:1000,function(g) lapply(1:1000, function(h) runif(3))) testfun(x) 

we replace calls std::vector rcpp::listof and, magically, works. best of -- data not copied here (assuming x list of numeric vectors).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -