// xy is passed in so that there is no need to allocate memory for getting rank // m=n double compute_wmw_paired_replicates_stat(double *X0, double *Y0, double *X, double *Y, int * lenY, int m) { int i,j,k; int cnt=0; for (i = 0; i < m; i++) { k=lenY[i]; int* index = (int*)malloc(1*sizeof(int)); int* perm = (int*)malloc((1+k)*sizeof(int)); SampleNoReplace(1, 1+k, index, perm);//index is the new X1, perm[1:n] is the new Z //PRINTF("%i %i", k, index[0]); PRINTF("\n"); for (j=1; j<index[0]; j++) {Y[cnt]=Y0[cnt]; cnt++;} if (index[0]==k+1) X[i]=X0[i]; else { X[i]=Y0[cnt]; Y[cnt]=X0[i]; cnt++; for (j=index[0]+1; j<=k; j++) {Y[cnt]=Y0[cnt]; cnt++;} } free(index); free(perm); } //PRINTF("%f %f", stat, mu); PRINTF("\n"); return 0; }
// modificato il prototipo per aumentare l'efficienza VETTOREi *sample1(VETTOREi *ris, int n, int k, int replace, double *p) { int *x; int i, nc = 0; GetRNGstate(); CREAv_i(ris, k); // g_x mi serve comunque (e sempre di dim. n) // OTTIMIZZATA da me! CREAv_i(g_x, n); // cosi` non ho problemi nel caso sia troppo piccolo x = g_x->dati; if (p != NULL) { FixupProb(p, n, k, replace); if (replace) { for (i = 0; i < n; i++) { if (n * p[i] > 0.1) nc++; } if (nc > 200) walker_ProbSampleReplace(n, p, x, k, ris->dati); else ProbSampleReplace(n, p, x, k, ris->dati); } else ProbSampleNoReplace(n, p, x, k, ris->dati); } else { /* avoid allocation for a single sample */ if (replace || k < 2) SampleReplace(k, n, ris->dati); else { // ho gia` allocato g_x SampleNoReplace(k, n, ris->dati, x); } } PutRNGstate(); return ris; }