[Rcpp-devel] Non-contiguous submatrix
Simon Zehnder
szehnder at uni-bonn.de
Mon Aug 26 12:19:45 CEST 2013
Dear Rcpp::Users and Rcpp::Devels,
I am right now working on a relabeling algorithm where I have a function taking a permutation matrix of all permutations of the labels. Inside the function the values should be permuted in respect to a row of this matrix. In R I would use the following commands:
values <- matrix(rnorm(4), ncol = 2, nrow = 2, byrow = TRUE)
perm <- as.matrix(expand.grid(seq(1, 2), seq(1, 2)))
index <- perm[which(perm[, 1] != perm[, 2]),]
values[, index[, 1]]
values[, index[, 2]]
I found this thread on stackoverflow: http://stackoverflow.com/questions/8435169/selecting-a-non-contiguous-submatrix-in-rcpp. Are there any proceedings for non-contiguous submatrices in Rcpp? I couldn't find a hint in the Rcpp-book (neither in chapter 3 nor in chapter 8). I would like to avoid nested loops and I need the values as Rcpp::NumericMatrix objects for the functions (so using RcppArmadillo (via non-contiguous views) is only a path I would choose if no other simpler possibilities are available). Any suggestions are welcome.
@Rcpp::Devels: I try to understand in the doxygen documentation how the operator '()' works. I see that there is always a VECTOR::Proxy underlying each Matrix object and I end up at the traits::r_vector_proxy in the 00_forward_proxy.h file. I assume, that each Matrix object has its type given by the proxy and acts in regard to this characterization. Where can I look for more information about this struct?
Best
Simon
More information about the Rcpp-devel
mailing list