Skip to content

Commit c5a914f

Browse files
author
Qiang Kou
committed
fix range sugar
1 parent ef07a32 commit c5a914f

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2016-10-24 Qiang Kou <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/Range.h : fix range sugar ambiguity
4+
* inst/unitTests/cpp/sugar.cpp: range sugar unit test
5+
* inst/unitTests/runit.sugar.R: range sugar unit test
6+
17
2016-10-24 Nathan Russell <[email protected]>
28

39
* inst/include/Rcpp/vector/MatrixBase.h: Change sugar

inst/include/Rcpp/sugar/Range.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ namespace Rcpp{
6060
return orig ;
6161
}
6262

63-
Range& operator+=(R_xlen_t n) {
63+
Range& operator+=( int n ) {
6464
start += n ; end_ += n ;
6565
return *this ;
6666
}
6767

68-
Range& operator-=(R_xlen_t n) {
68+
Range& operator-=( int n ) {
6969
start -= n ; end_ -= n ;
7070
return *this ;
7171
}
7272

73-
Range operator+( R_xlen_t n ){
73+
Range operator+( int n ){
7474
return Range( start + n, end_ + n ) ;
7575
}
7676

77-
Range operator-( R_xlen_t n ){
77+
Range operator-( int n ){
7878
return Range( start - n, end_ - n ) ;
7979
}
8080

inst/unitTests/cpp/sugar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,18 @@ NumericVector runit_Range(){
303303
return xx ;
304304
}
305305

306+
// [[Rcpp::export]]
307+
IntegerVector runit_range_plus(int start, int end, int n) {
308+
IntegerVector vec = Range(start, end) + n;
309+
return vec;
310+
}
311+
312+
// [[Rcpp::export]]
313+
IntegerVector runit_range_minus(int start, int end, int n) {
314+
IntegerVector vec = Range(start, end) - n;
315+
return vec;
316+
}
317+
306318
// [[Rcpp::export]]
307319
NumericVector runit_sapply( NumericVector xx ){
308320
NumericVector res = sapply( xx, square<double>() );

inst/unitTests/runit.sugar.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ if (.runThisTest) {
360360
checkEquals(fx(), c( exp(seq_len(4)), exp(-seq_len(4))))
361361
}
362362

363+
test.sugar.Range.plus <- function( ){
364+
fx <- runit_range_plus
365+
checkEquals( fx(1, 10, 2), c(1:10) + 2 )
366+
}
367+
368+
test.sugar.Range.minus <- function( ){
369+
fx <- runit_range_minus
370+
checkEquals( fx(1, 10, 2), c(1:10) - 2 )
371+
}
372+
363373
test.sugar.sapply <- function( ){
364374
fx <- runit_sapply
365375
checkEquals( fx(1:10) , (1:10)^2 )

0 commit comments

Comments
 (0)