[Rcpp-commits] r4383 - in pkg/Rcpp: . inst inst/unitTests inst/unitTests/cpp man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 2 16:45:24 CEST 2013
Author: romain
Date: 2013-07-02 16:45:24 +0200 (Tue, 02 Jul 2013)
New Revision: 4383
Added:
pkg/Rcpp/inst/unitTests/cpp/support.cpp
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/NEWS.Rd
pkg/Rcpp/inst/unitTests/runit.Module.R
pkg/Rcpp/inst/unitTests/runit.support.R
pkg/Rcpp/man/sourceCpp.Rd
pkg/Rcpp/src/attributes.cpp
Log:
populate the environment with the module content
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/ChangeLog 2013-07-02 14:45:24 UTC (rev 4383)
@@ -5,6 +5,7 @@
* unitTests/runit.Matrix.R: using sourceCpp
* unitTests/runit.misc.R: using sourceCpp
* unitTests/runit.wrap.R: using sourceCpp
+ * unitTests/runit.support.R: using sourceCpp
* unitTests/runit.Vector.R: testing List( int, IntegerVector ) which
eventually uses fill__dispatch
* include/Rcpp/traits/r_type_traits.h: support for as<T&> and as<const T&>
@@ -12,6 +13,9 @@
* include/Rcpp/as.h: as<T&> and as<const T&> when T is module exposed
* include/Rcpp/module/Module_generated_CppFunction.h: removed the
remove_const_and_reference since as<T&> and as<const T&> is supported
+ * src/attributes.cpp: automatically populating the environment with
+ the content of a module, rather than make the module object available
+ in the environment
2013-07-01 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/inst/NEWS.Rd 2013-07-02 14:45:24 UTC (rev 4383)
@@ -14,6 +14,14 @@
T is a class exposed by modules, i.e. with \code{RCPP_EXPOSED_CLASS}
}
+ \item Changes in Attributes:
+ \itemize{
+ \item Objects exported by a module (i.e. by a \code{RCPP_MODULE} call
+ in a file that is processed by \code{sourceCpp}) are now ditectly
+ available in the environment. We used to make the module object
+ available, which was less useful.
+ }
+
\item Changes in Modules:
\itemize{
\item We can now expose functions and methods that take
Added: pkg/Rcpp/inst/unitTests/cpp/support.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/support.cpp (rev 0)
+++ pkg/Rcpp/inst/unitTests/cpp/support.cpp 2013-07-02 14:45:24 UTC (rev 4383)
@@ -0,0 +1,94 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// support.cpp: Rcpp R/C++ interface class library -- unit tests
+//
+// Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#include <Rcpp.h>
+using namespace Rcpp ;
+
+// [[Rcpp::export]]
+List plus_REALSXP(){
+ return List::create(
+ NA_REAL + NA_REAL,
+ NA_REAL + 1.0,
+ 1.0 + NA_REAL
+ );
+}
+
+// [[Rcpp::export]]
+List times_REALSXP(){
+ return List::create(
+ NA_REAL * NA_REAL,
+ NA_REAL * 1.0,
+ 1.0 * NA_REAL
+ );
+}
+
+// [[Rcpp::export]]
+List divides_REALSXP(){
+ return List::create(
+ NA_REAL / NA_REAL,
+ NA_REAL / 1.0,
+ 1.0 / NA_REAL
+ );
+}
+
+// [[Rcpp::export]]
+List minus_REALSXP(){
+ return List::create(
+ NA_REAL - NA_REAL,
+ NA_REAL - 1.0,
+ 1.0 - NA_REAL
+ );
+}
+
+// [[Rcpp::export]]
+List functions_REALSXP(){
+ return List::create(
+ NumericVector::create(
+ exp( NA_REAL ),
+ acos( NA_REAL ),
+ asin( NA_REAL ),
+ atan( NA_REAL ),
+ ceil( NA_REAL ),
+ cos( NA_REAL ),
+ cosh( NA_REAL ),
+ floor( NA_REAL ),
+ log( NA_REAL ),
+ log10( NA_REAL ),
+ sqrt( NA_REAL),
+ sin( NA_REAL ),
+ sinh( NA_REAL ),
+ tan( NA_REAL ),
+ tanh( NA_REAL ),
+ fabs( NA_REAL ),
+ Rf_gammafn( NA_REAL),
+ Rf_lgammafn( NA_REAL ),
+ Rf_digamma( NA_REAL ),
+ Rf_trigamma( NA_REAL )
+ ) , NumericVector::create(
+ Rf_tetragamma( NA_REAL) ,
+ Rf_pentagamma( NA_REAL) ,
+ expm1( NA_REAL ),
+ log1p( NA_REAL ),
+ Rcpp::internal::factorial( NA_REAL ),
+ Rcpp::internal::lfactorial( NA_REAL )
+ )
+ );
+}
Modified: pkg/Rcpp/inst/unitTests/runit.Module.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Module.R 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/inst/unitTests/runit.Module.R 2013-07-02 14:45:24 UTC (rev 4383)
@@ -22,8 +22,8 @@
gc()
}
-# .runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
-.runThisTest <- FALSE
+.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
+# .runThisTest <- FALSE
if( .runThisTest && Rcpp:::capabilities()[["Rcpp modules"]] ) {
Modified: pkg/Rcpp/inst/unitTests/runit.support.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.support.R 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/inst/unitTests/runit.support.R 2013-07-02 14:45:24 UTC (rev 4383)
@@ -21,128 +21,39 @@
if (.runThisTest) {
-definitions <- function() {
- list(
- "plus_REALSXP"=list(
- signature(),
- '
- return List::create(
- NA_REAL + NA_REAL,
- NA_REAL + 1.0,
- 1.0 + NA_REAL
- );
- '),
- "times_REALSXP" = list(
- signature(),
- '
- return List::create(
- NA_REAL * NA_REAL,
- NA_REAL * 1.0,
- 1.0 * NA_REAL
- );
- '),
- "divides_REALSXP" = list(
- signature(),
- '
- return List::create(
- NA_REAL / NA_REAL,
- NA_REAL / 1.0,
- 1.0 / NA_REAL
- );
- '
- ),
- "minus_REALSXP" = list(
- signature(),
- '
- return List::create(
- NA_REAL - NA_REAL,
- NA_REAL - 1.0,
- 1.0 - NA_REAL
- );
- '
- ),
- "functions_REALSXP" = list(
- signature(),
- '
- return List::create(
- NumericVector::create(
- exp( NA_REAL ),
- acos( NA_REAL ),
- asin( NA_REAL ),
- atan( NA_REAL ),
- ceil( NA_REAL ),
- cos( NA_REAL ),
- cosh( NA_REAL ),
- floor( NA_REAL ),
- log( NA_REAL ),
- log10( NA_REAL ),
- sqrt( NA_REAL),
- sin( NA_REAL ),
- sinh( NA_REAL ),
- tan( NA_REAL ),
- tanh( NA_REAL ),
- fabs( NA_REAL ),
- Rf_gammafn( NA_REAL),
- Rf_lgammafn( NA_REAL ),
- Rf_digamma( NA_REAL ),
- Rf_trigamma( NA_REAL )
- ) , NumericVector::create(
- Rf_tetragamma( NA_REAL) ,
- Rf_pentagamma( NA_REAL) ,
- expm1( NA_REAL ),
- log1p( NA_REAL ),
- Rcpp::internal::factorial( NA_REAL ),
- Rcpp::internal::lfactorial( NA_REAL )
- )
- );
- '
- )
- )
-}
-.setUp <- function() {
- tests <- ".rcpp.support"
- if( ! exists( tests, globalenv() )) {
- fun <- Rcpp:::compile_unit_tests(definitions())
- assign( tests, fun, globalenv() )
- }
-}
+.setUp <- Rcpp:::unit_test_setup( "support.cpp" )
test.plus.REALSXP <- function(){
- fun <- .rcpp.support$plus_REALSXP
checkEquals(
- fun(),
+ plus_REALSXP(),
list(NA_real_,NA_real_,NA_real_) ,
msg = " REALSXP + REALSXP" )
}
test.times.REALSXP <- function(){
- fun <- .rcpp.support$times_REALSXP
checkEquals(
- fun(),
+ times_REALSXP(),
list(NA_real_,NA_real_,NA_real_) ,
msg = " REALSXP * REALSXP" )
}
test.divides.REALSXP <- function(){
- fun <- .rcpp.support$divides_REALSXP
checkEquals(
- fun(),
+ divides_REALSXP(),
list(NA_real_,NA_real_,NA_real_) ,
msg = " REALSXP / REALSXP" )
}
test.minus.REALSXP <- function(){
- fun <- .rcpp.support$minus_REALSXP
checkEquals(
- fun(),
+ minus_REALSXP(),
list(NA_real_,NA_real_,NA_real_) ,
msg = " REALSXP - REALSXP" )
}
test.functions.REALSXP <- function(){
- fun <- .rcpp.support$functions_REALSXP
checkEquals(
- fun(),
+ functions_REALSXP(),
list( rep(NA_real_, 20L), rep(NA_real_, 6L) ) ,
msg = "function(NA_REAL)" )
}
Modified: pkg/Rcpp/man/sourceCpp.Rd
===================================================================
--- pkg/Rcpp/man/sourceCpp.Rd 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/man/sourceCpp.Rd 2013-07-02 14:45:24 UTC (rev 4383)
@@ -12,7 +12,6 @@
rebuild = FALSE, showOutput = verbose,
verbose = getOption("verbose"))
}
-%- maybe also 'usage' for other objects documented here.
\arguments{
\item{file}{
A character string giving the path name of a file
@@ -36,13 +35,24 @@
\details{
If the \code{code} parameter is provided then the \code{file} parameter is ignored.
- Functions exported using \code{sourceCpp} must meet several conditions, including being defined in the global namespace and having return types that are compatible with \code{Rcpp::wrap} and parameter types that are compatible with \code{Rcpp::as}. See the \code{\link[=exportAttribute]{Rcpp::export}} documentation for more details.
+ Functions exported using \code{sourceCpp} must meet several conditions,
+ including being defined in the global namespace and having return types
+ that are compatible with \code{Rcpp::wrap} and parameter types that are
+ compatible with \code{Rcpp::as}.
+ See the \code{\link[=exportAttribute]{Rcpp::export}} documentation for more details.
- Rcpp Modules will be automatically loaded into the specified environment using the \code{\link[=Module]{Module}} function. the name of the loaded module object will be the same as the name specified in the \code{RCPP_MODULE} declaration.
+ Content of Rcpp Modules will be automatically loaded into the specified
+ environment using the \code{\link[=Module]{Module}} and
+ \code{\link[=populate]{populate}} functions.
- If the source file has compilation dependencies on other packages (e.g. \pkg{Matrix}, \pkg{RcppArmadillo}) then an \code{\link[=dependsAttribute]{Rcpp::depends}} attribute should be provided naming these dependencies.
+ If the source file has compilation dependencies on other
+ packages (e.g. \pkg{Matrix}, \pkg{RcppArmadillo}) then an
+ \code{\link[=dependsAttribute]{Rcpp::depends}} attribute
+ should be provided naming these dependencies.
- It's possible to embed chunks of R code within a C++ source file by including the R code within a block comment with the prefix of \code{/*** R}. For example:
+ It's possible to embed chunks of R code within a C++ source file by
+ including the R code within a block comment with the
+ prefix of \code{/*** R}. For example:
\preformatted{
/*** R
Modified: pkg/Rcpp/src/attributes.cpp
===================================================================
--- pkg/Rcpp/src/attributes.cpp 2013-07-02 10:56:34 UTC (rev 4382)
+++ pkg/Rcpp/src/attributes.cpp 2013-07-02 14:45:24 UTC (rev 4383)
@@ -2550,8 +2550,8 @@
for (std::vector<std::string>::const_iterator
it = modules.begin(); it != modules.end(); ++it)
{
- ostr << *it << " <- Rcpp::Module(\"" << *it << "\","
- << dllInfo << ")" << std::endl;
+ ostr << " populate( Rcpp::Module(\"" << *it << "\","
+ << dllInfo << "), environment() ) " << std::endl;
}
}
More information about the Rcpp-commits
mailing list