[Rcpp-devel] variable affectation in Rcpp Rcpp Armadillo

Dirk Eddelbuettel edd at debian.org
Thu Jun 16 01:52:42 CEST 2011


Salut Nicolas,

On 15 June 2011 at 17:03, Nicolas Heslot wrote:
| Hi rcpp-devel!
| First of all thank you for this awesome tool!

Pleasure, and welcome.
 
| 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

I'm with Whit here and confess that I do not know your question is. If you
show us what you tried, what you expected to happen and what actually
happened we may help.

(By the way, there is no tax on indentation in code and it does make it more
readable for those of us who didn't write it ;-)

Dirk
 
| It probably does not help much
| but I use R2.13 with the last version of the packages on a windows XP plateform
| 
| Nicolas
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| 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

-- 
Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com


More information about the Rcpp-devel mailing list