Hi there,<div><br></div><div>Thanks for replies for my earlier enquiries. </div><div><br></div><div>I had an error message: 'R encoutered a fatal error. This session was terminated'.</div><div><br></div><div>My code is here:</div>
<div><div>//[[Rcpp::depends("RcppArmadillo")]]</div><div>#include <Rcpp.h></div><div>#include <vector></div><div>#include <iostream></div><div>using namespace std;</div><div>using std::vector;</div>
<div>using namespace Rcpp;</div><div>typedef vector<vector<vector<double > > > array3d;</div><div><br></div><div>//[[Rcpp::export]]</div><div>array3d systematic_composite(NumericMatrix cdx, NumericMatrix idx,</div>
<div> NumericMatrix cs_compvar){</div><div> array3d arraysc;</div><div> int d1 = cdx.ncol();</div><div> int d2 = idx.ncol();</div><div> int d3 = cdx.nrow();</div><div> arraysc.resize(d1);</div>
<div> for (int i=0; i<d1; ++i){</div><div> arraysc[i].resize(d2);</div><div> for (int j=0; j<d2; ++j){</div><div> arraysc[i][j].resize(d3);</div><div> }</div><div> }</div><div> for (int i=0; i<d1; ++i){</div>
<div> for (int j=0; j<d2; ++j){</div><div> for (int k=0; k<d3; ++k){</div><div> arraysc[i][j][k] = (cdx(k,i) + idx(k,j))/sqrt(cs_compvar(i,j));</div><div> }</div><div> }</div><div> } </div><div>
return arraysc;</div><div>}</div><div><br></div><div>//[[Rcpp::export]]</div><div>NumericVector wrap_sim1(NumericMatrix cdx, NumericMatrix idx,</div><div> NumericMatrix cs_compvar, NumericMatrix pf_agg,</div>
<div> NumericVector noise, int w_pdlgd){</div><div> int d1 = pf_agg.nrow();</div><div> int d2 = cdx.nrow();</div><div> double ci=0, di=0;</div><div> double core_temp = 0, grp_avgpd_temp = 0, lgd_temp = 0;</div>
<div> double w_circle = sqrt(1-w_pdlgd*w_pdlgd);</div><div> NumericVector lln_temp(d2);</div><div> NumericVector lln_sum(d2);</div><div> for (int i=0; i<d2; ++i) lln_sum(i) = 0; </div><div> array3d corex = systematic_composite(cdx, idx, cs_compvar); </div>
<div> </div><div> for (int j=0; j<d1; ++j){</div><div> ci = pf_agg(j, 0);</div><div> di = pf_agg(j, 1);</div><div> for (int k=0; k<d2; ++k){</div><div> core_temp = corex[ci][di][k];</div><div> grp_avgpd_temp = Rcpp::stats::pnorm_0(</div>
<div> (pf_agg(j, 7)- pf_agg(j, 8) * core_temp)/pf_agg(j, 9),</div><div> 1,0);</div><div> lgd_temp = exp(</div><div> pf_agg(j,4) + pf_agg(j,5) *(</div><div> w_pdlgd *core_temp + noise(k) * w_circle)</div>
<div> );</div><div> lln_temp(k) = pf_agg(j, 6) * grp_avgpd_temp * lgd_temp;</div><div> lln_sum(k) = lln_sum(k) + lln_temp(k);</div><div> } </div><div> }</div><div> return lln_sum;</div><div>}</div></div>
<div><br></div><div>###########################</div><div>>R:</div><div>system.time(x <- wrap_sim1(cdx[,], idx[,], csx[,], pfagg_expand, noise1, -0.42))</div><div>cdx is a big matrix 100K*7</div><div>idx is a big matrix 100k*14</div>
<div>csx is a big matrix 7*14</div><div>pfagg_expand is a matrix 2323*10</div><div>They are all numerical.</div><div>in this case, my R program crashes. if I replace pfagg_expand with pfagg_expand[c(2,3),] in my R command, it works fine. Any idea what is going on? Thank you.</div>
<div><br></div><div><br clear="all"><div><br></div>-- <br>Aileen L.<div><br><div><br></div><div><h2 style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:2px;padding-right:2px;padding-bottom:0px;padding-left:0px;font-weight:normal;min-height:35px;font-family:Geneva,Arial,Helvetica,sans-serif;text-align:left;background-color:rgb(255,255,255)">
<br><br><font color="#cc33cc"></font></h2></div></div>
</div>