[Rcpp-commits] r367 - papers/rjournal pkg pkg/R pkg/inst pkg/src pkg/src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 13 08:42:19 CET 2010
Author: romain
Date: 2010-01-13 08:42:18 +0100 (Wed, 13 Jan 2010)
New Revision: 367
Modified:
papers/rjournal/EddelbuettelFrancois.tex
pkg/DESCRIPTION
pkg/R/zzz.R
pkg/inst/ChangeLog
pkg/src/NumericVector.cpp
pkg/src/Rcpp/Environment.h
pkg/src/Rcpp/NumericVector.h
pkg/src/RcppCommon.cpp
pkg/src/RcppCommon.h
Log:
+Environment::Binding templted conversion operator, NumericVector::operator[] inline
Modified: papers/rjournal/EddelbuettelFrancois.tex
===================================================================
--- papers/rjournal/EddelbuettelFrancois.tex 2010-01-13 03:48:42 UTC (rev 366)
+++ papers/rjournal/EddelbuettelFrancois.tex 2010-01-13 07:42:18 UTC (rev 367)
@@ -3,8 +3,7 @@
\maketitle
-\abstract{
-}
+\abstract{TBD}
\section{Introduction}
@@ -286,7 +285,7 @@
\begin{example}
#include <Rcpp.h>
using namespace Rcpp;
-NumericVector ab = {123.45, 67.89};
+NumericVector ab = \{123.45, 67.89\};
\end{example}
\subsection{character vectors}
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/DESCRIPTION 2010-01-13 07:42:18 UTC (rev 367)
@@ -1,6 +1,6 @@
Package: Rcpp
Title: Rcpp R/C++ interface package
-Version: 0.7.2
+Version: 0.7.2.1
Date: $Date$
Author: Dirk Eddelbuettel and Romain Francois, with contributions
by Simon Urbanek and David Reiss; based on code written during
@@ -9,7 +9,7 @@
Description: R/C++ interface classes and examples
The Rcpp library maps data types betweeen R and C++, and includes support
for R types real, integer, character, vector, matrix, Date, datetime (i.e.
- POSIXct) at microsecond resolution, data frame, and function. Transer to and
+ POSIXct) at microsecond resolution, data frame, and function. Transfer to and
from simple SEXP objects is particular easy. Calling R functions from C++ is
also supported.
.
Modified: pkg/R/zzz.R
===================================================================
--- pkg/R/zzz.R 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/R/zzz.R 2010-01-13 07:42:18 UTC (rev 367)
@@ -15,6 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
-.onAttach <- function(libname, pkgname){
- .Call( "initUncaughtExceptionHandler", PACKAGE = pkgname )
+.onLoad <- function(libname, pkgname){
+ .Call( "initRcpp", PACKAGE = pkgname )
}
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/inst/ChangeLog 2010-01-13 07:42:18 UTC (rev 367)
@@ -1,3 +1,15 @@
+2010-01-13 Romain Francois <francoisromain at free.fr>
+
+ * src/Rcpp/Environment.h: Environment::Binding gains a templated
+ conversion operator, to facilitate distance 2 implicit conversion
+ making this possible:
+ Environment env("package:stats") ;
+ Function f = env["rnorm"] ;
+
+ * src/Rcpp/NumericVector.h: operator[] is promoted to inline
+
+
+
2010-01-12 Dirk Eddelbuettel <edd at debian.org>
* DESCRIPTION: Release 0.7.2
Modified: pkg/src/NumericVector.cpp
===================================================================
--- pkg/src/NumericVector.cpp 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/src/NumericVector.cpp 2010-01-13 07:42:18 UTC (rev 367)
@@ -59,10 +59,6 @@
}
#endif
-double& NumericVector::operator[]( int i ) const throw(index_out_of_bounds){
- if( i<0 || i>=length()) throw index_out_of_bounds() ;
- return REAL(m_sexp)[i] ;
-}
double* NumericVector::begin() const {
return REAL(m_sexp) ;
}
Modified: pkg/src/Rcpp/Environment.h
===================================================================
--- pkg/src/Rcpp/Environment.h 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/src/Rcpp/Environment.h 2010-01-13 07:42:18 UTC (rev 367)
@@ -223,6 +223,14 @@
*/
operator RObject() const ;
+ template <typename T>
+ operator T() const{
+ SEXP x = env.get(name) ;
+ T t(x) ;
+ return t;
+ }
+
+
private:
/**
* Reference to the environment if the binding
Modified: pkg/src/Rcpp/NumericVector.h
===================================================================
--- pkg/src/Rcpp/NumericVector.h 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/src/Rcpp/NumericVector.h 2010-01-13 07:42:18 UTC (rev 367)
@@ -46,14 +46,16 @@
/**
* the length of the vector, uses Rf_length
*/
- inline int length() const { return Rf_length( m_sexp ) ; }
+ inline int length() const { return LENGTH( m_sexp ) ; }
/**
* alias of length
*/
- inline int size() const { return Rf_length( m_sexp ) ; }
+ inline int size() const { return LENGTH( m_sexp ) ; }
- double& operator[]( int i ) const throw(index_out_of_bounds) ;
+ inline double& operator[]( const int& i ) { return REAL(m_sexp)[i]; }
+ inline const double& operator[]( const int& i ) const { return REAL(m_sexp)[i]; }
+
double* begin() const ;
double* end() const ;
Modified: pkg/src/RcppCommon.cpp
===================================================================
--- pkg/src/RcppCommon.cpp 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/src/RcppCommon.cpp 2010-01-13 07:42:18 UTC (rev 367)
@@ -4,6 +4,7 @@
//
// Copyright (C) 2005 - 2006 Dominick Samperi
// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -136,4 +137,54 @@
}
}
+/* garbage collection machinery */
+// static SEXP Rcpp_PreciousList = NULL ;
+SEXP initRcpp(){
+ initUncaughtExceptionHandler() ;
+ // Rcpp_PreciousList = R_NilValue ;
+ // R_PreserveObject(Rcpp_PreciousList) ;
+ return R_NilValue ;
+}
+
+// later
+// static SEXP ReleaseObj(SEXP object, SEXP list) {
+// if (!Rf_isNull(list)) {
+// if (CAR(list) != object) {
+// SEXP c = list;
+// while (!Rf_isNull(CDR(c))) {
+// if (CADR(c) == object) {
+// SETCDR(c, CDDR(c));
+// break;
+// }
+// c = CDR(c);
+// }
+// } else return CDR(list);
+// }
+// return list;
+// }
+//
+//
+// void Rcpp_PreserveObject(SEXP object){
+// Rcpp_PreciousList = Rf_cons(object, Rcpp_PreciousList);
+// // Rprintf( "preserve, stack size: %d\n", stacksize) ;
+// // R_PreserveObject(object);
+// }
+// void Rcpp_ReleaseObject(SEXP object){
+// // Rprintf( "release , stack size: %d\n", stacksize) ;
+// // R_ReleaseObject(object);
+// // if (CAR(Rcpp_PreciousList) == object) {
+// // Rcpp_PreciousList = CDR(Rcpp_PreciousList);
+// // } else {
+// // SEXP c = Rcpp_PreciousList;
+// // while (!Rf_isNull(CDR(c))) {
+// // if (CADR(c) == object) {
+// // SETCDR(c, CDDR(c));
+// // break;
+// // }
+// // c = CDR(c) ;
+// // }
+// // }
+// Rcpp_PreciousList = ReleaseObj( object, Rcpp_PreciousList) ;
+// }
+
Modified: pkg/src/RcppCommon.h
===================================================================
--- pkg/src/RcppCommon.h 2010-01-13 03:48:42 UTC (rev 366)
+++ pkg/src/RcppCommon.h 2010-01-13 07:42:18 UTC (rev 367)
@@ -88,4 +88,8 @@
const char * const sexp_to_name(int sexp_type);
+RcppExport SEXP initRcpp() ;
+void Rcpp_PreserveObject(SEXP object) ;
+void Rcpp_ReleaseObject(SEXP object) ;
+
#endif
More information about the Rcpp-commits
mailing list