[Rcpp-commits] r2315 - pkg/RcppDE/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Oct 16 22:44:57 CEST 2010


Author: edd
Date: 2010-10-16 22:44:57 +0200 (Sat, 16 Oct 2010)
New Revision: 2315

Modified:
   pkg/RcppDE/src/Makevars
   pkg/RcppDE/src/de4_0.cpp
   pkg/RcppDE/src/evaluate.cpp
Log:
back to pointer-less interface to evaluate


Modified: pkg/RcppDE/src/Makevars
===================================================================
--- pkg/RcppDE/src/Makevars	2010-10-16 20:26:37 UTC (rev 2314)
+++ pkg/RcppDE/src/Makevars	2010-10-16 20:44:57 UTC (rev 2315)
@@ -2,4 +2,5 @@
 ##PKG_CXXFLAGS=-ftree-parallelize-loops=8
 ##PKG_LIBS=$(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -fopenmp
 ##PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
+##PKG_CXXFLAGS+=-D_FORTIFY_SOURCE=0 -g0 -funsafe-loop-optimizations -Wunsafe-loop-optimizations
 PKG_LIBS= $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

Modified: pkg/RcppDE/src/de4_0.cpp
===================================================================
--- pkg/RcppDE/src/de4_0.cpp	2010-10-16 20:26:37 UTC (rev 2314)
+++ pkg/RcppDE/src/de4_0.cpp	2010-10-16 20:44:57 UTC (rev 2315)
@@ -21,8 +21,8 @@
            arma::rowvec & d_pop, arma::rowvec & d_storepop, arma::rowvec & d_bestmemit, arma::rowvec & d_bestvalit,
            int & i_iterations, double i_pPct, long & l_nfeval);
 void permute(int ia_urn2[], int i_urn2_depth, int i_NP, int i_avoid, int ia_urntmp[]);
-//RcppExport double evaluate(long & l_nfeval, const arma::rowvec & param, SEXP par, SEXP fcall, SEXP env);
-RcppExport double evaluate(long & l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env);
+RcppExport double evaluate(long & l_nfeval, const arma::rowvec & param, SEXP par, SEXP fcall, SEXP env);
+//RcppExport double evaluate(long & l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env);
 
 RcppExport SEXP DEoptimC(SEXP lowerS, SEXP upperS, SEXP fnS, SEXP controlS, SEXP rhoS) {
     BEGIN_RCPP ;	// macro to fill in try part of try/catch exception handler
@@ -158,8 +158,7 @@
 	} else { /* or user-specified initial member */
 	    ta_popP.row(i) = initialpop.row(i);
 	} 
-	arma::rowvec r = ta_popP.row(i);
-	ta_popC[i] = evaluate(l_nfeval, r.memptr(), par, fcall, rho);
+	ta_popC[i] = evaluate(l_nfeval, ta_popP.row(i), par, fcall, rho);
 	if (i == 0 || ta_popC[i] <= t_bestC) {
 	    t_bestC = ta_popC[i];
 	    //for (j = 0; j < i_D; j++)  
@@ -356,7 +355,7 @@
 	    }
 
 	    /*------Trial mutation now in t_tmpP-----------------*/
-	    t_tmpC = evaluate(l_nfeval, t_tmpP.memptr(), par, fcall, rho); 	    // Evaluate mutant in t_tmpP[]
+	    t_tmpC = evaluate(l_nfeval, t_tmpP, par, fcall, rho); 	    // Evaluate mutant in t_tmpP[]
 
 	    /* note that i_bs_flag means that we will choose the
 	     *best NP vectors from the old and new population later*/
@@ -440,7 +439,7 @@
 		}
 	    if(same && i_iter > 1)  {
 		i_xav++;
-		tmp_best = evaluate(l_nfeval, t_bestP.memptr(), par, fcall, rho);			// if re-evaluation of winner 
+		tmp_best = evaluate(l_nfeval, t_bestP, par, fcall, rho);			// if re-evaluation of winner 
 
 		/* possibly letting the winner be the average of all past generations */
 		if(i_av_winner)

Modified: pkg/RcppDE/src/evaluate.cpp
===================================================================
--- pkg/RcppDE/src/evaluate.cpp	2010-10-16 20:26:37 UTC (rev 2314)
+++ pkg/RcppDE/src/evaluate.cpp	2010-10-16 20:44:57 UTC (rev 2315)
@@ -7,12 +7,12 @@
 
 #include <RcppArmadillo.h>
 
-//RcppExport double evaluate(long &l_nfeval, const arma::rowvec & param, SEXP parS, SEXP fcall, SEXP env) {
-RcppExport double evaluate(long &l_nfeval, const double *param, SEXP parS, SEXP fcall, SEXP env) {
+RcppExport double evaluate(long &l_nfeval, const arma::rowvec & param, SEXP parS, SEXP fcall, SEXP env) {
+    //RcppExport double evaluate(long &l_nfeval, const double *param, SEXP parS, SEXP fcall, SEXP env) {
     Rcpp::NumericVector par(parS); 			// access parS as numeric vector to fill it
-    //memcpy(par.begin(), param.memptr(), par.size() * sizeof(double));
+    memcpy(par.begin(), param.memptr(), par.size() * sizeof(double));
     //std::copy(param.begin(), param.end(), par.begin()); // STL way of copying
-    memcpy(par.begin(), param, par.size() * sizeof(double));
+    //memcpy(par.begin(), param, par.size() * sizeof(double));
     SEXP fn = ::Rf_lang2(fcall, par); 			// this could be done with Rcpp 
     SEXP sexp_fvec = ::Rf_eval(fn, env);		// but is still a lot slower right now
     double f_result = Rcpp::as<double>(sexp_fvec);



More information about the Rcpp-commits mailing list