[Rcpp-commits] r4392 - in pkg/RcppArmadillo: . inst inst/examples inst/examples/kalman inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 13 02:41:35 CEST 2013


Author: edd
Date: 2013-07-13 02:41:34 +0200 (Sat, 13 Jul 2013)
New Revision: 4392

Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/DESCRIPTION
   pkg/RcppArmadillo/inst/NEWS.Rd
   pkg/RcppArmadillo/inst/examples/fastLm.r
   pkg/RcppArmadillo/inst/examples/kalman/benchmark.R
   pkg/RcppArmadillo/inst/examples/kalman/firstExample.R
   pkg/RcppArmadillo/inst/examples/varSimulation.r
   pkg/RcppArmadillo/inst/unitTests/runTests.R
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
Log:
converted to use Rcpp attributes rather than inline
hence inline removed from Suggests: in DESCRIPTION


Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/ChangeLog	2013-07-13 00:41:34 UTC (rev 4392)
@@ -1,3 +1,14 @@
+2013-07-12  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/unitTests/runTests.R: No longer need to test minimal versions
+	of package 'inline' as unit tests now use Rcpp attributes
+	* inst/unitTests/runit.RcppArmadillo.R: Don't load package 'library'
+
+	* inst/examples/fastLm.r: Also rewritten to use Rcpp attributes
+	* inst/examples/varSimulation.r: Idem
+
+	* DESCRIPTION: Removed Suggests: on inline
+
 2013-06-04  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION: Release 0.3.900.0

Modified: pkg/RcppArmadillo/DESCRIPTION
===================================================================
--- pkg/RcppArmadillo/DESCRIPTION	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/DESCRIPTION	2013-07-13 00:41:34 UTC (rev 4392)
@@ -34,5 +34,5 @@
 LazyLoad: yes
 Depends: R (>= 2.14.0), Rcpp (>= 0.10.2)
 LinkingTo: Rcpp
-Suggests: inline, RUnit
+Suggests: RUnit
 URL: http://arma.sourceforge.net/, http://dirk.eddelbuettel.com/code/rcpp.armadillo.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/RcppArmadillo

Modified: pkg/RcppArmadillo/inst/NEWS.Rd
===================================================================
--- pkg/RcppArmadillo/inst/NEWS.Rd	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/NEWS.Rd	2013-07-13 00:41:34 UTC (rev 4392)
@@ -2,6 +2,12 @@
 \title{News for Package 'RcppArmadillo'}
 \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
 
