[Earthmovdist-commits] r27 - pkg/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 14 19:07:13 CEST 2010
Author: edd
Date: 2010-10-14 19:07:13 +0200 (Thu, 14 Oct 2010)
New Revision: 27
Modified:
pkg/src/emdL1_R.cpp
Log:
converted to new Rcpp API
Modified: pkg/src/emdL1_R.cpp
===================================================================
--- pkg/src/emdL1_R.cpp 2010-10-14 16:53:01 UTC (rev 26)
+++ pkg/src/emdL1_R.cpp 2010-10-14 17:07:13 UTC (rev 27)
@@ -2,75 +2,59 @@
// emdL1_R.cc:
-#include "Rcpp.h"
+#include <Rcpp.h>
#include "emdL1.h"
RcppExport SEXP emdL1(SEXP H1, SEXP H2, SEXP parms) {
- SEXP rl=R_NilValue;
- char* exceptionMesg=NULL;
-
try {
- RcppVector<double> h1(H1); // double vector based on H1
- RcppVector<double> h2(H2); // double vector based on H2
- RcppParams rparam(parms); // parameter from R based on parms
- bool verbose = rparam.getBoolValue("verbose");
- RcppResultSet rs;
+ Rcpp::NumericVector h1(H1); // double vector based on H1
+ Rcpp::NumericVector h2(H2); // double vector based on H2
+ Rcpp::List rparam(parms); // parameter from R based on parms
+ bool verbose = Rcpp::as<bool>(rparam["verbose"]);
EmdL1 em;
double d = -1;
- switch( rparam.getIntValue("noDims") )
- {
+ switch( Rcpp::as<int>(rparam["noDims"]) ) {
case 1:
- d = em.EmdDist(
- h1.cVector(),
- h2.cVector(),
- rparam.getIntValue("dim1")
- );
- rs.add("dist", d);
+ d = em.EmdDist(h1.begin(),
+ h2.begin(),
+ Rcpp::as<int>(rparam["dim1"]));
if (verbose)
Rprintf("1D - EmdL1(h1,h2)=%lf\n", d);
break;
case 2 :
- d = em.EmdDist(
- h1.cVector(),
- h2.cVector(),
- rparam.getIntValue("dim1"),
- rparam.getIntValue("dim2")
- );
- rs.add("dist", d);
+ d = em.EmdDist(h1.begin(),
+ h2.begin(),
+ Rcpp::as<int>(rparam["dim1"]),
+ Rcpp::as<int>(rparam["dim2"]));
if (verbose)
Rprintf("2D - EmdL1(h1,h2)=%lf\n", d);
break;
case 3 :
- d = em.EmdDist(
- h1.cVector(),
- h2.cVector(),
- rparam.getIntValue("dim1"),
- rparam.getIntValue("dim2"),
- rparam.getIntValue("dim3")
- );
- rs.add("dist", d);
+ d = em.EmdDist(h1.begin(),
+ h2.begin(),
+ Rcpp::as<int>(rparam["dim1"]),
+ Rcpp::as<int>(rparam["dim2"]),
+ Rcpp::as<int>(rparam["dim3"]));
if (verbose)
Rprintf("3D - EmdL1(h1,h2)=%lf\n", d);
break;
- }
+ }
+ //return Rcpp::NumericVector::create(Rcpp::Named("dist", Rcpp::wrap(d)));
+ return Rcpp::wrap(d);
- rl = rs.getReturnList();
-
- } catch(std::exception& ex) {
- exceptionMesg = copyMessageToR(ex.what());
- } catch(...) {
- exceptionMesg = copyMessageToR("unknown reason");
+ } catch(std::exception &ex) {
+ forward_exception_to_r(ex);
+ } catch(...) {
+ ::Rf_error("c++ exception (unknown reason)");
}
+
+ return R_NilValue;
- if (exceptionMesg != NULL)
- Rf_error(exceptionMesg);
-
- return rl;
}
More information about the Earthmovdist-commits
mailing list