Dear all,
Thank you for the fast and helpful replies! I was able to fix the
function/the problem.
There was indeed a problem with the matrix index, thank you Dirk! And
using "return Rcpp::wrap(weightsNet)" instead of "return weightsNet"
helped to fix a problem when I created a R-package with the function
included, thank you Simon!
Simon: I call the function from a program in R. The function creates a
matrix based on the input that I need for a neural network.
Best, Marc
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 <[email protected]> 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 <[email protected]> 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
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel