[Rcpp-commits] r2159 - pkg/Rcpp/inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Sep 24 11:52:34 CEST 2010
Author: romain
Date: 2010-09-24 11:52:34 +0200 (Fri, 24 Sep 2010)
New Revision: 2159
Modified:
pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h
Log:
using iterators instead of Vector::operator[], resulting in slightly faster sugar version of convolve
Modified: pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h 2010-09-24 09:46:12 UTC (rev 2158)
+++ pkg/Rcpp/inst/include/Rcpp/vector/RangeIndexer.h 2010-09-24 09:52:34 UTC (rev 2159)
@@ -28,17 +28,18 @@
class RangeIndexer {
public:
typedef typename VECTOR::Proxy Proxy ;
+ typedef typename VECTOR::iterator iterator ;
// TODO: check if the indexer is valid
RangeIndexer( VECTOR& vec_, const Rcpp::Range& range_) :
- vec(vec_), range(range_) {}
+ vec(vec_), range(range_), start(vec_.begin()) {}
// TODO: size exceptions
template <bool NA, typename T>
RangeIndexer& operator=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
int n = size() ;
for( int i=0; i<n; i++){
- vec[ range[i] ] = x[i] ;
+ start[ range[i] ] = x[i] ;
}
return *this ;
}
@@ -47,7 +48,7 @@
RangeIndexer& operator+=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
int n = size() ;
for( int i=0; i<n; i++){
- vec[ range[i] ] += x[i] ;
+ start[ range[i] ] += x[i] ;
}
return *this ;
}
@@ -56,7 +57,7 @@
RangeIndexer& operator*=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
int n = size() ;
for( int i=0; i<n; i++){
- vec[ range[i] ] *= x[i] ;
+ start[ range[i] ] *= x[i] ;
}
return *this ;
}
@@ -65,7 +66,7 @@
RangeIndexer& operator-=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
int n = size() ;
for( int i=0; i<n; i++){
- vec[ range[i] ] -= x[i] ;
+ start[ range[i] ] -= x[i] ;
}
return *this ;
}
@@ -74,13 +75,13 @@
RangeIndexer& operator/=( const Rcpp::VectorBase<RTYPE,NA,T>& x){
int n = size() ;
for( int i=0; i<n; i++){
- vec[ range[i] ] /= x[i] ;
+ start[ range[i] ] /= x[i] ;
}
return *this ;
}
inline Proxy operator[]( int i ){
- return vec[ range[i] ] ;
+ return start[ range[i] ] ;
}
inline int size(){
@@ -90,6 +91,7 @@
private:
VECTOR& vec ;
const Rcpp::Range& range ;
+ iterator start ;
} ;
}
More information about the Rcpp-commits
mailing list