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
[Rcpp-devel] Non-contiguous submatrix
5 messages · Romain Francois, Simon Zehnder, Dirk Eddelbuettel
Le 26 ao?t 2013 ? 12:19, Simon Zehnder <szehnder at uni-bonn.de> a ?crit :
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.
Writing loops is what you do in c++. There is no guilty conscience like in R.
@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?
In the source files. You'll have to jump between several files. Not easy to follow, even for us. Good luck.
Best Simon
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Hi Romain, thanks for the quick reply! This is an answer I can work with! Best Simon
On Aug 26, 2013, at 12:33 PM, Romain Francois <romain at r-enthusiasts.com> wrote:
Le 26 ao?t 2013 ? 12:19, Simon Zehnder <szehnder at uni-bonn.de> a ?crit :
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.
Writing loops is what you do in c++. There is no guilty conscience like in R.
@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?
In the source files. You'll have to jump between several files. Not easy to follow, even for us. Good luck.
Best Simon
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
On 26 August 2013 at 12:19, Simon Zehnder wrote:
| 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? Not in Rcpp -- but Armadillo has it and this example on the Rcpp Gallery uses it along with RcppArmadillo: http://gallery.rcpp.org/articles/armadillo-subsetting/ Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Thanks Dirk! That looks interesting! I will check which solution performs better in my application! Best Simon
On Aug 26, 2013, at 1:24 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
On 26 August 2013 at 12:19, Simon Zehnder wrote: | 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? Not in Rcpp -- but Armadillo has it and this example on the Rcpp Gallery uses it along with RcppArmadillo: http://gallery.rcpp.org/articles/armadillo-subsetting/ Dirk -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com