[Rcpp-devel] redimension help
Silkworth,David J.
SILKWODJ at airproducts.com
Wed Jun 8 05:18:14 CEST 2011
I have not been slack on reviewing the archives, but they ARE hard to
search.
So far, I am led to believe that a list of vectors can only be accessed
during initialization.
This would seem to be a real problem for entering elements in looped
increments 10's of thousands of times.
The original matrix scheme DOES work, but I think I have to improve the
estimated size of rows, so that I don't create an excessive memory foot
print. Once dimensioned a matrix apparently is not going to be resized.
I am aware that as long as my individual vectors and my matrix row
lengths are the same size that these will combine into an
Rcpp::DataFrame.
Once in R I would have to either find a way to ignore the unfilled
elements or hopefully the following code would not be too oppressive:
RcppDF<-RcppDF[1:r,]
I just thought it would be possible to do in C++
Try this:
require(inline)
src <- '
int s = 7; // result of original oversize estimate before process
runs
int c = 3; //known column count established from a list argument
(variable to function)
int r = 4; // number of rows that more complex process found
necessary to fill
int i = 0;
Rcpp::List Lmv(c) ; // list of matrix column vectors
for( i=0; i<c; i++) {
Rcpp::IntegerVector m(s) ;
// insertion of next three lines partially fills the matrix column
vectors
// the same way as previous sample code
for( int j=0; j<r; j++){
m(j)= (i+1)*(j+1);
}
Lmv[i] = m;
}
// this code does not access the vector elements as I wish
for(int j=0; j<c; j++) {
for( i=0; i<r; i++) {
Rcpp::IntegerVector v = Lmv(j);
v(i) = (i+1)*(j+1);
}
}
return Lmv;
'
fun <- cxxfunction(signature(), src, plugin = "Rcpp")
print(fun())
And please do search the list archives. I explained a few times already
why
using [][] cannot work.
Not all STL methods exist in all Rcpp classes.
Dirk
More information about the Rcpp-devel
mailing list