[Rcpp-commits] r2320 - in pkg/RcppDE: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Oct 16 23:42:21 CEST 2010


Author: edd
Date: 2010-10-16 23:42:21 +0200 (Sat, 16 Oct 2010)
New Revision: 2320

Modified:
   pkg/RcppDE/benchmark.txt
   pkg/RcppDE/src/de4_0.cpp
Log:
eliminate a bunch of 'element copy loops' in the i_bs_flag case


Modified: pkg/RcppDE/benchmark.txt
===================================================================
--- pkg/RcppDE/benchmark.txt	2010-10-16 21:28:39 UTC (rev 2319)
+++ pkg/RcppDE/benchmark.txt	2010-10-16 21:42:21 UTC (rev 2320)
@@ -174,3 +174,36 @@
 Genrose20   0.886389 0.897556           1.0126      -1.25979
 Genrose50   2.523278 2.563389           1.0159      -1.58964
 MEANS       0.563056 0.571139           1.0144      -1.43562
+
+
+# At  2010-10-16 16:26:55.718442
+# SVN  2318M 
+             DEoptim   RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2  0.040167 0.041000          1.02075      -2.07469
+Rastrigin5  0.105333 0.106500          1.01108      -1.10759
+Rastrigin20 0.540556 0.540778          1.00041      -0.04111
+Wild2       0.066056 0.066444          1.00589      -0.58873
+Wild5       0.181111 0.181000          0.99939       0.06135
+Wild20      1.038278 1.035222          0.99706       0.29429
+Genrose2    0.070389 0.070722          1.00474      -0.47356
+Genrose5    0.186778 0.185222          0.99167       0.83284
+Genrose20   0.894556 0.896833          1.00255      -0.25463
+Genrose50   2.531000 2.548667          1.00698      -0.69801
+MEANS       0.565422 0.567239          1.00321      -0.32129
+
+
+# At  2010-10-16 16:41:11.48119
+# SVN  2319M 
+             DEoptim   RcppDE ratioRcppToBasic pctGainOfRcpp
+Rastrigin2  0.040167 0.042056           1.0470      -4.70263
+Rastrigin5  0.104889 0.109889           1.0477      -4.76695
+Rastrigin20 0.539667 0.548500           1.0164      -1.63681
+Wild2       0.065667 0.066944           1.0195      -1.94585
+Wild5       0.180333 0.183111           1.0154      -1.54036
+Wild20      1.034167 1.040500           1.0061      -0.61241
+Genrose2    0.069444 0.071667           1.0320      -3.20000
+Genrose5    0.183278 0.186722           1.0188      -1.87936
+Genrose20   0.886167 0.897000           1.0122      -1.22249
+Genrose50   2.527722 2.571667           1.0174      -1.73850
+MEANS       0.563150 0.571806           1.0154      -1.53699
+

Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp	2010-10-16 21:28:39 UTC (rev 2319)
+++ pkg/RcppDE/src/de4_0.cpp	2010-10-16 21:42:21 UTC (rev 2320)
@@ -330,43 +330,49 @@
 	    }
 	} // End mutation loop through pop., ie the "for (i = 0; i < i_NP; i++)"
 
-	if (i_bs_flag) {
-	    /* examine old and new pop. and take the best NP members into next generation */
-	    for (i = 0; i < i_NP; i++) {
-		for (j = 0; j < i_D; j++) 
-		    ta_popP.at(i,j) = ta_oldP.at(i,j);
-		ta_popC[i] = ta_oldC[i];
-	    }
-	    for (i = 0; i < i_NP; i++) {
-		for (j = 0; j < i_D; j++) 
-		    ta_popP.at(i_NP+i,j) = ta_newP.at(i,j);
-		ta_popC[i_NP+i] = ta_newC[i];
-	    }
+	if (i_bs_flag) {	// examine old and new pop. and take the best NP members into next generation 
+	    
+	    // for (i = 0; i < i_NP; i++) {
+	    // 	for (j = 0; j < i_D; j++) 
+	    // 	    ta_popP.at(i,j) = ta_oldP.at(i,j);
+	    // 	ta_popC[i] = ta_oldC[i];
+	    // }
+	    ta_popP.rows(0, i_NP-1) = ta_oldP;
+	    ta_popC.rows(0, i_NP-1) = ta_oldC;
+
+	    // for (i = 0; i < i_NP; i++) {
+	    // 	for (j = 0; j < i_D; j++) 
+	    // 	    ta_popP.at(i_NP+i,j) = ta_newP.at(i,j);
+	    // 	ta_popC[i_NP+i] = ta_newC[i];
+	    // }
+	    ta_popP.rows(i_NP, 2*i_NP-1) = ta_newP;
+	    ta_popC.rows(i_NP, 2*i_NP-1) = ta_newC;
+
 	    i_len = 2 * i_NP;
-	    step = i_len;  /* array length */
+	    step = i_len;  		// array length 
 	    while (step > 1) {
-		step /= 2;   /* halve the step size */
+		step /= 2;   		// halve the step size 
 		do {
 		    done = 1;
 		    bound  = i_len - step;
 		    for (j = 0; j < bound; j++) {
 			i = j + step + 1;
 			if (ta_popC[j] > ta_popC[i-1]) {
-			    for (k = 0; k < i_D; k++) 
-				tempP[k] = ta_popP.at(i-1, k);
+			    //for (k = 0; k < i_D; k++) tempP[k] = ta_popP.at(i-1, k);
+			    tempP = ta_popP.row(i-1);
 			    tempC = ta_popC[i-1];
-			    for (k = 0; k < i_D; k++) 
-				ta_popP.at(i-1,k) = ta_popP.at(j,k);
+			    //for (k = 0; k < i_D; k++) ta_popP.at(i-1,k) = ta_popP.at(j,k);
+			    ta_popP.row(i-1) = ta_popP.row(j);
 			    ta_popC[i-1] = ta_popC[j];
-			    for (k = 0; k < i_D; k++) 
-				ta_popP.at(j,k) = tempP[k];
+			    //for (k = 0; k < i_D; k++) ta_popP.at(j,k) = tempP[k];
+			    ta_popP.row(j) = tempP;
 			    ta_popC[j] = tempC;
 			    done = 0; 
-			    /* if a swap has been made we are not finished yet */
-			}  /* if */
-		    }  /* for */
-		} while (!done);   /* while */
-	    } /*while (step > 1) */
+			    // if a swap has been made we are not finished yet 
+			}  // if 
+		    }  // for 
+		} while (!done);   // do .. while 
+	    } // while (step > 1) 
 	    /* now the best NP are in first NP places in gta_pop, use them */
 	    for (i = 0; i < i_NP; i++) {
 		for (j = 0; j < i_D; j++) 



More information about the Rcpp-commits mailing list