[Rcpp-commits] r1985 - 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:12:11 CEST 2010


Author: romain
Date: 2010-08-12 07:12:10 +0200 (Thu, 12 Aug 2010)
New Revision: 1985

Added:
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarBlock.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
Log:
evebn more flexible SugarMath meta code (the function pointer type passed as a template parameter)

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarBlock.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarBlock.h	2010-08-12 04:51:09 UTC (rev 1984)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarBlock.h	2010-08-12 05:12:10 UTC (rev 1985)
@@ -41,24 +41,6 @@
 	const T1& vec ;
 };
 
-template <bool NA, typename OUT, typename U1, typename T1>
-class SugarMath_1 : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarMath_1<NA,OUT,U1,T1> > {
-public:
-	typedef OUT (*FunPtr)(U1) ;
-	SugarMath_1( FunPtr ptr_, const T1 & vec_) : ptr(ptr_), vec(vec_){}
-	
-	inline OUT operator[]( int i) const { 
-		double x = vec[i] ;
-		if( ISNAN(x) ) return x;
-		return ptr( x ) ;
-	}
-	inline int size() const { return vec.size() ; }
-	
-private:
-	FunPtr ptr ;
-	const T1& vec ;
-};
-
 template <bool NA, typename OUT, typename U1, typename T1, typename U2, typename T2>
 class SugarBlock_2 : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarBlock_2<NA,OUT,U1,T1,U2,T2> > {
 public:
@@ -117,8 +99,8 @@
 };
 
 
-}
-}
+} // sugar
+} // Rcpp
 
 #define SUGAR_BLOCK_1(__NAME__,__SYMBOL__) \
 	namespace Rcpp{                                                 \
@@ -133,20 +115,6 @@
 	}                                                               \
 	}
 
-#define SUGAR_MATH_1(__NAME__,__SYMBOL__) \
-	namespace Rcpp{                                                 \
-	template <bool NA, typename T>                                  \
-	inline sugar::SugarMath_1<NA,double,double,T>                  \
-	__NAME__(                                                       \
-		const VectorBase<REALSXP,NA,T>& t                           \
-	){                                                              \
-		return sugar::SugarMath_1<NA,double,double,T>(             \
-			__SYMBOL__ , t                                          \
-		) ;                                                         \
-	}                                                               \
-	}
-
-
 #define SUGAR_BLOCK_2(__NAME__,__SYMBOL__)                                          \
 	namespace Rcpp{                                                                  \
 	template <bool LHS_NA, typename LHS_T, bool RHS_NA, typename RHS_T >             \
@@ -181,8 +149,5 @@
 	}                                                                                 \
 	}
 	
-	
-	
 
-
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/SugarMath.h	2010-08-12 05:12:10 UTC (rev 1985)
@@ -0,0 +1,63 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// SugarBlock.h: Rcpp R/C++ interface class library -- sugar functions
+//
+// Copyright (C) 2010 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/>.
+
+#ifndef RCPP_SUGAR_SUGARMATH_H
+#define RCPP_SUGAR_SUGARMATH_H
+
+namespace Rcpp{
+namespace sugar{
+	
+template <bool NA, typename OUT, typename U1, typename T1, typename FunPtr>
+class SugarMath_1 : public Rcpp::VectorBase< Rcpp::traits::r_sexptype_traits<OUT>::rtype , NA, SugarMath_1<NA,OUT,U1,T1,FunPtr> > {
+public:
+	SugarMath_1( FunPtr ptr_, const T1 & vec_) : ptr(ptr_), vec(vec_){}
+	
+	inline OUT operator[]( int i) const { 
+		U1 x = vec[i] ;
+		if( ISNAN(x) ) return x;
+		return ptr( x ) ;
+	}
+	inline int size() const { return vec.size() ; }
+	
+private:
+	FunPtr ptr ;
+	const T1& vec ;
+};
+
+} // sugar
+} // Rcpp
+
+#define SUGAR_MATH_1(__NAME__,__SYMBOL__)                                    \
+	namespace Rcpp{                                                          \
+	template <bool NA, typename T>                                           \
+	inline sugar::SugarMath_1<NA,double,double,T, double (*)(double) >       \
+	__NAME__(                                                                \
+		const VectorBase<REALSXP,NA,T>& t                                    \
+	){                                                                       \
+		return sugar::SugarMath_1<NA,double,double,T, double (*)(double)>(   \
+			__SYMBOL__ , t                                                   \
+		) ;                                                                  \
+	}                                                                        \
+	}
+
+	
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2010-08-12 04:51:09 UTC (rev 1984)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h	2010-08-12 05:12:10 UTC (rev 1985)
@@ -26,6 +26,7 @@
 #include <cmath>
 
 #include <Rcpp/sugar/functions/SugarBlock.h>
+#include <Rcpp/sugar/functions/SugarMath.h>
 #include <Rcpp/sugar/functions/math.h>
 
 #include <Rcpp/sugar/functions/any.h>



More information about the Rcpp-commits mailing list