[Rcpp-commits] r2351 - in pkg/Rcpp: . inst/include/Rcpp/vector inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 21 20:09:08 CEST 2010


Author: romain
Date: 2010-10-21 20:09:07 +0200 (Thu, 21 Oct 2010)
New Revision: 2351

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
   pkg/Rcpp/inst/unitTests/runit.Matrix.R
Log:
fixed Column indexing bug

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-10-21 16:21:56 UTC (rev 2350)
+++ pkg/Rcpp/ChangeLog	2010-10-21 18:09:07 UTC (rev 2351)
@@ -1,3 +1,11 @@
+2010-10-21  Romain Francois <romain at r-enthusiasts.com>
+
+    * inst/include/Rcpp/vector/MatrixColumn.h: Fixed indexing bug (mismatch 
+    between number of rows and number of columns
+    
+    * inst/unitTests/runit.Matrix.R: test the fix above based on the 
+    R-help/Rcpp-devel thread: http://article.gmane.org/gmane.comp.lang.r.rcpp/851
+    
 2010-10-21  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Module.h: Reorder instantiation for class_ 

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-10-21 16:21:56 UTC (rev 2350)
+++ pkg/Rcpp/DESCRIPTION	2010-10-21 18:09:07 UTC (rev 2351)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.8.7
+Version: 0.8.7.1
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Douglas Bates, John Chambers, Simon Urbanek, and David Reiss; 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h	2010-10-21 16:21:56 UTC (rev 2350)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixColumn.h	2010-10-21 18:09:07 UTC (rev 2351)
@@ -40,7 +40,12 @@
 		parent = other.parent ;
 		index  = other.index ;
 	}
-	
+
+//	template <int RT, bool NA, typename T>
+//	MatrixColumn& operator=( const Rcpp::VectorBase<RT,NA,T>& rhs ){
+//	    std::copy( rhs.begin(), rhs.end(), begin() )  ;
+//	}
+
 	Proxy operator[]( int i ){
 		/* TODO: should we cache nrow and ncol */
 		return parent[ get_parent_index(i) ] ;
@@ -52,11 +57,11 @@
 	}
 	
 	inline iterator begin(){
-		return parent.begin() + index * parent.ncol() ;
+		return parent.begin() + index * parent.nrow() ;
 	}
 	
 	inline iterator begin() const {
-		return parent.begin() + index * parent.ncol() ;
+		return parent.begin() + index * parent.nrow() ;
 	}
 	
 	inline iterator end(){
@@ -75,7 +80,7 @@
 	MATRIX& parent; 
 	int index ;
 	
-	inline int get_parent_index(int i) const { return index * parent.ncol() + i ; }
+	inline int get_parent_index(int i) const { return index * parent.nrow() + i ; }
 } ;
 
 #endif

Modified: pkg/Rcpp/inst/unitTests/runit.Matrix.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Matrix.R	2010-10-21 16:21:56 UTC (rev 2350)
+++ pkg/Rcpp/inst/unitTests/runit.Matrix.R	2010-10-21 18:09:07 UTC (rev 2351)
@@ -131,6 +131,22 @@
 					return wrap( std::accumulate( col.begin(), col.end(), 0.0 ) ) ;
 				'	
 			), 
+			"runit_NumericMatrix_cumsum" = list( 
+			    signature(x = "matrix" ), 
+				'
+				NumericMatrix input( x ) ;
+                int nr = input.nrow(), nc = input.ncol() ;
+                NumericMatrix output(nr, nc) ;
+                
+                NumericVector tmp( nr );
+                for( int i=0; i<nc; i++){
+                    tmp = tmp + input.column(i) ;
+                    NumericMatrix::Column target( output, i ) ;
+                    std::copy( tmp.begin(), tmp.end(), target.begin() ) ;
+                }
+                return output ;
+                '
+			), 
 			"runit_CharacterMatrix_column" = list( 
 				signature(x = "matrix" ),
 					'
@@ -272,6 +288,12 @@
 	checkEquals( funx( x ), sum( x[,1] ) , msg = "iterating over a column" )
 }
 
+test.NumericMatrix.cumsum <- function(){
+	funx <- .rcpp.Matrix$runit_NumericMatrix_cumsum
+	x <- matrix( 1:8 + .5, ncol = 2 )
+	checkEquals( funx( x ), t(apply(x, 1, cumsum)) , msg = "cumsum" )
+}
+
 test.CharacterMatrix.column <- function(){
 	funx <- .rcpp.Matrix$runit_CharacterMatrix_column
 	m <- matrix( letters, ncol = 2 )



More information about the Rcpp-commits mailing list