[Rcpp-devel] Rcpp matrix generation crashes my R session

Simon Zehnder szehnder at uni-bonn.de
Sat Jun 22 18:51:48 CEST 2013


I actually do not know, for what you are using this function.....are you calling it from R or inside another C++ function?

On Jun 22, 2013, at 6:49 PM, Simon Zehnder <szehnder at uni-bonn.de> wrote:

> Marc, 
> 
> 
> I tried it via an inline function and I got a segfault.....
> 
> it is probably the return value: Rcpp::wrap(weightsNet) instead of solely weightsNet.
> 
> Best 
> 
> Simon
> 
> 
> On Jun 22, 2013, at 6:10 PM, Marc Jekel <mjekel at uni-bonn.de> wrote:
> 
>> Dear Rcpp users,
>> 
>> I am a beginner, I was inspired by the new book by Eddelbuettel and just started to use Rccp. So far, everything works fine except for one function. The strange thing about it is that I runs perfectly when I call it several times but crashes my R session at some point (usually after the third call). I checked it on two Win 8 PCS to make sure it is nothing related to my PC.
>> 
>> Here is the code:
>> 
>> ##########
>> 
>> #include <Rcpp.h>
>> using namespace Rcpp;
>> 
>> // [[Rcpp::export]]
>> NumericMatrix transPCSpairwiseComp_C(
>> NumericVector validities,
>> NumericMatrix pattern,
>> int numbCues
>> ){
>> 
>> NumericMatrix weightsNet(numbCues+3,numbCues+3);
>> 
>> for(int loop = 0; loop < numbCues; loop++){
>> 
>> weightsNet(0,1+loop) = validities[loop];
>> }
>> 
>> for(int loopCol = 0; loopCol < numbCues; loopCol++){
>> for(int loop = 0; loop < numbCues; loop++){
>> weightsNet(1+loopCol, numbCues + 1 + loop)=
>> pattern(loopCol,loop);
>> 
>> }}
>> 
>> weightsNet(numbCues+1, numbCues+1) = 0;
>> weightsNet(numbCues+1, numbCues+2) = -.2;
>> 
>> for(int LoopCol = 0; LoopCol < weightsNet.nrow(); LoopCol++){
>> for(int LoopRow = 0; LoopRow < weightsNet.nrow(); LoopRow++){
>> weightsNet(LoopCol,LoopRow) = weightsNet(LoopCol,LoopRow) + weightsNet(LoopRow,LoopCol);
>> }}
>> 
>> 
>> return weightsNet;
>> }
>> 
>> #########
>> 
>> So it is very basic code, a matrix is created based on three inputs (the vector "validities", the matrix "pattern", and the integer "numbCues"). My impression is that the very first command (creating the matrix weightsNet) is problematic because R also crashes when I delete all other code (although usually not after the third time I call it).
>> 
>> Thanks for any hint!
>> 
>> Marc
>> 
>> 
>> 
>> _______________________________________________
>> 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
> 



More information about the Rcpp-devel mailing list