[Rcpp-devel] Creating a multidimensional array
Barth Riley
barthriley at comcast.net
Tue Jul 31 20:55:44 CEST 2018
Dear list
I am trying to create a simple Rcpp function that creates a three-dimensional array based on the values of a four-dimensional array. The arrays are declared as NumericVectors with a dim attribute represent the number of levels of each dimension. Here is a sample of the code:
NumericVector sumby4(NumericVector X) {
Dimension dim = X.attr("dim");
if(dim.size() != 4) return NULL;
NumericVector ret = NumericVector::create(dim[0],dim[1],dim[2]);
for(int i = 0; i < dim[0]; i++) {
for(int j = 0; j < dim[1]; j++) {
for(int k = 0; k < dim[2]; k++) {
ret(i,j,k) = NA_REAL;
…
When I attempt to compile the package in which this function resides, I get the error message associated with the “ret(I,j,k) = NA_REAL” line:
No match for call to Rcpp::NumericVector Rcpp::Vector<14 Rcpp::PreserveStorage>})(int&, int&, int&)
I take from this message that the NumericVector ret cannot be indexed by three values, even though it has been dimensioned as a 3D array. What am I doing wrong here?
Barth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180731/de61d690/attachment.html>
More information about the Rcpp-devel
mailing list