[Rcpp-commits] r429 - in pkg: inst src src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jan 22 17:31:10 CET 2010
Author: romain
Date: 2010-01-22 17:31:10 +0100 (Fri, 22 Jan 2010)
New Revision: 429
Modified:
pkg/inst/ChangeLog
pkg/src/Rcpp/as.h
pkg/src/as.cpp
Log:
more uses of transform
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-01-22 15:32:18 UTC (rev 428)
+++ pkg/inst/ChangeLog 2010-01-22 16:31:10 UTC (rev 429)
@@ -16,9 +16,11 @@
* src/RcppFunction.{h,cpp}: listen to some suncc warnings
* src/RcppFrame.cpp: listen to some suncc warnings
-
- * src/as.cpp: use transform instead of assign
+ * src/as.cpp: use transform instead of assign, which should
+ make the code more portable (particularly suncc) and also
+ deal with coercion
+
2010-01-21 Dirk Eddelbuettel <edd at debian.org>
* DESCRIPTION: Release 0.7.3
Modified: pkg/src/Rcpp/as.h
===================================================================
--- pkg/src/Rcpp/as.h 2010-01-22 15:32:18 UTC (rev 428)
+++ pkg/src/Rcpp/as.h 2010-01-22 16:31:10 UTC (rev 429)
@@ -62,6 +62,26 @@
}
inline int Rbyte_to_int(Rbyte x){ return static_cast<int>(x); }
+inline Rbyte Rboolean_to_Rbyte(int x){ return x == TRUE ? static_cast<Rbyte>(1) : static_cast<Rbyte>(0) ;}
+inline Rbyte double_to_Rbyte(double x){
+ if( x == NA_REAL) return static_cast<Rbyte>(0) ;
+ int y = static_cast<int>(x) ;
+ return (y < 0 || y > 255) ? static_cast<Rbyte>(0) : static_cast<Rbyte>(y) ;
+}
+inline Rbyte int_to_Rbyte(int x){
+ return (x < 0 || x > 255) ? static_cast<Rbyte>(0) : static_cast<Rbyte>(x) ;
+}
+
+inline double Rbyte_to_double(Rbyte x){
+ return static_cast<double>(x) ;
+}
+inline double int_to_double(int x){
+ return x == NA_INTEGER ? NA_REAL : static_cast<double>(x) ;
+}
+inline double Rboolean_to_double(int x){
+ return x == NA_LOGICAL ? NA_REAL : static_cast<double>(x) ;
+}
+
inline int int_to_RBoolean(int x){ return ( x == NA_INTEGER ) ? NA_LOGICAL : (x!=0); }
Modified: pkg/src/as.cpp
===================================================================
--- pkg/src/as.cpp 2010-01-22 15:32:18 UTC (rev 428)
+++ pkg/src/as.cpp 2010-01-22 16:31:10 UTC (rev 429)
@@ -159,16 +159,16 @@
std::vector<Rbyte> v(n);
switch( TYPEOF(m_sexp) ){
case LGLSXP:
- v.assign( LOGICAL(m_sexp), LOGICAL(m_sexp)+n ) ;
+ transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), Rboolean_to_Rbyte ) ;
break ;
case RAWSXP:
v.assign( RAW(m_sexp), RAW(m_sexp)+n ) ;
break ;
case REALSXP:
- v.assign( REAL(m_sexp), REAL(m_sexp)+n) ;
+ transform( REAL(m_sexp), REAL(m_sexp)+n, v.begin(), double_to_Rbyte ) ;
break;
case INTSXP:
- v.assign( INTEGER(m_sexp), INTEGER(m_sexp)+n) ;
+ transform( INTEGER(m_sexp), INTEGER(m_sexp)+n, v.begin(), int_to_Rbyte ) ;
break;
default:
throw std::range_error("as< vector<Rbyte> > expects raw, double or int");
@@ -181,16 +181,16 @@
std::vector<double> v(n);
switch( TYPEOF(m_sexp) ){
case LGLSXP:
- v.assign( LOGICAL(m_sexp), LOGICAL(m_sexp)+n ) ;
+ transform( LOGICAL(m_sexp), LOGICAL(m_sexp)+n, v.begin(), Rboolean_to_double ) ;
break ;
case RAWSXP:
- v.assign( RAW(m_sexp), RAW(m_sexp)+n ) ;
+ transform( RAW(m_sexp), RAW(m_sexp)+n, v.begin(), Rbyte_to_double ) ;
break ;
case REALSXP:
v.assign( REAL(m_sexp), REAL(m_sexp)+n) ;
break;
case INTSXP:
- v.assign( INTEGER(m_sexp), INTEGER(m_sexp)+n) ;
+ transform( INTEGER(m_sexp), INTEGER(m_sexp)+n, v.begin(), int_to_double) ;
break;
default:
throw std::range_error("as< vector<double> >: expects raw, double or int");
More information about the Rcpp-commits
mailing list