Skip to content

Commit 8d3880f

Browse files
author
Qiang Kou
committed
using R_xlen_t as index type in sugar functions
1 parent 70ad472 commit 8d3880f

40 files changed

+190
-191
lines changed

inst/include/Rcpp/internal/Proxy_Iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Proxy_Iterator {
112112

113113
inline int index() const { return proxy.index ; }
114114

115-
inline PROXY operator[](int i){ return PROXY(*proxy.parent, proxy.index + i) ; }
115+
inline PROXY operator[](R_xlen_t i){ return PROXY(*proxy.parent, proxy.index + i) ; }
116116

117117
private:
118118
PROXY proxy ;

inst/include/Rcpp/sugar/functions/all.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class All : public SingleLogicalResult< true, All<NA,T> >{
3333
All( const VEC_TYPE& t ) : PARENT() , object(t) {}
3434

3535
void apply(){
36-
int n = object.size() ;
36+
R_xlen_t n = object.size() ;
3737
int current = 0 ;
3838
PARENT::reset() ;
39-
for( int i=0 ; i<n ; i++){
39+
for( R_xlen_t i=0 ; i<n ; i++){
4040
current = object[i] ;
4141
if( current == FALSE ) {
4242
PARENT::set_false() ;
@@ -64,9 +64,9 @@ class All<false,T> : public SingleLogicalResult< false, All<false,T> >{
6464
All( const VEC_TYPE& t ) : PARENT() , object(t) {}
6565

6666
void apply(){
67-
int n = object.size() ;
67+
R_xlen_t n = object.size() ;
6868
PARENT::set_true() ;
69-
for( int i=0 ; i<n ; i++){
69+
for( R_xlen_t i=0 ; i<n ; i++){
7070
if( object[i] == FALSE ) {
7171
PARENT::set_false() ;
7272
return ;

inst/include/Rcpp/sugar/functions/any.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Any : public SingleLogicalResult< true, Any<NA,T> >{
3333
Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
3434

3535
void apply(){
36-
int n = object.size() ;
36+
R_xlen_t n = object.size() ;
3737
int current = 0 ;
3838
PARENT::reset() ;
39-
for( int i=0 ; i<n ; i++){
39+
for( R_xlen_t i=0 ; i<n ; i++){
4040
current = object[i] ;
4141
if( current == TRUE ) {
4242
PARENT::set_true() ;
@@ -62,9 +62,9 @@ class Any<false,T> : public SingleLogicalResult< false, Any<false,T> >{
6262
Any( const VEC_TYPE& t ) : PARENT() , object(t) {}
6363

6464
void apply(){
65-
int n = object.size() ;
65+
R_xlen_t n = object.size() ;
6666
PARENT::set_false() ;
67-
for( int i=0 ; i<n ; i++){
67+
for( R_xlen_t i=0 ; i<n ; i++){
6868
if( object[i] == TRUE ) {
6969
PARENT::set_true() ;
7070
return ;

inst/include/Rcpp/sugar/functions/clamp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class Clamp_Primitive_Vector_Primitive : public VectorBase<
6565

6666
Clamp_Primitive_Vector_Primitive( STORAGE lhs_, const T& vec_, STORAGE rhs_) : vec(vec_), op(lhs_,rhs_) {}
6767

68-
inline STORAGE operator[]( int i ) const {
68+
inline STORAGE operator[]( R_xlen_t i ) const {
6969
return op( vec[i] ) ;
7070
}
71-
inline int size() const { return vec.size() ; }
71+
inline R_xlen_t size() const { return vec.size() ; }
7272

7373
private:
7474
const T& vec ;

inst/include/Rcpp/sugar/functions/complex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class SugarComplex : public Rcpp::VectorBase<
4444

4545
SugarComplex( FunPtr ptr_, const VEC_TYPE & vec_) : ptr(ptr_), vec(vec_){}
4646

47-
inline RESULT_TYPE operator[]( int i) const {
47+
inline RESULT_TYPE operator[]( R_xlen_t i) const {
4848
Rcomplex x = vec[i] ;
4949
if( Rcpp::traits::is_na<CPLXSXP>( x ) )
5050
return Rcpp::traits::get_na< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype >() ;
5151
return ptr( x );
5252
}
53-
inline int size() const { return vec.size() ; }
53+
inline R_xlen_t size() const { return vec.size() ; }
5454

5555
private:
5656
FunPtr ptr ;

inst/include/Rcpp/sugar/functions/cumsum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class Cumsum : public Lazy< Rcpp::Vector<RTYPE> , Cumsum<RTYPE,NA,T> > {
3535
Cumsum( const VEC_TYPE& object_ ) : object(object_){}
3636

3737
VECTOR get() const {
38-
int n = object.size() ;
38+
R_xlen_t n = object.size() ;
3939
VECTOR result( n, Rcpp::traits::get_na<RTYPE>() ) ;
4040
STORAGE current = object[0] ;
4141
if( Rcpp::traits::is_na<RTYPE>(current) )
4242
return result ;
4343
result[0] = current ;
44-
for( int i=1; i<n; i++){
44+
for( R_xlen_t i=1; i<n; i++){
4545
current = object[i] ;
4646
if( Rcpp::traits::is_na<RTYPE>(current) )
4747
return result ;

inst/include/Rcpp/sugar/functions/diff.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Diff : public Rcpp::VectorBase< RTYPE, LHS_NA , Diff<RTYPE,LHS_NA,LHS_T> >
4141
was_na(traits::is_na<RTYPE>(previous))
4242
{}
4343

44-
inline STORAGE operator[]( int i ) const {
44+
inline STORAGE operator[]( R_xlen_t i ) const {
4545
STORAGE y = lhs[i+1] ;
4646
if( previous_index != i ){
4747
// we don't know the previous value, we need to get it.
@@ -56,18 +56,18 @@ class Diff : public Rcpp::VectorBase< RTYPE, LHS_NA , Diff<RTYPE,LHS_NA,LHS_T> >
5656
return res ;
5757
}
5858

59-
inline void set_previous(int i, STORAGE value) const {
59+
inline void set_previous(R_xlen_t i, STORAGE value) const {
6060
previous = value ;
6161
was_na = traits::is_na<RTYPE>(previous) ;
6262
previous_index = i ;
6363
}
6464

65-
inline int size() const { return lhs.size() - 1 ; }
65+
inline R_xlen_t size() const { return lhs.size() - 1 ; }
6666

6767
private:
6868
const LHS_TYPE& lhs ;
6969
mutable STORAGE previous ;
70-
mutable int previous_index ;
70+
mutable R_xlen_t previous_index ;
7171
mutable bool was_na ;
7272
} ;
7373

@@ -78,20 +78,20 @@ class Diff<REALSXP, LHS_NA, LHS_T> : public Rcpp::VectorBase< REALSXP, LHS_NA, D
7878

7979
Diff( const LHS_TYPE& lhs_ ) : lhs(lhs_), previous(lhs_[0]), previous_index(0) {}
8080

81-
inline double operator[]( int i ) const {
81+
inline double operator[]( R_xlen_t i ) const {
8282
double y = lhs[i+1] ;
8383
if( previous_index != i ) previous = lhs[i] ;
8484
double res = y - previous ;
8585
previous = y ;
8686
previous_index = i+1 ;
8787
return res ;
8888
}
89-
inline int size() const { return lhs.size() - 1 ; }
89+
inline R_xlen_t size() const { return lhs.size() - 1 ; }
9090

9191
private:
9292
const LHS_TYPE& lhs ;
9393
mutable double previous ;
94-
mutable int previous_index ;
94+
mutable R_xlen_t previous_index ;
9595
} ;
9696

9797
template <int RTYPE, typename LHS_T>
@@ -102,20 +102,20 @@ class Diff<RTYPE,false,LHS_T> : public Rcpp::VectorBase< RTYPE, false , Diff<RTY
102102

103103
Diff( const LHS_TYPE& lhs_ ) : lhs(lhs_), previous(lhs[0]), previous_index(0) {}
104104

105-
inline STORAGE operator[]( int i ) const {
105+
inline STORAGE operator[]( R_xlen_t i ) const {
106106
STORAGE y = lhs[i+1] ;
107107
if( previous_index != i ) previous = lhs[i] ;
108108
STORAGE diff = y - previous ;
109109
previous = y ;
110110
previous_index = i+1 ;
111111
return y - previous ;
112112
}
113-
inline int size() const { return lhs.size() - 1 ; }
113+
inline R_xlen_t size() const { return lhs.size() - 1 ; }
114114

115115
private:
116116
const LHS_TYPE& lhs ;
117117
mutable STORAGE previous ;
118-
mutable int previous_index ;
118+
mutable R_xlen_t previous_index ;
119119
} ;
120120

121121
} // sugar

inst/include/Rcpp/sugar/functions/head.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ class Head : public Rcpp::VectorBase< RTYPE ,NA, Head<RTYPE,NA,T> > {
3131
typedef typename Rcpp::VectorBase<RTYPE,NA,T> VEC_TYPE ;
3232
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
3333

34-
Head( const VEC_TYPE& object_, int n_ ) : object(object_), n(n_) {
34+
Head( const VEC_TYPE& object_, R_xlen_t n_ ) : object(object_), n(n_) {
3535
if( n < 0 ){
3636
n = object.size() + n ;
3737
}
3838
}
3939

40-
inline STORAGE operator[]( int i ) const {
40+
inline STORAGE operator[]( R_xlen_t i ) const {
4141
return object[ i ] ;
4242
}
43-
inline int size() const { return n; }
43+
inline R_xlen_t size() const { return n; }
4444

4545
private:
4646
const VEC_TYPE& object ;
@@ -52,7 +52,7 @@ class Head : public Rcpp::VectorBase< RTYPE ,NA, Head<RTYPE,NA,T> > {
5252
template <int RTYPE,bool NA, typename T>
5353
inline sugar::Head<RTYPE,NA,T> head(
5454
const VectorBase<RTYPE,NA,T>& t,
55-
int n
55+
R_xlen_t n
5656
){
5757
return sugar::Head<RTYPE,NA,T>( t, n ) ;
5858
}

inst/include/Rcpp/sugar/functions/ifelse.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class IfElse : public VectorBase<
5252
RCPP_DEBUG( DEMANGLE(IfElse) ) ;
5353
}
5454

55-
inline STORAGE operator[]( int i ) const {
55+
inline STORAGE operator[]( R_xlen_t i ) const {
5656
int x = cond[i] ;
5757
if( Rcpp::traits::is_na<LGLSXP>(x) ) return Rcpp::traits::get_na<RTYPE>() ;
5858
if( x ) return lhs[i] ;
5959
return rhs[i] ;
6060
}
6161

62-
inline int size() const { return cond.size() ; }
62+
inline R_xlen_t size() const { return cond.size() ; }
6363

6464
private:
6565
const COND_TYPE& cond ;
@@ -93,12 +93,12 @@ class IfElse<RTYPE,false,COND_T,LHS_NA,LHS_T,RHS_NA,RHS_T> : public VectorBase<
9393
/* FIXME : cond, lhs and rhs must all have the same size */
9494
}
9595

96-
inline STORAGE operator[]( int i ) const {
96+
inline STORAGE operator[]( R_xlen_t i ) const {
9797
if( cond[i] ) return lhs[i] ;
9898
return rhs[i] ;
9999
}
100100

101-
inline int size() const { return cond.size() ; }
101+
inline R_xlen_t size() const { return cond.size() ; }
102102

103103
private:
104104

@@ -133,14 +133,14 @@ class IfElse_Primitive_Vector : public VectorBase<
133133
/* FIXME : cond, lhs and rhs must all have the sale size */
134134
}
135135

136-
inline STORAGE operator[]( int i ) const {
136+
inline STORAGE operator[]( R_xlen_t i ) const {
137137
int x = cond[i] ;
138138
if( Rcpp::traits::is_na<LGLSXP>(x) ) return x ;
139139
if( x ) return lhs ;
140140
return rhs[i] ;
141141
}
142142

143-
inline int size() const { return cond.size() ; }
143+
inline R_xlen_t size() const { return cond.size() ; }
144144

145145
private:
146146
const COND_TYPE& cond ;
@@ -170,12 +170,12 @@ class IfElse_Primitive_Vector<RTYPE,false,COND_T,RHS_NA,RHS_T> : public VectorBa
170170
/* FIXME : cond, lhs and rhs must all have the same size */
171171
}
172172

173-
inline STORAGE operator[]( int i ) const {
173+
inline STORAGE operator[]( R_xlen_t i ) const {
174174
if( cond[i] ) return lhs ;
175175
return rhs[i] ;
176176
}
177177

178-
inline int size() const { return cond.size() ; }
178+
inline R_xlen_t size() const { return cond.size() ; }
179179

180180
private:
181181
const COND_TYPE& cond ;
@@ -209,14 +209,14 @@ class IfElse_Vector_Primitive : public VectorBase<
209209
/* FIXME : cond, lhs and rhs must all have the same size */
210210
}
211211

212-
inline STORAGE operator[]( int i ) const {
212+
inline STORAGE operator[]( R_xlen_t i ) const {
213213
int x = cond[i] ;
214214
if( Rcpp::traits::is_na<LGLSXP>(x) ) return Rcpp::traits::get_na<RTYPE>() ;
215215
if( x ) return lhs[i] ;
216216
return rhs ;
217217
}
218218

219-
inline int size() const { return cond.size() ; }
219+
inline R_xlen_t size() const { return cond.size() ; }
220220

221221
private:
222222
const COND_TYPE& cond ;
@@ -246,12 +246,12 @@ class IfElse_Vector_Primitive<RTYPE,false,COND_T,LHS_NA,LHS_T> : public VectorBa
246246
/* FIXME : cond, lhs and rhs must all have the sale size */
247247
}
248248

249-
inline STORAGE operator[]( int i ) const {
249+
inline STORAGE operator[]( R_xlen_t i ) const {
250250
if( cond[i] ) return lhs[i] ;
251251
return rhs ;
252252
}
253253

254-
inline int size() const { return cond.size() ; }
254+
inline R_xlen_t size() const { return cond.size() ; }
255255

256256
private:
257257
const COND_TYPE& cond ;
@@ -284,13 +284,13 @@ class IfElse_Primitive_Primitive : public VectorBase<
284284
/* FIXME : cond, lhs and rhs must all have the same size */
285285
}
286286

287-
inline STORAGE operator[]( int i ) const {
287+
inline STORAGE operator[]( R_xlen_t i ) const {
288288
int x = cond[i] ;
289289
if( Rcpp::traits::is_na<LGLSXP>(x) ) return Rcpp::traits::get_na<RTYPE>() ;
290290
return x ? lhs : rhs ;
291291
}
292292

293-
inline int size() const { return cond.size() ; }
293+
inline R_xlen_t size() const { return cond.size() ; }
294294

295295
private:
296296
const COND_TYPE& cond ;
@@ -317,11 +317,11 @@ class IfElse_Primitive_Primitive<RTYPE,false,COND_T> : public VectorBase<
317317
/* FIXME : cond, lhs and rhs must all have the same size */
318318
}
319319

320-
inline STORAGE operator[]( int i ) const {
320+
inline STORAGE operator[]( R_xlen_t i ) const {
321321
return cond[i] ? lhs : rhs ;
322322
}
323323

324-
inline int size() const { return cond.size() ; }
324+
inline R_xlen_t size() const { return cond.size() ; }
325325

326326
private:
327327
const COND_TYPE& cond ;
@@ -394,8 +394,8 @@ template<
394394
inline sugar::IfElse_Primitive_Primitive< INTSXP,COND_NA,COND_T >
395395
ifelse(
396396
const Rcpp::VectorBase<LGLSXP,COND_NA,COND_T>& cond,
397-
int lhs,
398-
int rhs
397+
R_xlen_t lhs,
398+
R_xlen_t rhs
399399
){
400400
return sugar::IfElse_Primitive_Primitive<INTSXP,COND_NA,COND_T>( cond, lhs, rhs ) ;
401401
}

inst/include/Rcpp/sugar/functions/is_finite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class IsFinite : public ::Rcpp::VectorBase< LGLSXP, false, IsFinite<RTYPE,NA,VEC
3131

3232
IsFinite( const VEC_TYPE& obj_) : obj(obj_){}
3333

34-
inline int operator[]( int i ) const {
34+
inline int operator[]( R_xlen_t i ) const {
3535
return ::Rcpp::traits::is_finite<RTYPE>( obj[i] ) ;
3636
}
3737

38-
inline int size() const { return obj.size() ; }
38+
inline R_xlen_t size() const { return obj.size() ; }
3939

4040
private:
4141
const VEC_TYPE& obj ;

0 commit comments

Comments
 (0)