[Rcpp-commits] r3708 - in pkg/RcppGSL: . R inst vignettes/RcppGSL
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jul 22 22:04:44 CEST 2012
Author: edd
Date: 2012-07-22 22:04:44 +0200 (Sun, 22 Jul 2012)
New Revision: 3708
Modified:
pkg/RcppGSL/ChangeLog
pkg/RcppGSL/DESCRIPTION
pkg/RcppGSL/R/inline.R
pkg/RcppGSL/cleanup
pkg/RcppGSL/inst/NEWS.Rd
pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw
Log:
o R/inline.R changed again to not use assignInMyNamespace but two simple globals
o more vignettes/ cleanup: avoiding highlight use on external C++ or shell
Modified: pkg/RcppGSL/ChangeLog
===================================================================
--- pkg/RcppGSL/ChangeLog 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/ChangeLog 2012-07-22 20:04:44 UTC (rev 3708)
@@ -1,3 +1,11 @@
+2012-07-22 Dirk Eddelbuettel <edd at debian.org>
+
+ * R/inline.R: Use two hidden global variables to store RcppGSL
+ compiler and linker flags instead of using assignInNamespace
+
+ * vignettes/RcppGSL/RcppGSL-intro.Rnw: Skip use of highlight for
+ C++ and shell snippets to sidestep build issues on 32bit OSs
+
2012-07-21 Dirk Eddelbuettel <edd at debian.org>
* R/fastLm.R: expanded summary() display as in RcppArmadillo
@@ -2,4 +10,2 @@
- * R/inline.R: Use assignInMyNamespace() as per current R Policy
-
* inst/NEWS.Rd: converted from ascii text to Rd format
Modified: pkg/RcppGSL/DESCRIPTION
===================================================================
--- pkg/RcppGSL/DESCRIPTION 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/DESCRIPTION 2012-07-22 20:04:44 UTC (rev 3708)
@@ -1,7 +1,7 @@
Package: RcppGSL
Type: Package
Title: Rcpp integration for GNU GSL vectors and matrices
-Version: 0.1.1.4
+Version: 0.1.1.5
Date: $Date$
Author: Romain Francois and Dirk Eddelbuettel
Maintainer: Dirk Eddelbuettel <edd at debian.org>
@@ -20,6 +20,11 @@
The RcppGSL package provides an easy-to-use interface between GSL data
structures and R using concepts from Rcpp which is itself a package that
eases the interfaces between R and C++.
+ .
+ This package also serves as a prime example of how to build a package
+ that uses Rcpp to connect to anoother third-party library. The autoconf
+ script, inline plugin and example package can all be used as a stanza to
+ write a similar package against another library.
License: GPL (>= 2)
LazyLoad: yes
Depends: Rcpp (>= 0.9.8)
Modified: pkg/RcppGSL/R/inline.R
===================================================================
--- pkg/RcppGSL/R/inline.R 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/R/inline.R 2012-07-22 20:04:44 UTC (rev 3708)
@@ -15,38 +15,26 @@
## You should have received a copy of the GNU General Public License
## along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>.
-if(.Platform$OS.type=="windows") {
- LIB_GSL <- Sys.getenv("LIB_GSL")
- gsl_cflags <- sprintf( "-I%s/include", LIB_GSL )
- gsl_libs <- sprintf( "-L%s/lib -lgsl -lgslcblas", LIB_GSL )
- know_flags <- TRUE
-} else {
- gsl_cflags <- ""
- gsl_libs <- ""
- know_flags <- FALSE
-}
+.onLoad <- function(libname, pkgname) {
-get_gsl_flags <- function(){
- gsl_cflags <- system( "gsl-config --cflags" , intern = TRUE )
- gsl_libs <- system( "gsl-config --libs" , intern = TRUE )
+ if (.Platform$OS.type=="windows") {
+ LIB_GSL <- Sys.getenv("LIB_GSL")
+ gsl_cflags <- sprintf( "-I%s/include", LIB_GSL )
+ gsl_libs <- sprintf( "-L%s/lib -lgsl -lgslcblas", LIB_GSL )
+ } else {
+ gsl_cflags <- system( "gsl-config --cflags" , intern = TRUE )
+ gsl_libs <- system( "gsl-config --libs" , intern = TRUE )
+ }
- assignInMyNamespace( "gsl_cflags", gsl_cflags )
- assignInMyNamespace( "gsl_libs", gsl_libs )
- assignInMyNamespace( "know_flags", TRUE )
+ assign( ".rcppgsl_cflags", gsl_cflags, envir=.GlobalEnv )
+ assign( ".rcppgsl_libs", gsl_libs, envir=.GlobalEnv )
}
-LdFlags <- function( print = TRUE ){
- if( ! know_flags ) {
- get_gsl_flags()
- }
- if( print) cat( gsl_libs ) else gsl_libs
-}
+LdFlags <- function(print = TRUE) {
+ if (print) cat(.rcppgsl_libs) else .rcppgsl_libs }
-CFlags <- function( print = TRUE){
- if( ! know_flags ) {
- get_gsl_flags()
- }
- if( print ) cat( gsl_cflags ) else gsl_cflags
+CFlags <- function(print = TRUE) {
+ if (print) cat(.rcppgsl_cflags) else .rcppgsl_cflags
}
inlineCxxPlugin <- function(...) {
Modified: pkg/RcppGSL/cleanup
===================================================================
--- pkg/RcppGSL/cleanup 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/cleanup 2012-07-22 20:04:44 UTC (rev 3708)
@@ -1,7 +1,7 @@
#!/bin/sh
rm -f config.log config.status confdefs.h \
- src/*.o src/*.so src/Makevars \
+ src/*.o src/*.so src/Makevars src/symbols.rds \
inst/doc/*.blg inst/doc/*.bbl \
*/*~ *~
rm -rf autom4te.cache inst/doc/*/auto
Modified: pkg/RcppGSL/inst/NEWS.Rd
===================================================================
--- pkg/RcppGSL/inst/NEWS.Rd 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/inst/NEWS.Rd 2012-07-22 20:04:44 UTC (rev 3708)
@@ -6,13 +6,13 @@
\itemize{
\item{summary() for fastLm() now displays vastly more information}
\item{fastLmPure() now uses same argument order as R's lm.fit()}
- \item{inline support function now uses assignInMyNamespace}
\item{Export and document S3 methods in NAMESPACE and manual page as
such}
\item{Vignettes have been moved to the \code{vignettes/} directory}
\item{Main vignette renamed to \code{RcppGSL-intro.pdf} to use a
filename different from the package reference manual}
\item{NEWS file converted to .Rd format}
+ \item{inline support function no longer uses assignInNamespace}
}
}
\section{Changes in version 0.1.1 (2011-04-05)}{
Modified: pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw
===================================================================
--- pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw 2012-07-21 22:45:19 UTC (rev 3707)
+++ pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw 2012-07-22 20:04:44 UTC (rev 3708)
@@ -24,13 +24,12 @@
\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave
\RequirePackage[T1]{fontenc}
-<<echo=FALSE,print=FALSE>>=
-library( "RcppGSL" )
+<<setup,echo=FALSE,print=FALSE>>=
+require(inline)
+library(RcppGSL)
options("width"=65)
rcppgsl.version <- packageDescription( "RcppGSL" )$Version
prettyDate <- format(Sys.Date(), "%B %e, %Y")
-require( inline )
-require( RcppGSL )
@
% closing $ needed here
@@ -138,55 +137,111 @@
the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice
example for \pkg{GSL} integration with \proglang{R}.
-<<lang=cpp,size=small>>=
-#include <RcppGSL.h>
-#include <gsl/gsl_multifit.h>
-#include <cmath>
+% < < fastLm,lang=cpp,size=small > > =
+% #include <RcppGSL.h>
+% #include <gsl/gsl_multifit.h>
+% #include <cmath>
-extern "C" SEXP fastLm(SEXP ys, SEXP Xs) {
+% extern "C" SEXP fastLm(SEXP ys, SEXP Xs) {
- try {
- RcppGSL::vector<double> y = ys; // create gsl data structures from SEXP
- RcppGSL::matrix<double> X = Xs;
+% try {
+% RcppGSL::vector<double> y = ys; // create gsl data structures from SEXP
+% RcppGSL::matrix<double> X = Xs;
- int n = X.nrow(), k = X.ncol();
- double chisq;
+% int n = X.nrow(), k = X.ncol();
+% double chisq;
- RcppGSL::vector<double> coef(k); // to hold the coefficient vector
- RcppGSL::matrix<double> cov(k,k); // and the covariance matrix
+% RcppGSL::vector<double> coef(k); // to hold the coefficient vector
+% RcppGSL::matrix<double> cov(k,k); // and the covariance matrix
- // the actual fit requires working memory we allocate and free
- gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
- gsl_multifit_linear (X, y, coef, cov, &chisq, work);
- gsl_multifit_linear_free (work);
+% // the actual fit requires working memory we allocate and free
+% gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
+% gsl_multifit_linear (X, y, coef, cov, &chisq, work);
+% gsl_multifit_linear_free (work);
- // extract the diagonal as a vector view
- gsl_vector_view diag = gsl_matrix_diagonal(cov) ;
+% // extract the diagonal as a vector view
+% gsl_vector_view diag = gsl_matrix_diagonal(cov) ;
- // currently there is not a more direct interface in Rcpp::NumericVector
- // that takes advantage of wrap, so we have to do it in two steps
- Rcpp::NumericVector std_err ; std_err = diag;
- std::transform( std_err.begin(), std_err.end(), std_err.begin(), sqrt);
+% // currently there is not a more direct interface in Rcpp::NumericVector
+% // that takes advantage of wrap, so we have to do it in two steps
+% Rcpp::NumericVector std_err ; std_err = diag;
+% std::transform( std_err.begin(), std_err.end(), std_err.begin(), sqrt);
- Rcpp::List res = Rcpp::List::create(Rcpp::Named("coefficients") = coef,
- Rcpp::Named("stderr") = std_err,
- Rcpp::Named("df") = n - k);
+% Rcpp::List res = Rcpp::List::create(Rcpp::Named("coefficients") = coef,
+% Rcpp::Named("stderr") = std_err,
+% Rcpp::Named("df") = n - k);
- // free all the GSL vectors and matrices -- as these are really C data structures
- // we cannot take advantage of automatic memory management
- coef.free(); cov.free(); y.free(); X.free();
+% // free all the GSL vectors and matrices -- as these are really C data structures
+% // we cannot take advantage of automatic memory management
+% coef.free(); cov.free(); y.free(); X.free();
- return res; // return the result list to R
+% return res; // return the result list to R
- } catch( std::exception &ex ) {
- forward_exception_to_r( ex );
- } catch(...) {
- ::Rf_error( "c++ exception (unknown reason)" );
- }
- return R_NilValue; // -Wall
-}
-@
+% } catch( std::exception &ex ) {
+% forward_exception_to_r( ex );
+% } catch(...) {
+% ::Rf_error( "c++ exception (unknown reason)" );
+% }
+% return R_NilValue; // -Wall
+% }
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hldir{\#include\ \usebox{\hlsmallboxlessthan}RcppGSL.h\usebox{\hlsmallboxgreaterthan}}\hspace*{\fill}\\
+\hlstd{}\hldir{\#include\ \usebox{\hlsmallboxlessthan}gsl/gsl\textunderscore multifit.h\usebox{\hlsmallboxgreaterthan}}\hspace*{\fill}\\
+\hlstd{}\hldir{\#include\ \usebox{\hlsmallboxlessthan}cmath\usebox{\hlsmallboxgreaterthan}}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwc{extern\ }\hlstd{}\hlstr{"C"}\hlstd{\ SEXP\ }\hlkwd{fastLm}\hlstd{}\hlsym{(}\hlstd{SEXP\ ys}\hlsym{,\ }\hlstd{SEXP\ Xs}\hlsym{)\ \usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ }\hlstd{}\hlkwa{try\ }\hlstd{}\hlsym{\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{y\ }\hlsym{=\ }\hlstd{ys}\hlsym{;}\hlstd{\ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ create\ gsl\ data\ structures\ from\ SEXP}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{matrix}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{X\ }\hlsym{=\ }\hlstd{Xs}\hlsym{;}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwb{int\ }\hlstd{n\ }\hlsym{=\ }\hlstd{X}\hlsym{.}\hlstd{}\hlkwd{nrow}\hlstd{}\hlsym{(),\ }\hlstd{k\ }\hlsym{=\ }\hlstd{X}\hlsym{.}\hlstd{}\hlkwd{ncol}\hlstd{}\hlsym{();}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwb{double\ }\hlstd{chisq}\hlsym{;}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{}\hlkwd{coef}\hlstd{}\hlsym{(}\hlstd{k}\hlsym{);}\hlstd{\ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ to\ hold\ the\ coefficient\ vector}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{matrix}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{}\hlkwd{cov}\hlstd{}\hlsym{(}\hlstd{k}\hlsym{,}\hlstd{k}\hlsym{);}\hlstd{\ \ \ }\hlsym{}\hlstd{}\hlslc{//\ and\ the\ covariance\ matrix}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ the\ actual\ fit\ requires\ working\ memory\ we\ allocate\ and\ free}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{gsl\textunderscore multifit\textunderscore linear\textunderscore workspace\ }\hlsym{{*}}\hlstd{work\ }\hlsym{=\ }\hlstd{}\hlkwd{gsl\textunderscore multifit\textunderscore linear\textunderscore alloc\ }\hlstd{}\hlsym{(}\hlstd{n}\hlsym{,\ }\hlstd{k}\hlsym{);}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwd{gsl\textunderscore multifit\textunderscore linear\ }\hlstd{}\hlsym{(}\hlstd{X}\hlsym{,\ }\hlstd{y}\hlsym{,\ }\hlstd{coef}\hlsym{,\ }\hlstd{cov}\hlsym{,\ \&}\hlstd{chisq}\hlsym{,\ }\hlstd{work}\hlsym{);}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwd{gsl\textunderscore multifit\textunderscore linear\textunderscore free\ }\hlstd{}\hlsym{(}\hlstd{work}\hlsym{);}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ extract\ the\ diagonal\ as\ a\ vector\ view}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{gsl\textunderscore vector\textunderscore view\ diag\ }\hlsym{=\ }\hlstd{}\hlkwd{gsl\textunderscore matrix\textunderscore diagonal}\hlstd{}\hlsym{(}\hlstd{cov}\hlsym{)\ ;}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ currently\ there\ is\ not\ a\ more\ direct\ interface\ in\ Rcpp::NumericVector}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ that\ takes\ advantage\ of\ wrap,\ so\ we\ have\ to\ do\ it\ in\ two\ steps}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{Rcpp}\hlsym{::}\hlstd{NumericVector\ std\textunderscore err\ }\hlsym{;\ }\hlstd{std\textunderscore err\ }\hlsym{=\ }\hlstd{diag}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{std}\hlsym{::}\hlstd{}\hlkwd{transform}\hlstd{}\hlsym{(\ }\hlstd{std\textunderscore err}\hlsym{.}\hlstd{}\hlkwd{begin}\hlstd{}\hlsym{(),\ }\hlstd{std\textunderscore err}\hlsym{.}\hlstd{}\hlkwd{end}\hlstd{}\hlsym{(),\ }\hlstd{std\textunderscore err}\hlsym{.}\hlstd{}\hlkwd{begin}\hlstd{}\hlsym{(),\ }\hlstd{sqrt}\hlsym{);}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{Rcpp}\hlsym{::}\hlstd{List\ res\ }\hlsym{=\ }\hlstd{Rcpp}\hlsym{::}\hlstd{List}\hlsym{::}\hlstd{}\hlkwd{create}\hlstd{}\hlsym{(}\hlstd{Rcpp}\hlsym{::}\hlstd{}\hlkwd{Named}\hlstd{}\hlsym{(}\hlstd{}\hlstr{"coefficients"}\hlstd{}\hlsym{)\ =\ }\hlstd{coef}\hlsym{,}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{Rcpp}\hlsym{::}\hlstd{}\hlkwd{Named}\hlstd{}\hlsym{(}\hlstd{}\hlstr{"stderr"}\hlstd{}\hlsym{)\ =\ }\hlstd{std\textunderscore err}\hlsym{,}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlstd{Rcpp}\hlsym{::}\hlstd{}\hlkwd{Named}\hlstd{}\hlsym{(}\hlstd{}\hlstr{"df"}\hlstd{}\hlsym{)\ =\ }\hlstd{n\ }\hlsym{{-}\ }\hlstd{k}\hlsym{);}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ free\ all\ the\ GSL\ vectors\ and\ matrices\ {-}{-}\ as\ these\ are\ really\ C\ data\ structures}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlslc{//\ we\ cannot\ take\ advantage\ of\ automatic\ memory\ management}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{coef}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{();\ }\hlstd{cov}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{();\ }\hlstd{y}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{();\ }\hlstd{X}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{();}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwa{return\ }\hlstd{res}\hlsym{;}\hlstd{\ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ return\ the\ result\ list\ to\ R}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ }\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}\ }\hlstd{}\hlkwa{catch}\hlstd{}\hlsym{(\ }\hlstd{std}\hlsym{::}\hlstd{exception\ }\hlsym{\&}\hlstd{ex\ }\hlsym{)\ \usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlkwd{forward\textunderscore exception\textunderscore to\textunderscore r}\hlstd{}\hlsym{(\ }\hlstd{ex\ }\hlsym{);}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}\ }\hlstd{}\hlkwa{catch}\hlstd{}\hlsym{(...)\ \usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ \ \ \ \ }\hlstd{}\hlsym{::}\hlstd{}\hlkwd{Rf\textunderscore error}\hlstd{}\hlsym{(\ }\hlstd{}\hlstr{"c++\ exception\ (unknown\ reason)"}\hlstd{\ }\hlsym{);}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{R\textunderscore NilValue}\hlsym{;\ }\hlstd{}\hlslc{//\ {-}Wall}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
+
We first initialize a \textsl{RcppGSL} vector and matrix, each templated to
the standard numeric type \texttt{double} (and the GSL supports other types
ranging from lower precision floating point to signed and unsigned integers
@@ -223,65 +278,135 @@
data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int|
structs are defined as:
-<<lang=cpp,size=small>>=
-typedef struct{
- size_t size;
- size_t stride;
- double * data;
- gsl_block * block;
- int owner;
-} gsl_vector;
+% < < vector_int,lang=cpp,size=small > > =
+% typedef struct{
+% size_t size;
+% size_t stride;
+% double * data;
+% gsl_block * block;
+% int owner;
+% } gsl_vector;
-typedef struct {
- size_t size;
- size_t stride;
- int * data;
- gsl_block_int * block;
- int owner;
-}
-gsl_vector_int;
-@
+% typedef struct {
+% size_t size;
+% size_t stride;
+% int * data;
+% gsl_block_int * block;
+% int owner;
+% }
+% gsl_vector_int;
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hlkwc{typedef\ }\hlstd{}\hlkwb{struct}\hlstd{}\hlsym{\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{size\textunderscore t\ }\hlstd{size}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{size\textunderscore t\ }\hlstd{stride}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{double\ }\hlstd{}\hlsym{{*}\ }\hlstd{data}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{gsl\textunderscore block\ }\hlsym{{*}\ }\hlstd{block}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{int\ }\hlstd{owner}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}\ }\hlstd{gsl\textunderscore vector}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwc{typedef\ }\hlstd{}\hlkwb{struct\ }\hlstd{}\hlsym{\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{size\textunderscore t\ }\hlstd{size}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{size\textunderscore t\ }\hlstd{stride}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{int\ }\hlstd{}\hlsym{{*}\ }\hlstd{data}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{gsl\textunderscore block\textunderscore int\ }\hlsym{{*}\ }\hlstd{block}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{int\ }\hlstd{owner}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{gsl\textunderscore vector\textunderscore int}\hlsym{;}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
+
A typical use of the \verb|gsl_vector| struct is given below:
-<<lang=cpp,size=small>>=
-int i;
-gsl_vector * v = gsl_vector_alloc (3); // allocate a gsl_vector of size 3
+% < <vector_free,lang=cpp,size=small> > =
+% int i;
+% gsl_vector * v = gsl_vector_alloc (3); // allocate a gsl_vector of size 3
-for (i = 0; i < 3; i++) { // fill the vector
- gsl_vector_set (v, i, 1.23 + i);
-}
+% for (i = 0; i < 3; i++) { // fill the vector
+% gsl_vector_set (v, i, 1.23 + i);
+% }
-double sum = 0.0 ; // access elements
-for (i = 0; i < 3; i++) {
- sum += gsl_vector_set( v, i ) ;
-}
+% double sum = 0.0 ; // access elements
+% for (i = 0; i < 3; i++) {
+% sum += gsl_vector_set( v, i ) ;
+% }
-gsl_vector_free (v); // free the memory
-@
+% gsl_vector_free (v); // free the memory
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hlkwb{int\ }\hlstd{i}\hlsym{;}\hspace*{\fill}\\
+\hlstd{gsl\textunderscore vector\ }\hlsym{{*}\ }\hlstd{v\ }\hlsym{=\ }\hlstd{}\hlkwd{gsl\textunderscore vector\textunderscore alloc\ }\hlstd{}\hlsym{(}\hlstd{}\hlnum{3}\hlstd{}\hlsym{);}\hlstd{\ \ }\hlsym{}\hlstd{}\hlslc{//\ allocate\ a\ gsl\textunderscore vector\ of\ size\ 3}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwa{for\ }\hlstd{}\hlsym{(}\hlstd{i\ }\hlsym{=\ }\hlstd{}\hlnum{0}\hlstd{}\hlsym{;\ }\hlstd{i\ }\hlsym{\usebox{\hlsmallboxlessthan}\ }\hlstd{}\hlnum{3}\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{++)\ \usebox{\hlsmallboxopenbrace}}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ fill\ the\ vector}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwd{gsl\textunderscore vector\textunderscore set\ }\hlstd{}\hlsym{(}\hlstd{v}\hlsym{,\ }\hlstd{i}\hlsym{,\ }\hlstd{}\hlnum{1.23\ }\hlstd{}\hlsym{+\ }\hlstd{i}\hlsym{);}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwb{double\ }\hlstd{sum\ }\hlsym{=\ }\hlstd{}\hlnum{0.0\ }\hlstd{}\hlsym{;}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ access\ elements}\hspace*{\fill}\\
+\hlstd{}\hlkwa{for\ }\hlstd{}\hlsym{(}\hlstd{i\ }\hlsym{=\ }\hlstd{}\hlnum{0}\hlstd{}\hlsym{;\ }\hlstd{i\ }\hlsym{\usebox{\hlsmallboxlessthan}\ }\hlstd{}\hlnum{3}\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{++)\ \usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{sum\ }\hlsym{+=\ }\hlstd{}\hlkwd{gsl\textunderscore vector\textunderscore set}\hlstd{}\hlsym{(\ }\hlstd{v}\hlsym{,\ }\hlstd{i\ }\hlsym{)\ ;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwd{gsl\textunderscore vector\textunderscore free\ }\hlstd{}\hlsym{(}\hlstd{v}\hlsym{);}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ free\ the\ memory}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
\subsection{RcppGSL::vector}
\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector<T>} to manipulate
\verb|gsl_vector| pointers taking advantage of C++ templates. Using this
template type, the previous example now becomes:
-<<lang=cpp,size=small>>=
-int i;
-RcppGSL::vector<double> v(3); // allocate a gsl_vector of size 3
+% < < vector_sum,lang=cpp,size=small > > =
+% int i;
+% RcppGSL::vector<double> v(3); // allocate a gsl_vector of size 3
-for (i = 0; i < 3; i++) { // fill the vector
- v[i] = 1.23 + i ;
-}
+% for (i = 0; i < 3; i++) { // fill the vector
+% v[i] = 1.23 + i ;
+% }
-double sum = 0.0 ; // access elements
-for (i = 0; i < 3; i++) {
- sum += v[i] ;
-}
+% double sum = 0.0 ; // access elements
+% for (i = 0; i < 3; i++) {
+% sum += v[i] ;
+% }
-v.free() ; // free the memory
-@
+% v.free() ; // free the memory
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hlkwb{int\ }\hlstd{i}\hlsym{;}\hspace*{\fill}\\
+\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{}\hlkwd{v}\hlstd{}\hlsym{(}\hlstd{}\hlnum{3}\hlstd{}\hlsym{);}\hlstd{\ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ allocate\ a\ gsl\textunderscore vector\ of\ size\ 3}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwa{for\ }\hlstd{}\hlsym{(}\hlstd{i\ }\hlsym{=\ }\hlstd{}\hlnum{0}\hlstd{}\hlsym{;\ }\hlstd{i\ }\hlsym{\usebox{\hlsmallboxlessthan}\ }\hlstd{}\hlnum{3}\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{++)\ \usebox{\hlsmallboxopenbrace}}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ fill\ the\ vector}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{v}\hlsym{{[}}\hlstd{i}\hlsym{{]}\ =\ }\hlstd{}\hlnum{1.23\ }\hlstd{}\hlsym{+\ }\hlstd{i\ }\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{}\hspace*{\fill}\\
+\hlkwb{double\ }\hlstd{sum\ }\hlsym{=\ }\hlstd{}\hlnum{0.0\ }\hlstd{}\hlsym{;}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ access\ elements}\hspace*{\fill}\\
+\hlstd{}\hlkwa{for\ }\hlstd{}\hlsym{(}\hlstd{i\ }\hlsym{=\ }\hlstd{}\hlnum{0}\hlstd{}\hlsym{;\ }\hlstd{i\ }\hlsym{\usebox{\hlsmallboxlessthan}\ }\hlstd{}\hlnum{3}\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{++)\ \usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{sum\ }\hlsym{+=\ }\hlstd{v}\hlsym{{[}}\hlstd{i}\hlsym{{]}\ ;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+v}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{()\ ;}\hlstd{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }\hlsym{}\hlstd{}\hlslc{//\ free\ the\ memory}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
The class \texttt{RcppGSL::vector<double>} is a smart pointer, that can be used
anywhere where a raw pointer \verb|gsl_vector| can be used, such as the
\verb|gsl_vector_set| and \verb|gsl_vector_get| functions above.
@@ -293,17 +418,32 @@
\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through
the \texttt{RcppGSL::vector<int>} template specialization:
-<<lang=cpp,size=small>>=
-RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector<int> vec){
- int res = std::accumulate( vec.begin(), vec.end(), 0 ) ;
- vec.free() ; // we need to free vec after use
- return res ;
-}
-@
+% < <macro,lang=cpp,size=small > > =
+% RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector<int> vec){
+% int res = std::accumulate( vec.begin(), vec.end(), 0 ) ;
+% vec.free() ; // we need to free vec after use
+% return res ;
+% }
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hlkwd{RCPP\textunderscore FUNCTION\textunderscore 1}\hlstd{}\hlsym{(\ }\hlstd{}\hlkwb{int}\hlstd{}\hlsym{,\ }\hlstd{sum\textunderscore gsl\textunderscore vector\textunderscore int}\hlsym{,\ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{int}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{vec}\hlsym{)\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{int\ }\hlstd{res\ }\hlsym{=\ }\hlstd{std}\hlsym{::}\hlstd{}\hlkwd{accumulate}\hlstd{}\hlsym{(\ }\hlstd{vec}\hlsym{.}\hlstd{}\hlkwd{begin}\hlstd{}\hlsym{(),\ }\hlstd{vec}\hlsym{.}\hlstd{}\hlkwd{end}\hlstd{}\hlsym{(),\ }\hlstd{}\hlnum{0\ }\hlstd{}\hlsym{)\ ;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{vec}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{()\ ;}\hlstd{\ \ }\hlsym{}\hlstd{}\hlslc{//\ we\ need\ to\ free\ vec\ after\ use}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{res\ }\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
+
The function can then simply be called from \proglang{R} :
-<<results=hide,echo=FALSE>>=
+<<inlineex1,results=hide,echo=FALSE>>=
fx <- cxxfunction(
list( sum_gsl_vector_int = signature( vec_ = "integer" ) ),
c( sum_gsl_vector_int = '
@@ -312,7 +452,7 @@
vec.free() ; // we need to free vec after use
return wrap( res ) ;
' ), plugin = "RcppGSL" )
-<<size=small>>=
+<<callinlineex1,size=small>>=
.Call( "sum_gsl_vector_int", 1:10 )
@
@@ -320,30 +460,57 @@
R list as \verb|gsl_vector| objects using implicit conversion mechanisms
of \pkg{Rcpp}
-<<lang=cpp,size=small>>=
-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"] ;
+%< < example2,lang=cpp,size=small > > =
+% 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] ;
- }
+% // 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() ;
+% // as usual with GSL, we need to explicitely free the memory
+% x.free() ;
+% y.free() ;
- // return the result
- return res ;
-}
-@
+% // return the result
+% return res ;
+% }
+% @
+\begin{small}
+\begin{Hchunk}
+\noindent
+\ttfamily
+\hlstd{}\hlkwd{RCPP\textunderscore FUNCTION\textunderscore 1}\hlstd{}\hlsym{(\ }\hlstd{}\hlkwb{double}\hlstd{}\hlsym{,\ }\hlstd{gsl\textunderscore vector\textunderscore sum\textunderscore 2}\hlsym{,\ }\hlstd{Rcpp}\hlsym{::}\hlstd{List\ data\ }\hlsym{)\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlslc{//\ grab\ "x"\ as\ a\ gsl\textunderscore vector\ through\ the\ RcppGSL::vector\usebox{\hlsmallboxlessthan}double\usebox{\hlsmallboxgreaterthan}\ class}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{x\ }\hlsym{=\ }\hlstd{data}\hlsym{{[}}\hlstd{}\hlstr{"x"}\hlstd{}\hlsym{{]}\ ;}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ }\hlstd{}\hlslc{//\ grab\ "y"\ as\ a\ gsl\textunderscore vector\ through\ the\ RcppGSL::vector\usebox{\hlsmallboxlessthan}int\usebox{\hlsmallboxgreaterthan}\ class}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{int}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{y\ }\hlsym{=\ }\hlstd{data}\hlsym{{[}}\hlstd{}\hlstr{"y"}\hlstd{}\hlsym{{]}\ ;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{double\ }\hlstd{res\ }\hlsym{=\ }\hlstd{}\hlnum{0.0\ }\hlstd{}\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlsym{(\ }\hlstd{}\hlkwb{size\textunderscore t\ }\hlstd{i}\hlsym{=}\hlstd{}\hlnum{0}\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{\usebox{\hlsmallboxlessthan}\ }\hlstd{x}\hlsym{{-}\usebox{\hlsmallboxgreaterthan}}\hlstd{size}\hlsym{;\ }\hlstd{i}\hlsym{++)\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ \ \ }\hlstd{res\ }\hlsym{+=\ }\hlstd{x}\hlsym{{[}}\hlstd{i}\hlsym{{]}\ {*}\ }\hlstd{y}\hlsym{{[}}\hlstd{i}\hlsym{{]}\ ;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ }\hlstd{}\hlslc{//\ as\ usual\ with\ GSL,\ we\ need\ to\ explicitely\ free\ the\ memory}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{x}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{()\ ;}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{y}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{()\ ;}\hspace*{\fill}\\
+\hlstd{\hspace*{\fill}\\
+}\hlstd{\ \ }\hlstd{}\hlslc{//\ return\ the\ result}\hspace*{\fill}\\
+\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{res\ }\hlsym{;}\hspace*{\fill}\\
+\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hlstd{}\hspace*{\fill}\\
+\mbox{}
+\normalfont
+\end{Hchunk}\vspace{1em}
+\end{small}
+
called from \proglang{R} :
-<<results=hide, echo=FALSE>>=
+<<inlinexex2,results=hide, echo=FALSE>>=
fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ),
c( gsl_vector_sum_2 = '
List data(data_) ;
@@ -366,7 +533,7 @@
return wrap(res);
' ), plugin = "RcppGSL" )
@
-<<>>=
+<<callinlineex2>>=
data <- list( x = seq(0,1,length=10), y = 1:10 )
.Call( "gsl_vector_sum_2", data )
@
@@ -410,25 +577,50 @@
type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view}
to handle vector views using \proglang{C++} syntax.
-<<lang=cpp,size=small>>=
-extern "C" SEXP test_gsl_vector_view(){
- int n = 10 ;
- RcppGSL::vector<double> v(n) ;
- for( int i=0 ; i<n; i++){
- v[i] = i ;
- }
- RcppGSL::vector_view<double> v_even = gsl_vector_subvector_with_stride(v,0,2,n/2);
- RcppGSL::vector_view<double> v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2);
+% < < lang=cpp,size=small > > =
+% extern "C" SEXP test_gsl_vector_view(){
+% int n = 10 ;
+% RcppGSL::vector<double> v(n) ;
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 3708
More information about the Rcpp-commits
mailing list