Hi Dear I have a problem in using a variable for loop in using RcppArmadillo library. I have pasting here my code. It is executing but not giving the same results as its R code version gives. The results produced by it are really weird. I have checked it step by step. It is because of the for (int q=0; q<i; q++). I request tp please help how to handle it in cpp.
The another question is I want to multiply the cube b(i, ,) by a scalar. How can we consider the entire columns and slices of a cube for each of the rows. "b(span(i), span(), span())" is not working for me. Thank you #include <RcppArmadillo.h> using namespace Rcpp; using namespace RcppArmadillo; //[[Rcpp::depends(RcppArmadillo)]] //[[Rcpp::export]] arma::cube up(arma::mat a){ int m = a.n_cols; int n = a.n_rows; int p = a.n_rows; arma::cube b(n, m, p); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ for(int q=0; q<i; q++){ if(q==0){ b(i, j, q) = a(i, j); } else{ b(i, j, q) = 0.0; } } } } return b; } -- *Amina Shahzadi*
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel