Hi Aileen,<div><br></div><div>First thing that pops out: you declare 'w_pdlgd' as type int, but submit the double -0.42. Also, you aren't using anything from RcppArmadillo here, and you don't need the includes from vector or iostream here either it seems. Also, you didn't specify anything about the 'noise' vector -- is it of proper length?</div>
<div><br></div><div>Otherwise, it's really difficult to debug when we don't have the actual data available.</div><div><br></div><div>Try to distill the functions you have into the smallest possible pieces that still produce an error.</div>
<div><br></div><div>-Kevin</div><div><br></div><div><div class="gmail_quote">On Wed, Jan 30, 2013 at 6:22 PM, Aileen Lin <span dir="ltr"><<a href="mailto:aileenshanhong.lin@gmail.com" target="_blank">aileenshanhong.lin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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>
<span class="HOEnZb"><font color="#888888">
<div><br></div><div><br clear="all"><div><br></div>-- <br>Aileen L.<div><br><div><br></div><div><h2 style="padding-right:2px;padding-left:0px;padding-top:2px;text-align:left;margin-bottom:0px;font-weight:normal;min-height:35px;padding-bottom:0px;margin-right:0px;margin-left:0px;font-family:Geneva,Arial,Helvetica,sans-serif;margin-top:0px">
<br><br><font color="#cc33cc"></font></h2></div></div>
</div>
</font></span><br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br></div>