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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Dec 4 13:02:19 CET 2010


Author: romain
Date: 2010-12-04 13:02:19 +0100 (Sat, 04 Dec 2010)
New Revision: 2705

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/THANKS
   pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
   pkg/Rcpp/inst/unitTests/runit.Matrix.R
Log:
fix SubMatrix indexing

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-12-04 11:46:44 UTC (rev 2704)
+++ pkg/Rcpp/ChangeLog	2010-12-04 12:02:19 UTC (rev 2705)
@@ -2,6 +2,9 @@
 
     * inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw: documentation patch by 
     Christian Gunnning <xian at unm.edu>
+    
+    * inst/include/Rcpp/vector/matrix.h: fix SubMatrix. Bug reported by 
+    Christian Gunnning <xian at unm.edu> on Rcpp-devel
 
 2010-12-03  Dirk Eddelbuettel  <edd at debian.org>
 

Modified: pkg/Rcpp/inst/THANKS
===================================================================
--- pkg/Rcpp/inst/THANKS	2010-12-04 11:46:44 UTC (rev 2704)
+++ pkg/Rcpp/inst/THANKS	2010-12-04 12:02:19 UTC (rev 2705)
@@ -3,7 +3,7 @@
 
 Laurent Gautier         for helpful discussions on R internals
 Alistair Gee            for a patch making ColDatum more robust
-Christian Gunning       for a documentation patch
+Christian Gunning       for a documentation patch and reporting bugs
 Uwe Ligges              for help with Windows (32 and 64 bit) build issues
 Tama Ma                 for a patch that extends Module constructors
 Karl Millar             for a patch helping with a non-g++ compiler

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2010-12-04 11:46:44 UTC (rev 2704)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2010-12-04 12:02:19 UTC (rev 2705)
@@ -231,8 +231,8 @@
     
     SubMatrix( MATRIX& m_, const Range& row_range_, const Range& col_range_ ) :
         m(m_),
-        iter( static_cast< Vector<RTYPE>& >(m_).begin() + row_range_.get_start() + col_range_.get_start() * m_.ncol() ), 
-        m_nc( m.ncol() ), 
+        iter( static_cast< Vector<RTYPE>& >(m_).begin() + row_range_.get_start() + col_range_.get_start() * m_.nrow() ), 
+        m_nr( m.nrow() ), 
         nc( col_range_.size() ), 
         nr( row_range_.size() )
     {}
@@ -242,15 +242,15 @@
     inline int nrow() const { return nr ; }
     
     inline Proxy operator()(int i, int j) const {
-        return iter[ i + j*m_nc ] ;
+        return iter[ i + j*m_nr ] ;
     }
     
-    inline vec_iterator column_iterator( int j ) const { return iter + j*m_nc ; } 
+    inline vec_iterator column_iterator( int j ) const { return iter + j*m_nr ; } 
     
 private:
     MATRIX& m ;
     vec_iterator iter ;
-    int m_nc, nc, nr ;
+    int m_nr, nc, nr ;
 } ;
 
 template <int RTYPE>

Modified: pkg/Rcpp/inst/unitTests/runit.Matrix.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Matrix.R	2010-12-04 11:46:44 UTC (rev 2704)
+++ pkg/Rcpp/inst/unitTests/runit.Matrix.R	2010-12-04 12:02:19 UTC (rev 2705)
@@ -209,6 +209,20 @@
                  }
                  return output ;
 			    '
+			), 
+			"runit_SubMatrix" = list( 
+			    signature(), 
+			    '
+                 NumericMatrix xx(4, 5);
+                 xx(0,0) = 3;
+                 xx(0,1) = 4;
+                 xx(0,2) = 5;
+                 xx(1,_) = xx(0,_);
+                 xx(_,3) = xx(_,2);
+                 SubMatrix<REALSXP> yy = xx( Range(0,2), Range(0,3) ) ;
+                 NumericMatrix res = yy ;
+                 return res;
+			    '
 			)
 		)
         
@@ -358,3 +372,10 @@
     checkEquals( funx( probs ), apply(probs,2,cumsum) )
 }
 
+test.NumericMatrix.rowsum <- function( ){
+    funx <- .rcpp.Matrix$runit_SubMatrix
+    target <- rbind( c(3,4,5,5), c(3,4,5,5), 0 )
+    checkEquals( funx(), target, msg = "SubMatrix" )
+}
+
+



More information about the Rcpp-commits mailing list