[Rcpp-devel] variable affectation in Rcpp Rcpp Armadillo

Nicolas Heslot nh269 at cornell.edu
Wed Jun 15 23:03:59 CEST 2011


Hi rcpp-devel!
First of all thank you for this awesome tool!

I started a few days ago coding with Rcpp to try to reduce the computing
time of a MCMC model.
However, I don't have experience with C/C++ and I can't figure out how to
reaffect a new content to a variable.
This seems probably very simple to you but I can't figure it out, and this
is the last step preventing my code to work out I think...
The objects all_ui, all_ui2, all_ui3, all_rd and all_corMat are list objects
containing matrix
But once a matrice extracted from one of those lists is affected, to let say
the object ui I can't affect the next matrix to ui at the next iteration.
I tried to find a way to eliminate the object at each iteration or to empty
it using .reset but without success.

So any help would be very much appreciated!
(fragment of code posted below)

arma::mat tmp;
arma::mat tmp2;
arma::mat tmp3;
arma::mat ui;
arma::mat ui2;
arma::mat ui3;
arma::mat sigma;

for (int j = 0; j < P-1; j++) {
tmp2.fill(0);
tmp3.fill(0);
 for (int i = 0; i < N-1; i++) {
 ui = all_ui[i];
ui2 = all_ui2[i];
 ui3 = all_ui3[i];
rdi = all_rd[i];
all_corMati = all_corMat[i];
 sigma = sigma2*all_corMat[i];
// calculate mean and variance
arma::mat tmp = (solve(sig%all_corMat[i])* gen_a(i,j))*all_ui[i];
arma::mat tmp2 += (all_rd[i] -
mu*trans(all_ui3[i])-(X(i)*alpha)*trans(all_ui2[i]) +
gen_a(i,j)*a.row(j)*trans(all_ui[i]))*tmp;
arma::mat tmp3 += (gen_a(i,j)*trans(all_ui[i]))*tmp;
}
}

Thank you for your help

It probably does not help much
but I use R2.13 with the last version of the packages on a windows XP
plateform

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110615/afc81270/attachment.htm>


More information about the Rcpp-devel mailing list