[Rcpp-commits] r1799 - in pkg/Rcpp/inst: . include/Rcpp/sugar/functions unitTests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 7 11:28:09 CEST 2010
Author: romain
Date: 2010-07-07 11:28:09 +0200 (Wed, 07 Jul 2010)
New Revision: 1799
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/include/Rcpp/sugar/functions/rep.h
pkg/Rcpp/inst/unitTests/runit.sugar.R
Log:
version of rep that takes a primitive as first argument
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-07-07 09:12:37 UTC (rev 1798)
+++ pkg/Rcpp/inst/ChangeLog 2010-07-07 09:28:09 UTC (rev 1799)
@@ -1,3 +1,8 @@
+2010-07-07 Romain Francois <romain at r-enthusiasts.com>
+
+ * inst/include/Rcpp/sugar/functions/rep.h: version of rep that takes a
+ primitive as the first argument
+
2010-07-06 Dirk Eddelbuettel <edd at debian.org>
* src/Date.cpp: Imported mktime() from R (which is due to Arthur Olson)
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/rep.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/rep.h 2010-07-07 09:12:37 UTC (rev 1798)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/rep.h 2010-07-07 09:28:09 UTC (rev 1799)
@@ -43,7 +43,26 @@
const VEC_TYPE& object ;
int times, n ;
} ;
+
+template <typename T>
+class Rep_Single : public Rcpp::VectorBase<
+ Rcpp::traits::r_sexptype_traits<T>::rtype,
+ true,
+ Rep_Single<T>
+> {
+public:
+ Rep_Single( const T& x_, int n_) : x(x_), n(n_){}
+ inline T operator[]( int i ) const {
+ return x;
+ }
+ inline int size() const { return n ; }
+
+private:
+ const T& x ;
+ int n ;
+} ;
+
} // sugar
template <int RTYPE, bool NA, typename T>
@@ -51,6 +70,21 @@
return sugar::Rep<RTYPE,NA,T>( t, n ) ;
}
+inline sugar::Rep_Single<double> rep( const double& x, int n ){
+ return sugar::Rep_Single<double>( x, n ) ;
+}
+inline sugar::Rep_Single<int> rep( const int& x, int n ){
+ return sugar::Rep_Single<int>( x, n ) ;
+}
+inline sugar::Rep_Single<Rbyte> rep( const Rbyte& x, int n ){
+ return sugar::Rep_Single<Rbyte>( x, n ) ;
+}
+inline sugar::Rep_Single<Rcomplex> rep( const Rcomplex& x, int n ){
+ return sugar::Rep_Single<Rcomplex>( x, n ) ;
+}
+inline sugar::Rep_Single<bool> rep( const bool& x, int n ){
+ return sugar::Rep_Single<bool>( x, n ) ;
+}
} // Rcpp
#endif
Modified: pkg/Rcpp/inst/unitTests/runit.sugar.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.sugar.R 2010-07-07 09:12:37 UTC (rev 1798)
+++ pkg/Rcpp/inst/unitTests/runit.sugar.R 2010-07-07 09:28:09 UTC (rev 1799)
@@ -487,7 +487,8 @@
List res = List::create(
_["rep"] = rep( xx, 3 ),
_["rep_each"] = rep_each( xx, 3 ),
- _["rep_len"] = rep_len( xx, 12 )
+ _["rep_len"] = rep_len( xx, 12 ),
+ _["rep_prim_double"] = rep( 0.0, 10 )
) ;
return res ;
'
@@ -954,14 +955,14 @@
list(
"rep" = rep( 1:10, 3 ),
"rep_each" = rep( 1:10, each = 3 ),
- "rep_len" = rep( 1:10, length.out = 12 )
+ "rep_len" = rep( 1:10, length.out = 12 ),
+ "rep_prim_double" = rep( 0.0, 10 )
)
)
}
test.sugar.rev <- function(){
fx <- .rcpp.sugar$runit_rev
- print( fx( 1:10 ) )
checkEquals( fx(1:10), rev( 1:10 * 1:10 ) )
}
More information about the Rcpp-commits
mailing list