[Rcpp-commits] r2542 - in pkg/Rcpp/inst: include/Rcpp/macros include/Rcpp/vector unitTests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 26 20:01:36 CET 2010
Author: romain
Date: 2010-11-26 20:01:36 +0100 (Fri, 26 Nov 2010)
New Revision: 2542
Modified:
pkg/Rcpp/inst/include/Rcpp/macros/unroll.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
pkg/Rcpp/inst/unitTests/runit.Matrix.R
Log:
fixed stupid bug
Modified: pkg/Rcpp/inst/include/Rcpp/macros/unroll.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/macros/unroll.h 2010-11-26 18:24:17 UTC (rev 2541)
+++ pkg/Rcpp/inst/include/Rcpp/macros/unroll.h 2010-11-26 19:01:36 UTC (rev 2542)
@@ -43,5 +43,25 @@
{} \
}
+#define RCPP_LOOP_UNROLL_LHSFUN(TARGET,FUN,SOURCE) \
+int __trip_count = n >> 2 ; \
+int i = 0 ; \
+for ( ; __trip_count > 0 ; --__trip_count) { \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+} \
+switch (n - i){ \
+ case 3: \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ case 2: \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ case 1: \
+ TARGET[FUN(i)] = SOURCE[i] ; i++ ; \
+ case 0: \
+ default: \
+ {} \
+}
#endif
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2010-11-26 18:24:17 UTC (rev 2541)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2010-11-26 19:01:36 UTC (rev 2542)
@@ -112,13 +112,13 @@
MatrixRow& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
int n = size() ;
const T& ref = rhs.get_ref() ;
- RCPP_LOOP_UNROLL(start,ref)
+ RCPP_LOOP_UNROLL_LHSFUN(start,get_parent_index,ref)
return *this ;
}
MatrixRow& operator=( const MatrixRow& rhs ){
int n = size() ;
- RCPP_LOOP_UNROLL(start,rhs)
+ RCPP_LOOP_UNROLL_LHSFUN(start,get_parent_index,rhs)
return *this ;
}
Modified: pkg/Rcpp/inst/unitTests/runit.Matrix.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Matrix.R 2010-11-26 18:24:17 UTC (rev 2541)
+++ pkg/Rcpp/inst/unitTests/runit.Matrix.R 2010-11-26 19:01:36 UTC (rev 2542)
@@ -190,7 +190,7 @@
signature( x = "matrix" ),
'
NumericMatrix input( x ) ;
- int nr = input.nrow(), nc = input.ncol() ;
+ int nc = input.ncol() ;
NumericMatrix output = clone<NumericMatrix>( input ) ;
for( int i=1; i<nc; i++){
output(_,i) = output(_,i-1) + input(_,i) ;
@@ -202,7 +202,7 @@
signature( x = "matrix" ),
'
NumericMatrix input( x ) ;
- int nr = input.nrow(), nc = input.ncol() ;
+ int nr = input.nrow();
NumericMatrix output = clone<NumericMatrix>( input ) ;
for( int i=1; i<nr; i++){
output(i,_) = output(i-1,_) + input(i,_) ;
More information about the Rcpp-commits
mailing list