[Rcpp-commits] r1986 - pkg/Rcpp/inst/include/Rcpp/sugar/functions
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 12 07:25:11 CEST 2010
Author: romain
Date: 2010-08-12 07:25:11 +0200 (Thu, 12 Aug 2010)
New Revision: 1986
Modified:
pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h
Log:
SUGAR_MATH_1 handles integer sugar expressions
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h 2010-08-12 05:12:10 UTC (rev 1985)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h 2010-08-12 05:25:11 UTC (rev 1986)
@@ -42,6 +42,39 @@
const T1& vec ;
};
+template <bool NA, typename OUT, typename T1, typename FunPtr>
+class SugarMath_1<NA,OUT,int,T1,FunPtr> : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarMath_1<NA,OUT,int,T1,FunPtr> > {
+public:
+ SugarMath_1( FunPtr ptr_, const T1 & vec_) : ptr(ptr_), vec(vec_){}
+
+ inline OUT operator[]( int i) const {
+ int x = vec[i] ;
+ if( Rcpp::traits::is_na<INTSXP>(x) ) return Rcpp::traits::get_na<REALSXP>( ) ;
+ return ptr( x ) ;
+ }
+ inline int size() const { return vec.size() ; }
+
+private:
+ FunPtr ptr ;
+ const T1& vec ;
+};
+
+template <typename OUT, typename T1, typename FunPtr>
+class SugarMath_1<false,OUT,int,T1,FunPtr> : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , false, SugarMath_1<false,OUT,int,T1,FunPtr> > {
+public:
+ SugarMath_1( FunPtr ptr_, const T1 & vec_) : ptr(ptr_), vec(vec_){}
+
+ inline OUT operator[]( int i) const {
+ return ptr( vec[i] ) ;
+ }
+ inline int size() const { return vec.size() ; }
+
+private:
+ FunPtr ptr ;
+ const T1& vec ;
+};
+
+
} // sugar
} // Rcpp
@@ -56,6 +89,15 @@
__SYMBOL__ , t \
) ; \
} \
+ template <bool NA, typename T> \
+ inline sugar::SugarMath_1<NA,double,int,T, double (*)(double) > \
+ __NAME__( \
+ const VectorBase<INTSXP,NA,T>& t \
+ ){ \
+ return sugar::SugarMath_1<NA,double,int,T, double (*)(double)>( \
+ __SYMBOL__ , t \
+ ) ; \
+ } \
}
More information about the Rcpp-commits
mailing list