[Rcpp-commits] r2158 - in pkg/Rcpp/inst: . examples/ConvolveBenchmarks include/Rcpp/sugar
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Sep 24 11:46:13 CEST 2010
Author: romain
Date: 2010-09-24 11:46:12 +0200 (Fri, 24 Sep 2010)
New Revision: 2158
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve5_cpp.cpp
pkg/Rcpp/inst/include/Rcpp/sugar/Range.h
Log:
added some operators (++,--, etc ...) to Range, simplify the sugar convolve example
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-09-24 09:31:28 UTC (rev 2157)
+++ pkg/Rcpp/inst/ChangeLog 2010-09-24 09:46:12 UTC (rev 2158)
@@ -1,5 +1,12 @@
2010-09-22 Romain Francois <romain at r-enthusiasts.com>
+ * inst/include/Rcpp/sugar/Range.h : Range gains some operators (++,--,n etc ...)
+
+ * inst/examples/ConvolveBenchmarks/convolve3_cpp.cpp: uisng the new Range
+ operators
+
+2010-09-22 Romain Francois <romain at r-enthusiasts.com>
+
* R/Module.R: set [[ and [[<- as regular methods too, which restores previous
behavior
Modified: pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve5_cpp.cpp
===================================================================
--- pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve5_cpp.cpp 2010-09-24 09:31:28 UTC (rev 2157)
+++ pkg/Rcpp/inst/examples/ConvolveBenchmarks/convolve5_cpp.cpp 2010-09-24 09:46:12 UTC (rev 2158)
@@ -11,8 +11,9 @@
NumericVector xb(b); int n_xb = xb.size() ;
NumericVector xab(n_xa + n_xb - 1,0.0);
- for(int i=0; i<n_xa; i++){
- xab[ Range(i, i+n_xb-1) ] += xa[i] * xb ;
+ Range r( 0, n_xb-1 );
+ for(int i=0; i<n_xa; i++, r++){
+ xab[ r ] += xa[i] * xb ;
}
return xab ;
}
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/Range.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/Range.h 2010-09-24 09:31:28 UTC (rev 2157)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/Range.h 2010-09-24 09:46:12 UTC (rev 2158)
@@ -40,6 +40,42 @@
return start + i ;
}
+ Range& operator++() {
+ start++ ; end_++ ;
+ return *this ;
+ }
+ Range& operator++(int) {
+ start++ ; end_++ ;
+ return *this ;
+ }
+
+ Range& operator--() {
+ start-- ; end_-- ;
+ return *this ;
+ }
+ Range& operator--(int) {
+ start-- ; end_-- ;
+ return *this ;
+ }
+
+ Range& operator+=(int n) {
+ start += n ; end_ += n ;
+ return *this ;
+ }
+
+ Range& operator-=(int n) {
+ start -= n ; end_ -= n ;
+ return *this ;
+ }
+
+ Range operator+( int n ){
+ return Range( start + n, end_ + n ) ;
+ }
+ Range operator-( int n ){
+ return Range( start - n, end_ - n ) ;
+ }
+
+
private:
int start ;
int end_ ;
More information about the Rcpp-commits
mailing list