+\section{Changes in RcppArmadillo version 0.3.abc (2013-xx-yy)}{
+  \itemize{
+    \item The \pkg{inline} package is no longer used in the examples and
+    unit tests which have all been converted to Rcpp attributes use
+}
+
 \section{Changes in RcppArmadillo version 0.3.900 (2013-06-04)}{
   \itemize{
     \item Upgraded to Armadillo release Version 3.900.0 (Bavarian

Modified: pkg/RcppArmadillo/inst/examples/fastLm.r
===================================================================
--- pkg/RcppArmadillo/inst/examples/fastLm.r	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/examples/fastLm.r	2013-07-13 00:41:34 UTC (rev 4392)
@@ -2,7 +2,7 @@
 ##
 ## fastLm.r: Benchmarking lm() via RcppArmadillo and directly
 ##
-## Copyright (C)  2010 - 2012  Dirk Eddelbuettel, Romain Francois and Douglas Bates
+## Copyright (C)  2010 - 2013  Dirk Eddelbuettel, Romain Francois and Douglas Bates
 ##
 ## This file is part of RcppArmadillo.
 ##
@@ -19,12 +19,11 @@
 ## You should have received a copy of the GNU General Public License
 ## along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
 
-library(inline)
+library(RcppArmadillo)
 library(rbenchmark)
 
 src <- '
-    Rcpp::NumericMatrix Xr(Xs);
-    Rcpp::NumericVector yr(ys);
+Rcpp::List fLmTwoCasts(Rcpp::NumericMatrix Xr, Rcpp::NumericVector yr) {
     int n = Xr.nrow(), k = Xr.ncol();
     arma::mat X(Xr.begin(), n, k, false);
     arma::colvec y(yr.begin(), yr.size(), false);
@@ -43,14 +42,12 @@
     return Rcpp::List::create(Rcpp::Named("coefficients")=coef,
                               Rcpp::Named("stderr")      =sderr,
                               Rcpp::Named("df")          =df);
+}
 '
+cppFunction(code=src, depends="RcppArmadillo")
 
-fLmTwoCasts <- cxxfunction(signature(Xs="numeric", ys="numeric"),
-                           src, plugin="RcppArmadillo")
-
 src <- '
-    arma::mat X = Rcpp::as<arma::mat>(Xs);
-    arma::colvec y = Rcpp::as<arma::colvec>(ys);
+Rcpp::List fLmOneCast(arma::mat X, arma::colvec y) {
     int df = X.n_rows - X.n_cols;
 
     // fit model y ~ X, extract residuals
@@ -66,12 +63,11 @@
     return Rcpp::List::create(Rcpp::Named("coefficients")=coef,
                               Rcpp::Named("stderr")      =sderr,
                               Rcpp::Named("df")          =df);
+}
 '
+cppFunction(code=src, depends="RcppArmadillo")
 
-fLmOneCast <- cxxfunction(signature(Xs="numeric", ys="numeric"),
-                          src, plugin="RcppArmadillo")
 
-
 fastLmPureDotCall <- function(X, y) {
     .Call("fastLm", X, y, PACKAGE = "RcppArmadillo")
 }

Modified: pkg/RcppArmadillo/inst/examples/kalman/benchmark.R
===================================================================
--- pkg/RcppArmadillo/inst/examples/kalman/benchmark.R	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/examples/kalman/benchmark.R	2013-07-13 00:41:34 UTC (rev 4392)
@@ -1,5 +1,6 @@
 
-suppressMessages(library(Rcpp))
+suppressMessages(library(utils))
+suppressMessages(library(RcppArmadillo))
 suppressMessages(library(rbenchmark))
 suppressMessages(library(compiler))
 

Modified: pkg/RcppArmadillo/inst/examples/kalman/firstExample.R
===================================================================
--- pkg/RcppArmadillo/inst/examples/kalman/firstExample.R	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/examples/kalman/firstExample.R	2013-07-13 00:41:34 UTC (rev 4392)
@@ -1,12 +1,13 @@
 
-library(inline)
+library(RcppArmadillo)
 
-g <- cxxfunction(signature(vs="numeric"), plugin="RcppArmadillo", body='
-     arma::colvec v = Rcpp::as<arma::colvec>(vs);
+cppFunction(code='
+Rcpp::List g(arma::colvec v) {
      arma::mat op = v * v.t();
      double ip = arma::as_scalar(v.t() * v);
      return Rcpp::List::create(Rcpp::Named("outer")=op,
                                Rcpp::Named("inner")=ip);
-')
+}
+', depends="RcppArmadillo")
 
 g(7:11)

Modified: pkg/RcppArmadillo/inst/examples/varSimulation.r
===================================================================
--- pkg/RcppArmadillo/inst/examples/varSimulation.r	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/examples/varSimulation.r	2013-07-13 00:41:34 UTC (rev 4392)
@@ -3,6 +3,7 @@
 ## varSimulation.r: Simulation of first-order vector autoregression data
 ##
 ## Copyright (C)  2011  Lance Bachmeier and Dirk Eddelbuettel
+## Copyright (C)  2013  Dirk Eddelbuettel
 ##
 ## This file is part of RcppArmadillo.
 ##
@@ -20,18 +21,21 @@
 ## along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
 
 
+## load Rcpp to be able to use cppFunction() below
+suppressMessages(library(Rcpp))
+
+
 ## parameter and error terms used throughout
 a <- matrix(c(0.5,0.1,0.1,0.5),nrow=2)
 e <- matrix(rnorm(10000),ncol=2)
 
-
 ## Let's start with the R version
 rSim <- function(coeff, errors) {
-  simdata <- matrix(0, nrow(errors), ncol(errors))
-  for (row in 2:nrow(errors)) {
-    simdata[row,] = coeff %*% simdata[(row-1),] + errors[row,]
-  }
-  return(simdata)
+    simdata <- matrix(0, nrow(errors), ncol(errors))
+    for (row in 2:nrow(errors)) {
+        simdata[row,] = coeff %*% simdata[(row-1),] + errors[row,]
+    }
+    return(simdata)
 }
 
 rData <- rSim(a, e)                     # generated by R
@@ -46,24 +50,22 @@
 stopifnot(all.equal(rData, compRData))  # checking results
 
 
-## Now load 'inline' to compile C++ code on the fly
-suppressMessages(require(inline))
+## C++ variant: code passed as a text variable ...
 code <- '
-  arma::mat coeff = Rcpp::as<arma::mat>(a);
-  arma::mat errors = Rcpp::as<arma::mat>(e);
-  int m = errors.n_rows; int n = errors.n_cols;
-  arma::mat simdata(m,n);
-  simdata.row(0) = arma::zeros<arma::mat>(1,n);
-  for (int row=1; row<m; row++) {
-    simdata.row(row) = simdata.row(row-1)*trans(coeff)+errors.row(row);
-  }
-  return Rcpp::wrap(simdata);
+arma::mat rcppSim(arma::mat coeff, arma::mat errors) {
+    int m = errors.n_rows;
+    int n = errors.n_cols;
+    arma::mat simdata(m,n);
+    simdata.row(0) = arma::zeros<arma::mat>(1,n);
+    for (int row=1; row<m; row++) {
+        simdata.row(row) = simdata.row(row-1)*trans(coeff)+errors.row(row);
+    }
+    return simdata;
+}
 '
+## ... which is compiled/linked/loaded here to create the compiled function
+cppFunction(code=code, depends="RcppArmadillo")
 
-## create the compiled function
-rcppSim <- cxxfunction(signature(a="numeric",e="numeric"),
-                       code,plugin="RcppArmadillo")
-
 rcppData <- rcppSim(a,e)                # generated by C++ code
 
 stopifnot(all.equal(rData, rcppData))   # checking results

Modified: pkg/RcppArmadillo/inst/unitTests/runTests.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runTests.R	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/unitTests/runTests.R	2013-07-13 00:41:34 UTC (rev 4392)
@@ -1,24 +1,16 @@
 pkg <- "RcppArmadillo"
 
-if( ! require( "inline", character.only = TRUE, quietly = TRUE ) ){
-    stop( "The inline package is required to run RcppArmadillo unit tests" )
-}
+if (require("RUnit", quietly = TRUE)) {
 
-if( compareVersion( packageDescription( "inline" )[["Version"]], "0.3.5" ) < 0 ){
-    stop( "RcppArmadillo unit tests need at least the version 0.3.5 of inline" )
-}
-
-if(require("RUnit", quietly = TRUE)) {
-
     is_local <- function(){
-    	if( exists( "argv", globalenv() ) && "--local" %in% argv ) return(TRUE)
-    	if( "--local" %in% commandArgs(TRUE) ) return(TRUE)
+    	if (exists( "argv", globalenv() ) && "--local" %in% argv) return(TRUE)
+    	if ("--local" %in% commandArgs(TRUE)) return(TRUE)
     	FALSE
     }
-    if( is_local() ) path <- getwd()
+    if (is_local()) path <- getwd()
 
     library(package=pkg, character.only = TRUE)
-    if(!(exists("path") && file.exists(path)))
+    if (!(exists("path") && file.exists(path)))
         path <- system.file("unitTests", package = pkg)
 
     ## --- Testing ---
@@ -27,8 +19,7 @@
     testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs = path)
 
     if(interactive()) {
-        cat("Now have RUnit Test Suite 'testSuite' for package '", pkg,
-            "' :\n", sep='')
+        cat("Now have RUnit Test Suite 'testSuite' for package '", pkg, "' :\n", sep='')
         str(testSuite)
         cat('', "Consider doing",
             "\t  tests <- runTestSuite(testSuite)", "\nand later",
@@ -40,7 +31,7 @@
         output <- NULL
 
         process_args <- function(argv){
-            if( !is.null(argv) && length(argv) > 0 ){
+            if (!is.null(argv) && length(argv) > 0 ){
                 rx <- "^--output=(.*)$"
                 g  <- grep( rx, argv, value = TRUE )
                 if( length(g) ){
@@ -50,23 +41,23 @@
         }
 
         # R CMD check uses this
-        if( exists( "RcppArmadillo.unit.test.output.dir", globalenv() ) ){
-			output <- RcppArmadillo.unit.test.output.dir
-		} else {
+        if (exists("RcppArmadillo.unit.test.output.dir", globalenv())) {
+            output <- RcppArmadillo.unit.test.output.dir
+        } else {
 
-			# give a chance to the user to customize where he/she wants
-        	# the unit tests results to be stored with the --output= command
-        	# line argument
-        	if( exists( "argv",  globalenv() ) ){
-        	    ## littler
-        	    output <- process_args(argv)
-        	} else {
-        	    ## Rscript
-        	    output <- process_args(commandArgs(TRUE))
-        	}
+            ## give a chance to the user to customize where he/she wants
+            ## the unit tests results to be stored with the --output= command
+            ## line argument
+            if (exists( "argv",  globalenv())) {
+                ## littler
+                output <- process_args(argv)
+            } else {
+                ## Rscript
+                output <- process_args(commandArgs(TRUE))
+            }
         }
 
-        if( is.null(output) ) {         # if it did not work, use parent dir
+        if (is.null(output)) {          # if it did not work, use parent dir
             output <- ".."              # as BDR does not want /tmp to be used
         }
 
@@ -87,7 +78,7 @@
         ##  stop() if there are any failures i.e. FALSE to unit test.
         ## This will cause R CMD check to return error and stop
         err <- getErrors(tests)
-        if( (err$nFail + err$nErr) > 0) {
+        if ((err$nFail + err$nErr) > 0) {
             stop( sprintf( "unit test problems: %d failures, %d errors", err$nFail, err$nErr) )
         } else{
             success <- err$nTestFunc - err$nFail - err$nErr - err$nDeactivated
@@ -95,7 +86,6 @@
         }
     }
 } else {
-    cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
-        "for package", pkg,"\n")
+    cat("R package 'RUnit' cannot be loaded -- no unit tests run\n", "for package", pkg,"\n")
 }
 

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-07-11 11:52:42 UTC (rev 4391)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-07-13 00:41:34 UTC (rev 4392)
@@ -1,6 +1,6 @@
 #!/usr/bin/r -t
 #
-# Copyright (C) 2010	Dirk Eddelbuettel, Romain Francois and Douglas Bates
+# Copyright (C) 2010 - 2013  Dirk Eddelbuettel, Romain Francois and Douglas Bates
 #
 # This file is part of RcppArmadillo.
 #
@@ -18,7 +18,7 @@
 # along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
 
 .setUp <- function(){
-    suppressMessages(require(inline))
+    suppressMessages(require(RcppArmadillo))
     sourceCpp(file.path(pathRcppArmadilloTests, "cpp/armadillo.cpp"))
 }
 



More information about the Rcpp-commits mailing list