I have the following code :
iterator = u.U.begin(); //u.U is a map<bitset,long>
int sizeofIterator = u.U.size();
for ( int pp = 0; pp<sizeofIterator; pp++ ){
double *faux = new double[q];
for (int k = 0 ; k<q ; k++){
faux[k]=1;
}
for (int k=0; k<q ; k++){
for (int i=0; i<I ; i++){
faux[k]= faux[k]*successProbability(theta[k],a[i],b[i],c[i]);
}
faux[k] = faux[k]*nodeWeight[k];
}
double sum = 0;
for (int k=0; k<q ; k++){
sum += faux[k];
}
for (int k=0; k<q; k++){
faux[k] = faux[k]/sum;
faux[k] = iterator->second * faux[k];
f[k] = faux[k]+f[k];
for(int i = 0; i<I; i++){
if(iterator->first[i]){
double aux = faux[k];
r[k*I+i]=r[k*I+i]+aux;
}
}
}
iterator++;
}
When that code is run, I've got a segmentation fault. I've got some conclusions and I know that the problem is in the line that's got
iterator++;
The iterator has to iterate 32 times (the size of the map) but the segfault occurs in the 18th iteration
TIP: When I comment the aux in line: r[k*I+i]=r[k*I+i]+aux;
i.e. I put the following r[k*I+i]=r[k*I+i]+0;//+aux;
All works (But I need to perform that sum, surely!)
¿Do you know why? ¿Can you help me please?
Thanks in advance
EDIT : We could not replicate the error on less code, it simply works, but is not the code we want to work :(