Hello Friends and Prof. Dirk

I am pasting here a code which has a for loop depending on another for
loop.
I am getting zeros for cube c. I tried and searched a lot but did not get
an example of this type. Would you please help in this regard?


#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace RcppArmadillo;
using namespace arma;
//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::export]]


arma::cube  exam(arma::vec a,  arma::mat b)
{
  int m = a.size();
  int n = b.n_rows;
  arma::cube c = zeros<cube>(n, m, n);
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      for(int k=0; k<i; k++) {
          if(k==0) {
            c(i, j ,k) = c(i, j, k) + b(i, j);
          }
          else{
            c(i, j, k) = c(i, j, k) +  c(i-1, j, k) *b(i, j);
          }
         }
        }
      }
  return c;
}


Thank You
-- 
*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

Reply via email to