[Rcpp-devel] r crashed
Kevin Ushey
kevinushey at gmail.com
Thu Jan 31 08:22:50 CET 2013
Hi Aileen,
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?
Otherwise, it's really difficult to debug when we don't have the actual
data available.
Try to distill the functions you have into the smallest possible pieces
that still produce an error.
-Kevin
On Wed, Jan 30, 2013 at 6:22 PM, Aileen Lin <aileenshanhong.lin at gmail.com>wrote:
> Hi there,
>
> Thanks for replies for my earlier enquiries.
>
> I had an error message: 'R encoutered a fatal error. This session was
> terminated'.
>
> My code is here:
> //[[Rcpp::depends("RcppArmadillo")]]
> #include <Rcpp.h>
> #include <vector>
> #include <iostream>
> using namespace std;
> using std::vector;
> using namespace Rcpp;
> typedef vector<vector<vector<double > > > array3d;
>
> //[[Rcpp::export]]
> array3d systematic_composite(NumericMatrix cdx, NumericMatrix idx,
> NumericMatrix cs_compvar){
> array3d arraysc;
> int d1 = cdx.ncol();
> int d2 = idx.ncol();
> int d3 = cdx.nrow();
> arraysc.resize(d1);
> for (int i=0; i<d1; ++i){
> arraysc[i].resize(d2);
> for (int j=0; j<d2; ++j){
> arraysc[i][j].resize(d3);
> }
> }
> for (int i=0; i<d1; ++i){
> for (int j=0; j<d2; ++j){
> for (int k=0; k<d3; ++k){
> arraysc[i][j][k] = (cdx(k,i) + idx(k,j))/sqrt(cs_compvar(i,j));
> }
> }
> }
> return arraysc;
> }
>
> //[[Rcpp::export]]
> NumericVector wrap_sim1(NumericMatrix cdx, NumericMatrix idx,
> NumericMatrix cs_compvar, NumericMatrix pf_agg,
> NumericVector noise, int w_pdlgd){
> int d1 = pf_agg.nrow();
> int d2 = cdx.nrow();
> double ci=0, di=0;
> double core_temp = 0, grp_avgpd_temp = 0, lgd_temp = 0;
> double w_circle = sqrt(1-w_pdlgd*w_pdlgd);
> NumericVector lln_temp(d2);
> NumericVector lln_sum(d2);
> for (int i=0; i<d2; ++i) lln_sum(i) = 0;
> array3d corex = systematic_composite(cdx, idx, cs_compvar);
>
> for (int j=0; j<d1; ++j){
> ci = pf_agg(j, 0);
> di = pf_agg(j, 1);
> for (int k=0; k<d2; ++k){
> core_temp = corex[ci][di][k];
> grp_avgpd_temp = Rcpp::stats::pnorm_0(
> (pf_agg(j, 7)- pf_agg(j, 8) * core_temp)/pf_agg(j, 9),
> 1,0);
> lgd_temp = exp(
> pf_agg(j,4) + pf_agg(j,5) *(
> w_pdlgd *core_temp + noise(k) * w_circle)
> );
> lln_temp(k) = pf_agg(j, 6) * grp_avgpd_temp * lgd_temp;
> lln_sum(k) = lln_sum(k) + lln_temp(k);
> }
> }
> return lln_sum;
> }
>
> ###########################
> >R:
> system.time(x <- wrap_sim1(cdx[,], idx[,], csx[,], pfagg_expand, noise1,
> -0.42))
> cdx is a big matrix 100K*7
> idx is a big matrix 100k*14
> csx is a big matrix 7*14
> pfagg_expand is a matrix 2323*10
> They are all numerical.
> 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.
>
>
>
> --
> Aileen L.
>
>
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130130/e5f8ec3e/attachment-0001.html>
More information about the Rcpp-devel
mailing list