[Rcpp-commits] r1403 - in pkg/RcppGSL: inst/doc/RcppGSL src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 2 15:48:48 CEST 2010


Author: romain
Date: 2010-06-02 15:48:48 +0200 (Wed, 02 Jun 2010)
New Revision: 1403

Modified:
   pkg/RcppGSL/inst/doc/RcppGSL/RcppGSL.Rnw
   pkg/RcppGSL/src/RcppGSL.cpp
Log:
keep the compiler happy

Modified: pkg/RcppGSL/inst/doc/RcppGSL/RcppGSL.Rnw
===================================================================
--- pkg/RcppGSL/inst/doc/RcppGSL/RcppGSL.Rnw	2010-06-02 13:42:43 UTC (rev 1402)
+++ pkg/RcppGSL/inst/doc/RcppGSL/RcppGSL.Rnw	2010-06-02 13:48:48 UTC (rev 1403)
@@ -136,7 +136,6 @@
 
 <<lang=cpp>>=
 RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector<int> vec){
-  int n = vec.size() ;
   int res = std::accumulate( vec.begin(), vec.end(), 0 ) ;
   vec.free() ;
   return res ;
@@ -163,7 +162,7 @@
   // the RcppGSL::vector<int> class
   RcppGSL::vector<int> y = data["y"] ;
   double res = 0.0 ;
-  for( int i=0; i< x->size; i++){
+  for( size_t i=0; i< x->size; i++){
     res += x[i] * y[i] ;
   }
 
@@ -179,7 +178,7 @@
 
 called from R :
 
-<<eval=FALSE>>=
+<<>>=
 data <- list( x = seq(0,1,length=10), y = 1:10 )
 .Call( "gsl_vector_sum_2", data )
 @

Modified: pkg/RcppGSL/src/RcppGSL.cpp
===================================================================
--- pkg/RcppGSL/src/RcppGSL.cpp	2010-06-02 13:42:43 UTC (rev 1402)
+++ pkg/RcppGSL/src/RcppGSL.cpp	2010-06-02 13:48:48 UTC (rev 1403)
@@ -342,33 +342,32 @@
 }
 
 
-// // helping the vignette
-// RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector<int> vec){
-//   int n = vec.size() ;
-//   int res = std::accumulate( vec.begin(), vec.end(), 0 ) ;
-//   vec.free() ;
-//   return res ;
-// }
-// 
-// RCPP_FUNCTION_1( double, gsl_vector_sum_2, Rcpp::List data ){
-//   // grab "x" as a gsl_vector through
-//   // the RcppGSL::vector<double> class
-//   RcppGSL::vector<double> x = data["x"] ;
-// 
-//   // grab "y" as a gsl_vector through
-//   // the RcppGSL::vector<int> class
-//   RcppGSL::vector<int> y = data["y"] ;
-//   double res = 0.0 ;
-//   for( int i=0; i< x->size; i++){
-//     res += x[i] * y[i] ;
-//   }
-// 
-//   // as usual with GSL, we need to explicitely free the
-//   // memory
-//   x.free() ;
-//   y.free() ;
-// 
-//   // return the result
-//   return res ;
-// }
+// helping the vignette
+RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector<int> vec){
+  int res = std::accumulate( vec.begin(), vec.end(), 0 ) ;
+  vec.free() ;
+  return res ;
+}
 
+RCPP_FUNCTION_1( double, gsl_vector_sum_2, Rcpp::List data ){
+  // grab "x" as a gsl_vector through
+  // the RcppGSL::vector<double> class
+  RcppGSL::vector<double> x = data["x"] ;
+
+  // grab "y" as a gsl_vector through
+  // the RcppGSL::vector<int> class
+  RcppGSL::vector<int> y = data["y"] ;
+  double res = 0.0 ;
+  for( size_t i=0; i< x->size; i++){
+    res += x[i] * y[i] ;
+  }
+
+  // as usual with GSL, we need to explicitely free the
+  // memory
+  x.free() ;
+  y.free() ;
+
+  // return the result
+  return res ;
+}
+



More information about the Rcpp-commits mailing list