[Rcpp-commits] r2439 - in pkg/Rcpp: . inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Nov 17 13:34:57 CET 2010
Author: romain
Date: 2010-11-17 13:34:57 +0100 (Wed, 17 Nov 2010)
New Revision: 2439
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
Log:
initial version of SubMatrix
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2010-11-17 10:45:58 UTC (rev 2438)
+++ pkg/Rcpp/ChangeLog 2010-11-17 12:34:57 UTC (rev 2439)
@@ -2,6 +2,8 @@
* inst/include/Rcpp/sugar/as_vector.h: added the as_vector function that turns
a sugar matrix expression into a vector of the appropriate type
+
+ * inst/include/Rcpp/vector/Matrix.h: new SubMatrix class
2010-11-13 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2010-11-17 10:45:58 UTC (rev 2438)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h 2010-11-17 12:34:57 UTC (rev 2439)
@@ -22,6 +22,8 @@
#ifndef Rcpp__vector__Matrix_h
#define Rcpp__vector__Matrix_h
+template <int RTYPE> class SubMatrix ;
+
template <int RTYPE>
class Matrix : public Vector<RTYPE>, public MatrixBase<RTYPE,true, Matrix<RTYPE> > {
public:
@@ -149,6 +151,11 @@
return Column( *this, i ) ;
}
+ inline SubMatrix<RTYPE> operator()( const Range& row_range, const Range& col_range){
+ return SubMatrix<RTYPE>( *this, row_range, col_range ) ;
+ }
+
+
private:
inline int offset( int i, int j) const {
@@ -210,4 +217,28 @@
} ;
+template <int RTYPE>
+class SubMatrix : public Rcpp::MatrixBase< RTYPE, true, SubMatrix<RTYPE> > {
+public:
+ typedef Matrix<RTYPE> MATRIX ;
+ typedef typename MATRIX::Proxy Proxy ;
+
+ SubMatrix( const MATRIX& m_, const Range& row_range_, const Range& col_range_ ) :
+ m(m_), row_range(row_range_), col_range(col_range_) {}
+
+
+ inline int size() const { return ncol() * nrow() ; }
+ inline int ncol() const { return col_range.size() ; }
+ inline int nrow() const { return row_range.size() ; }
+
+ inline Proxy operator()(int i, int j) const {
+ return m( row_range[i], col_range[j] ) ;
+ }
+
+private:
+ const MATRIX& m ;
+ const Range& row_range ;
+ const Range& col_range ;
+} ;
+
#endif
More information about the Rcpp-commits
mailing list