Message-ID: <F54BE6F5-0B2B-4ED7-A8A7-BFE12877A11E@uni-bonn.de>
Date: 2013-08-26T11:28:17Z
From: Simon Zehnder
Subject: [Rcpp-devel] Non-contiguous submatrix
In-Reply-To: <21019.15098.356480.755001@max.nulle.part>
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