[Rcpp-commits] r2379 - pkg/RcppDE/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 31 23:52:36 CET 2010
Author: edd
Date: 2010-10-31 23:52:36 +0100 (Sun, 31 Oct 2010)
New Revision: 2379
Added:
pkg/RcppDE/src/evaluateMP.cpp
Log:
add an evaluate version that does not need R, implementing Genrose in C++ alone
Added: pkg/RcppDE/src/evaluateMP.cpp
===================================================================
--- pkg/RcppDE/src/evaluateMP.cpp (rev 0)
+++ pkg/RcppDE/src/evaluateMP.cpp 2010-10-31 22:52:36 UTC (rev 2379)
@@ -0,0 +1,25 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Port of DEoptim (2.0.7) by Ardia et al to Rcpp/RcppArmadillo/Armadillo
+// Copyright (C) 2010 Dirk Eddelbuettel <edd at debian.org>
+//
+// DEoptim is Copyright (C) 2009 David Ardia and Katharine Mullen
+
+#ifdef USE_OPENMP
+#include <RcppArmadillo.h>
+
+// Slighly accelerated version of evaluate to evaluate function fcall with parameters param in environment env
+// Uses externally allocated par() vector into which param are copied
+double evaluate(long &l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env) {
+ memcpy(REAL(par), param, Rf_nrows(par) * sizeof(double)); // -- faster: direct access _assuming_ numeric vector
+ Rcpp::NumericVector x(par);
+ int n = x.size();
+ double sum = 1.0;
+ for (int i=1; i<n; i++) {
+ sum += 100*( pow(x[i-1]*x[i-1] - x[i], 2)) + (x[i] - 1)*(x[i] - 1);
+ }
+ l_nfeval++; // increment function evaluation count
+ return(sum);
+}
+#endif
+
Property changes on: pkg/RcppDE/src/evaluateMP.cpp
___________________________________________________________________
Added: svn:executable
+ *
More information about the Rcpp-commits
mailing list