[Rcpp-commits] r2684 - pkg/Rcpp/inst/examples/RcppInline
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 3 01:00:25 CET 2010
Author: romain
Date: 2010-12-03 01:00:24 +0100 (Fri, 03 Dec 2010)
New Revision: 2684
Removed:
pkg/Rcpp/inst/examples/RcppInline/RcppSimpleTests.r
Modified:
pkg/Rcpp/inst/examples/RcppInline/RcppInlineExample.r
Log:
cleaning
Modified: pkg/Rcpp/inst/examples/RcppInline/RcppInlineExample.r
===================================================================
--- pkg/Rcpp/inst/examples/RcppInline/RcppInlineExample.r 2010-12-02 23:48:14 UTC (rev 2683)
+++ pkg/Rcpp/inst/examples/RcppInline/RcppInlineExample.r 2010-12-03 00:00:24 UTC (rev 2684)
@@ -4,38 +4,21 @@
suppressMessages(library(inline))
foo <- '
- SEXP rl = R_NilValue; // Use this when there is nothing to be returned.
- char* exceptionMesg = NULL; // msg var in case of error
-
- try {
- RcppVector<int> vec(v); // vec parameter viewed as vector of ints.
- int n = vec.size(), i = 0;
- if (n != 10000) throw std::length_error("Wrong vector size");
+ IntegerVector vec(10000); // vec parameter viewed as vector of ints.
+ int i = 0;
for (int a = 0; a < 9; a++)
for (int b = 0; b < 9; b++)
for (int c = 0; c < 9; c++)
for (int d = 0; d < 9; d++)
vec(i++) = a*b - c*d;
- RcppResultSet rs; // Build result set to be returned as a list to R.
- rs.add("vec", vec); // vec as named element with name "vec"
- rl = rs.getReturnList(); // Get the list to be returned to R.
- } catch(std::exception& ex) {
- exceptionMesg = copyMessageToR(ex.what());
- } catch(...) {
- exceptionMesg = copyMessageToR("unknown reason");
- }
-
- if (exceptionMesg != NULL) Rf_error(exceptionMesg);
-
- return rl;
+ return vec;
'
-funx <- cxxfunction(signature(v="numeric"), foo, plugin = "Rcpp" )
+funx <- cxxfunction(signature(n="integer"), foo, plugin = "Rcpp" )
dd.inline.rcpp <- function() {
- x <- integer(10000)
- res <- funx(v=x)[[1]]
+ res <- funx()
tabulate(res)
}
Deleted: pkg/Rcpp/inst/examples/RcppInline/RcppSimpleTests.r
===================================================================
--- pkg/Rcpp/inst/examples/RcppInline/RcppSimpleTests.r 2010-12-02 23:48:14 UTC (rev 2683)
+++ pkg/Rcpp/inst/examples/RcppInline/RcppSimpleTests.r 2010-12-03 00:00:24 UTC (rev 2684)
@@ -1,54 +0,0 @@
-#!/usr/bin/r
-
-suppressMessages(library(Rcpp))
-suppressMessages(library(inline))
-
-
-foo <- '
- RcppStringVectorView v(x);
- Rprintf( "RcppStringVectorView: size = %d\\n", v.size() ) ;
- Rprintf( "RcppStringVectorView: elem 1 = %s\\n", v(1) ) ;
- return R_NilValue ;
- '
-funx <- cfunction(signature(x="character"), foo, Rcpp=TRUE, verbose=FALSE)
-funx(x=c("Bling", "Blang"))
-
-
-foo <- '
- RcppVectorView<int> v(x);
- Rprintf( "RcppVectorView: n = %d \\n", v.size()) ;
- Rprintf( "RcppVectorView: elem 1 = %d \\n", v(1)) ;
- '
-funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
-x <- 1:9
-funx(x=x)
-
-
-foo <- '
- RcppVector<int> v(x);
- Rprintf( "RcppVector: n = %d \\n", v.size()) ;
- Rprintf( "RcppVector: elem 1 = %d \\n", v(1)) ;
- '
-funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
-x <- 1:9
-funx(x=x)
-
-
-foo <- '
- RcppMatrixView<int> v(x);
- Rprintf( "RcppMatrixView: n = %d times k= %d\\n", v.rows(), v.cols() ) ;
- Rprintf( "RcppMatrixView: elem(1,2) = %d\\n", v(1,2) ) ;
- '
-funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
-x <- matrix(1:9, ncol=3)
-funx(x=x)
-
-foo <- '
- RcppMatrix<int> v(x);
- Rprintf( "RcppMatrix: n = %d times k= %d\\n", v.rows(), v.cols() ) ;
- Rprintf( "RcppMatrix: elem(1,2) = %d\\n", v(1,2) ) ;
- '
-funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
-x <- matrix(1:9, ncol=3)
-funx(x=x)
-
More information about the Rcpp-commits
mailing list