[Rcpp-commits] r1578 - in pkg/Rcpp: . inst/include/Rcpp/sugar inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 17 20:55:03 CEST 2010


Author: romain
Date: 2010-06-17 20:55:03 +0200 (Thu, 17 Jun 2010)
New Revision: 1578

Modified:
   pkg/Rcpp/TODO
   pkg/Rcpp/inst/include/Rcpp/sugar/seq_along.h
   pkg/Rcpp/inst/unitTests/runit.sugar.seqalong.R
Log:
rework seq_along and added seq_len

Modified: pkg/Rcpp/TODO
===================================================================
--- pkg/Rcpp/TODO	2010-06-17 18:46:25 UTC (rev 1577)
+++ pkg/Rcpp/TODO	2010-06-17 18:55:03 UTC (rev 1578)
@@ -41,7 +41,7 @@
 		
 Syntactic sugar
 
-    o   duplicated, unique, count, sum, seq_len, rep
+    o   duplicated, unique, count, sum, rep
     
     o	for matrices: row, col, lower_tri, upper_tri
 	

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/seq_along.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/seq_along.h	2010-06-17 18:46:25 UTC (rev 1577)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/seq_along.h	2010-06-17 18:55:03 UTC (rev 1578)
@@ -25,10 +25,9 @@
 namespace Rcpp{
 namespace sugar{
 
-template <typename T>
-class SeqAlong : public VectorBase< INTSXP,false,SeqAlong<T> > {
+class SeqLen : public VectorBase< INTSXP,false,SeqLen > {
 public:
-	SeqAlong( int len_ ) : len(len_){}
+	SeqLen( int len_ ) : len(len_){}
 	
 	inline int operator[]( int i ) const {
 		return 1 + i ;
@@ -36,16 +35,22 @@
 	inline int size() const { return len ; }
 	         
 private:
-	const int len ;
+	int len ;
 } ;
 	
 } // sugar
 
 template <int RTYPE, bool _NA_, typename T>
-inline sugar::SeqAlong<T> seq_along( const Rcpp::VectorBase<RTYPE,_NA_,T>& t){
-	return sugar::SeqAlong<T>( t.size() ) ;
+inline sugar::SeqLen seq_along( const Rcpp::VectorBase<RTYPE,_NA_,T>& t){
+	return sugar::SeqLen( t.size() ) ;
 }
 
+inline sugar::SeqLen seq_len( const size_t& n){
+	return sugar::SeqLen( n ) ;
+}
+
+
+
 } // Rcpp
 #endif
 

Modified: pkg/Rcpp/inst/unitTests/runit.sugar.seqalong.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.sugar.seqalong.R	2010-06-17 18:46:25 UTC (rev 1577)
+++ pkg/Rcpp/inst/unitTests/runit.sugar.seqalong.R	2010-06-17 18:55:03 UTC (rev 1578)
@@ -32,3 +32,14 @@
 	checkEquals( fx( rnorm(10)) , 1:10  )
 }
 
+test.sugar.seqlen <- function( ){
+
+	fx <- cxxfunction( signature( ), '
+		IntegerVector res = seq_len( 10 );
+		return res ;
+	', plugin = "Rcpp" )
+	
+	
+	checkEquals( fx() , 1:10  )
+}
+



More information about the Rcpp-commits mailing list