[Rcpp-commits] r1312 - in pkg/RcppGSL: inst inst/include inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 25 11:07:56 CEST 2010
Author: romain
Date: 2010-05-25 11:07:56 +0200 (Tue, 25 May 2010)
New Revision: 1312
Modified:
pkg/RcppGSL/inst/ChangeLog
pkg/RcppGSL/inst/include/RcppGSLForward.h
pkg/RcppGSL/inst/unitTests/runit.gsl.R
pkg/RcppGSL/src/RcppGSL.cpp
Log:
RcppGSL::matrix gains operator()(int,int)
Modified: pkg/RcppGSL/inst/ChangeLog
===================================================================
--- pkg/RcppGSL/inst/ChangeLog 2010-05-25 08:53:13 UTC (rev 1311)
+++ pkg/RcppGSL/inst/ChangeLog 2010-05-25 09:07:56 UTC (rev 1312)
@@ -2,6 +2,9 @@
* inst/include/RcppGSLForward.h : add indexing operator, stl iterator and
begin() and end() methods to RcppGSL::vector using proxy classes
+
+ * inst/include/RcppGSLForward.h : RcppGSL::matrix gets indexing
+ operator(int,int)
2010-05-13 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/RcppGSL/inst/include/RcppGSLForward.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-05-25 08:53:13 UTC (rev 1311)
+++ pkg/RcppGSL/inst/include/RcppGSLForward.h 2010-05-25 09:07:56 UTC (rev 1312)
@@ -115,9 +115,9 @@
inline operator type() { \
return gsl_vector##__SUFFIX__##_get( parent, index ) ; \
} \
- inline void move(int d){ index += d ; } \
int index ; \
gsltype* parent ; \
+ inline void move(int d){ index += d ; } \
} ; \
typedef ::Rcpp::internal::Proxy_Iterator<Proxy> iterator ; \
const static int RTYPE = ::Rcpp::traits::r_sexptype_traits<type>::rtype ; \
@@ -157,6 +157,21 @@
typedef gsl_matrix##__SUFFIX__ gsltype ; \
gsltype* data ; \
const static int RTYPE = ::Rcpp::traits::r_sexptype_traits<type>::rtype ; \
+ class Proxy { \
+ public: \
+ Proxy( gsltype* data_, int row_, int col_ ) : \
+ row(row_), col(col_), parent(data_){} \
+ Proxy& operator=( type x) { \
+ gsl_matrix##__SUFFIX__##_set( parent, row, col, x ) ; \
+ return *this ; \
+ } \
+ inline operator type() { \
+ return gsl_matrix##__SUFFIX__##_get( parent, row, col ) ; \
+ } \
+ int row ; \
+ int col ; \
+ gsltype* parent ; \
+ } ; \
matrix( SEXP x) throw(::Rcpp::not_compatible) : data(0) { import(x); } \
matrix( gsltype* x) : data(x) {} \
matrix( int nrow, int ncol) : \
@@ -173,6 +188,9 @@
inline size_t nrow(){ return data->size1 ; } \
inline size_t ncol(){ return data->size2 ; } \
inline size_t size(){ return data->size1 * data->size2 ; } \
+ inline Proxy operator()( int row, int col){ \
+ return Proxy( *this, row, col ) ; \
+ } \
void free(){ \
gsl_matrix##__SUFFIX__##_free(data) ; \
} \
Modified: pkg/RcppGSL/inst/unitTests/runit.gsl.R
===================================================================
--- pkg/RcppGSL/inst/unitTests/runit.gsl.R 2010-05-25 08:53:13 UTC (rev 1311)
+++ pkg/RcppGSL/inst/unitTests/runit.gsl.R 2010-05-25 09:07:56 UTC (rev 1312)
@@ -133,3 +133,9 @@
checkEquals( res, sum(x) )
}
+test.gsl.RcppGSL.matrix.indexing <- function(){
+ m <- matrix( 1:16+.5, nr = 4 )
+ res <- .Call( "test_gsl_matrix_indexing", m , PACKAGE = "RcppGSL" )
+ checkEquals( res, m+1 )
+}
+
Modified: pkg/RcppGSL/src/RcppGSL.cpp
===================================================================
--- pkg/RcppGSL/src/RcppGSL.cpp 2010-05-25 08:53:13 UTC (rev 1311)
+++ pkg/RcppGSL/src/RcppGSL.cpp 2010-05-25 09:07:56 UTC (rev 1312)
@@ -259,3 +259,12 @@
return std::accumulate( vec.begin(), vec.end(), 0.0 );
}
+RCPP_FUNCTION_1(RcppGSL::matrix<double>, test_gsl_matrix_indexing, RcppGSL::matrix<double> mat ){
+ for( size_t i=0; i< mat.nrow(); i++){
+ for( size_t j=0; j< mat.ncol(); j++){
+ mat(i,j) = mat(i,j) + 1.0 ;
+ }
+ }
+ return mat ;
+}
+
More information about the Rcpp-commits
mailing list