Message-ID: <CAMbX5wn2G9tT7vj-WMCvbO9V-b=Q-jd-R+pO0aptuZVacWz6Zg@mail.gmail.com>
Date: 2016-12-14T02:51:48Z
From: Amina Shahzadi
Subject: [Rcpp-devel] a variable for loop
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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161214/b6645368/attachment.html>