From noreply at r-forge.r-project.org Wed Jun 5 02:03:19 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 02:03:19 +0200 (CEST) Subject: [Rcpp-commits] r4328 - in pkg/RcppArmadillo: . debian inst inst/include inst/include/armadillo_bits Message-ID: <20130605000319.5165118535B@r-forge.r-project.org> Author: edd Date: 2013-06-05 02:03:18 +0200 (Wed, 05 Jun 2013) New Revision: 4328 Added: pkg/RcppArmadillo/inst/include/armadillo_bits/xvec_htrans_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/xvec_htrans_meat.hpp Modified: pkg/RcppArmadillo/ChangeLog pkg/RcppArmadillo/DESCRIPTION pkg/RcppArmadillo/debian/changelog pkg/RcppArmadillo/debian/control pkg/RcppArmadillo/inst/NEWS.Rd pkg/RcppArmadillo/inst/include/armadillo pkg/RcppArmadillo/inst/include/armadillo_bits/Col_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Proxy.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/ProxyCube.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Row_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/Row_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/access.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/arma_version.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/arrayops_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/arrayops_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/compiler_setup.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/config.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/diagview_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/diagview_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/diskio_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eGlueCube_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eGlueCube_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eGlue_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eGlue_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eOpCube_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eOpCube_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eOp_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eOp_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eglue_core_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/eop_core_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/fn_as_scalar.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/forward_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/hdf5_misc.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/memory.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/op_median_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/podarray_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/subview_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/subview_cube_bones.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/subview_cube_meat.hpp pkg/RcppArmadillo/inst/include/armadillo_bits/subview_meat.hpp Log: RcppArmadillo 0.3.900.0 with Armadillo release 3.900.0 Modified: pkg/RcppArmadillo/ChangeLog =================================================================== --- pkg/RcppArmadillo/ChangeLog 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/ChangeLog 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,3 +1,10 @@ +2013-06-04 Dirk Eddelbuettel + + * DESCRIPTION: Release 0.3.900.0 + * inst/NEWS: Release 0.3.900.0 + * inst/include/*: Upgraded to new release 3.900.0 of Armadillo + * debian/*: Similarly updated for new release to Debian + 2013-05-16 Dirk Eddelbuettel * inst/examples/kalman/benchmark.R: Switch from inline to sourceCpp Modified: pkg/RcppArmadillo/DESCRIPTION =================================================================== --- pkg/RcppArmadillo/DESCRIPTION 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/DESCRIPTION 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,7 +1,7 @@ Package: RcppArmadillo Type: Package Title: Rcpp integration for Armadillo templated linear algebra library -Version: 0.3.820 +Version: 0.3.900.0 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Doug Bates Maintainer: Dirk Eddelbuettel Modified: pkg/RcppArmadillo/debian/changelog =================================================================== --- pkg/RcppArmadillo/debian/changelog 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/debian/changelog 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,3 +1,15 @@ +r-cran-rcpparmadillo (0.3.900.0-1) unstable; urgency=low + + * New upstream release + + -- Dirk Eddelbuettel Tue, 04 Jun 2013 19:01:58 -0500 + +r-cran-rcpparmadillo (0.3.820-2) unstable; urgency=low + + * debian/control: Add a Depends: on r-cran-rcpp (Closes: #710127) + + -- Dirk Eddelbuettel Tue, 28 May 2013 09:31:14 -0500 + r-cran-rcpparmadillo (0.3.820-1) unstable; urgency=low * New upstream release Modified: pkg/RcppArmadillo/debian/control =================================================================== --- pkg/RcppArmadillo/debian/control 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/debian/control 2013-06-05 00:03:18 UTC (rev 4328) @@ -2,13 +2,13 @@ Section: gnu-r Priority: optional Maintainer: Dirk Eddelbuettel -Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.0.0), r-cran-rcpp, cdbs +Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.0.1), r-cran-rcpp, cdbs Standards-Version: 3.9.4 Homepage: http://dirk.eddelbuettel.com/code/rcpp.armadillo.html Package: r-cran-rcpparmadillo Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, ${R:Depends}, littler +Depends: ${shlibs:Depends}, ${misc:Depends}, ${R:Depends}, littler, r-cran-rcpp Description: GNU R package for Armadillo C++ linear algebra library Armadillo is a templated C++ linear algebra library (by Conrad Sanderson) that aims towards a good balance between speed and ease of use. Integer, Modified: pkg/RcppArmadillo/inst/NEWS.Rd =================================================================== --- pkg/RcppArmadillo/inst/NEWS.Rd 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/NEWS.Rd 2013-06-05 00:03:18 UTC (rev 4328) @@ -2,6 +2,24 @@ \title{News for Package 'RcppArmadillo'} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} +\section{Changes in RcppArmadillo version 0.3.900 (2013-06-04)}{ + \itemize{ + \item Upgraded to Armadillo release Version 3.900.0 (Bavarian + Sunflower) + \itemize{ + \item added automatic SSE2 vectorisation of elementary expressions + (eg. matrix addition) when using GCC 4.7+ with -O3 optimisation + \item added support for saving & loading of cubes in HDF5 format, + contributed by Szabolcs Horvat + \item faster \code{median()}, contributed by Ruslan Shestopalyuk + \item faster handling of compound expressions with transposes of + submatrix rows + \item faster handling of compound expressions with transposes of + complex vectors + } + } +} + \section{Changes in RcppArmadillo version 0.3.820 (2013-05-12)}{ \itemize{ \item Upgraded to Armadillo release Version 3.820 (Mt Cootha) Modified: pkg/RcppArmadillo/inst/include/armadillo =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo 2013-06-05 00:03:18 UTC (rev 4328) @@ -139,6 +139,7 @@ #include "armadillo_bits/Col_bones.hpp" #include "armadillo_bits/Row_bones.hpp" #include "armadillo_bits/Cube_bones.hpp" + #include "armadillo_bits/xvec_htrans_bones.hpp" #include "armadillo_bits/SpValProxy_bones.hpp" #include "armadillo_bits/SpMat_bones.hpp" @@ -444,6 +445,8 @@ #include "armadillo_bits/Col_meat.hpp" #include "armadillo_bits/Row_meat.hpp" #include "armadillo_bits/Cube_meat.hpp" + #include "armadillo_bits/xvec_htrans_meat.hpp" + #include "armadillo_bits/field_meat.hpp" #include "armadillo_bits/subview_meat.hpp" #include "armadillo_bits/subview_elem1_meat.hpp" Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_bones.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_bones.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_bones.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -40,7 +40,7 @@ inline Col(const std::initializer_list& list); inline const Col& operator=(const std::initializer_list& list); #endif - + inline explicit Col(const SpCol& X); inline const Col& operator=(const eT val); @@ -91,11 +91,11 @@ template inline void insert_rows(const uword row_num, const Base& X); - arma_inline arma_warn_unused eT& at(const uword i); - arma_inline arma_warn_unused eT at(const uword i) const; + arma_inline arma_warn_unused eT& at(const uword i); + arma_inline arma_warn_unused const eT& at(const uword i) const; - arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); - arma_inline arma_warn_unused eT at(const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); + arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; typedef eT* row_iterator; @@ -133,7 +133,7 @@ static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); - arma_aligned eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; + arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; arma_inline void change_to_row(); @@ -182,18 +182,20 @@ arma_inline const Op< Col_fixed_type, op_htrans > ht() const; arma_inline const Op< Col_fixed_type, op_strans > st() const; - arma_inline arma_warn_unused eT& operator[] (const uword i); - arma_inline arma_warn_unused eT operator[] (const uword i) const; - arma_inline arma_warn_unused eT& at (const uword i); - arma_inline arma_warn_unused eT at (const uword i) const; - arma_inline arma_warn_unused eT& operator() (const uword i); - arma_inline arma_warn_unused eT operator() (const uword i) const; + arma_inline arma_warn_unused const eT& at_alt (const uword i) const; - arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); - arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col) const; - arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); - arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT& operator[] (const uword i); + arma_inline arma_warn_unused const eT& operator[] (const uword i) const; + arma_inline arma_warn_unused eT& at (const uword i); + arma_inline arma_warn_unused const eT& at (const uword i) const; + arma_inline arma_warn_unused eT& operator() (const uword i); + arma_inline arma_warn_unused const eT& operator() (const uword i) const; + arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); + arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); + arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Col_meat.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,5 +1,5 @@ -// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) -// Copyright (C) 2008-2012 Conrad Sanderson +// Copyright (C) 2008-2013 NICTA (www.nicta.com.au) +// Copyright (C) 2008-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -413,7 +413,7 @@ eT& Col::row(const uword row_num) { - arma_debug_check( (row_num >= Mat::n_rows), "Col::row(): out of bounds" ); + arma_debug_check( (row_num >= Mat::n_rows), "Col::row(): index out of bounds" ); return access::rw(Mat::mem[row_num]); } @@ -425,7 +425,7 @@ eT Col::row(const uword row_num) const { - arma_debug_check( (row_num >= Mat::n_rows), "Col::row(): out of bounds" ); + arma_debug_check( (row_num >= Mat::n_rows), "Col::row(): index out of bounds" ); return Mat::mem[row_num]; } @@ -572,7 +572,7 @@ { arma_extra_debug_sigprint(); - arma_debug_check( row_num >= Mat::n_rows, "Col::shed_row(): out of bounds"); + arma_debug_check( row_num >= Mat::n_rows, "Col::shed_row(): index out of bounds"); shed_rows(row_num, row_num); } @@ -631,7 +631,7 @@ const uword B_n_rows = t_n_rows - row_num; // insertion at row_num == n_rows is in effect an append operation - arma_debug_check( (row_num > t_n_rows), "Col::insert_rows(): out of bounds"); + arma_debug_check( (row_num > t_n_rows), "Col::insert_rows(): index out of bounds"); if(N > 0) { @@ -690,7 +690,7 @@ template arma_inline arma_warn_unused -eT +const eT& Col::at(const uword i) const { return Mat::mem[i]; @@ -712,7 +712,7 @@ template arma_inline arma_warn_unused -eT +const eT& Col::at(const uword in_row, const uword) const { return Mat::mem[in_row]; @@ -1060,6 +1060,28 @@ template arma_inline arma_warn_unused +const eT& +Col::fixed::at_alt(const uword ii) const + { + #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) + + return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; + + #else + const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; + + memory::mark_as_aligned(mem_aligned); + + return mem_aligned[ii]; + #endif + } + + + +template +template +arma_inline +arma_warn_unused eT& Col::fixed::operator[] (const uword ii) { @@ -1072,7 +1094,7 @@ template arma_inline arma_warn_unused -eT +const eT& Col::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; @@ -1096,7 +1118,7 @@ template arma_inline arma_warn_unused -eT +const eT& Col::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; @@ -1111,7 +1133,7 @@ eT& Col::fixed::operator() (const uword ii) { - arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): out of bounds"); + arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } @@ -1122,10 +1144,10 @@ template arma_inline arma_warn_unused -eT +const eT& Col::fixed::operator() (const uword ii) const { - arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): out of bounds"); + arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } @@ -1148,7 +1170,7 @@ template arma_inline arma_warn_unused -eT +const eT& Col::fixed::at(const uword in_row, const uword) const { return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; @@ -1163,7 +1185,7 @@ eT& Col::fixed::operator() (const uword in_row, const uword in_col) { - arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): out of bounds" ); + arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } @@ -1174,10 +1196,10 @@ template arma_inline arma_warn_unused -eT +const eT& Col::fixed::operator() (const uword in_row, const uword in_col) const { - arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): out of bounds" ); + arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_bones.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_bones.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_bones.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -46,8 +46,8 @@ arma_aligned const eT* const mem; //!< pointer to the memory used by the cube (memory is read-only) protected: - arma_aligned Mat* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; - arma_aligned eT mem_local[ Cube_prealloc::mem_n_elem ]; + arma_aligned Mat* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; + arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; public: @@ -159,21 +159,23 @@ template inline const Cube& operator/=(const mtGlueCube& X); - arma_inline arma_warn_unused eT& operator[] (const uword i); - arma_inline arma_warn_unused eT operator[] (const uword i) const; + arma_inline arma_warn_unused const eT& at_alt (const uword i) const; - arma_inline arma_warn_unused eT& at(const uword i); - arma_inline arma_warn_unused eT at(const uword i) const; + arma_inline arma_warn_unused eT& operator[] (const uword i); + arma_inline arma_warn_unused const eT& operator[] (const uword i) const; - arma_inline arma_warn_unused eT& operator() (const uword i); - arma_inline arma_warn_unused eT operator() (const uword i) const; + arma_inline arma_warn_unused eT& at(const uword i); + arma_inline arma_warn_unused const eT& at(const uword i) const; - arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); - arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline arma_warn_unused eT& operator() (const uword i); + arma_inline arma_warn_unused const eT& operator() (const uword i) const; - arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); - arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); + arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); + arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline const Cube& operator++(); arma_inline void operator++(int); @@ -331,8 +333,8 @@ static const bool use_extra = (fixed_n_elem > Cube_prealloc::mem_n_elem); - arma_aligned Mat* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ]; - arma_aligned eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ]; + arma_aligned Mat* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ]; + arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ]; arma_inline void mem_setup(); @@ -356,20 +358,20 @@ using Cube::operator(); - arma_inline arma_warn_unused eT& operator[] (const uword i); - arma_inline arma_warn_unused eT operator[] (const uword i) const; + arma_inline arma_warn_unused eT& operator[] (const uword i); + arma_inline arma_warn_unused const eT& operator[] (const uword i) const; - arma_inline arma_warn_unused eT& at (const uword i); - arma_inline arma_warn_unused eT at (const uword i) const; + arma_inline arma_warn_unused eT& at (const uword i); + arma_inline arma_warn_unused const eT& at (const uword i) const; - arma_inline arma_warn_unused eT& operator() (const uword i); - arma_inline arma_warn_unused eT operator() (const uword i) const; + arma_inline arma_warn_unused eT& operator() (const uword i); + arma_inline arma_warn_unused const eT& operator() (const uword i) const; - arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); - arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); + arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; - arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); - arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col, const uword in_slice) const; + arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); + arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; }; Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Cube_meat.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -978,7 +978,7 @@ { arma_extra_debug_sigprint(); - arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): out of bounds"); + arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): index out of bounds"); shed_slices(slice_num, slice_num); } @@ -1034,7 +1034,7 @@ const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation - arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds"); + arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); if(N > 0) { @@ -1087,12 +1087,12 @@ const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation - arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): out of bounds"); + arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); arma_debug_check ( ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ), - "Cube::insert_slices(): given object has an incompatible dimensions" + "Cube::insert_slices(): given object has incompatible dimensions" ); if(N > 0) @@ -1908,6 +1908,21 @@ +//! linear element accessor (treats the cube as a vector); no bounds check; assumes memory is aligned +template +arma_inline +arma_warn_unused +const eT& +Cube::at_alt(const uword i) const + { + const eT* mem_aligned = mem; + memory::mark_as_aligned(mem_aligned); + + return mem_aligned[i]; + } + + + //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline @@ -1925,7 +1940,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds"); @@ -1949,7 +1964,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::operator[] (const uword i) const { return mem[i]; @@ -1973,7 +1988,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::at(const uword i) const { return mem[i]; @@ -2006,7 +2021,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check @@ -2039,7 +2054,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::at(const uword in_row, const uword in_col, const uword in_slice) const { return mem[in_slice*n_elem_slice + in_col*n_rows + in_row]; @@ -2774,6 +2789,10 @@ case ppm_binary: save_okay = diskio::save_ppm_binary(*this, name); break; + + case hdf5_binary: + save_okay = diskio::save_hdf5_binary(*this, name); + break; default: arma_warn(print_status, "Cube::save(): unsupported file type"); @@ -2867,6 +2886,10 @@ case ppm_binary: load_okay = diskio::load_ppm_binary(*this, name, err_msg); break; + + case hdf5_binary: + load_okay = diskio::load_hdf5_binary(*this, name, err_msg); + break; default: arma_warn(print_status, "Cube::load(): unsupported file type"); @@ -3292,7 +3315,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::fixed::operator[] (const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; @@ -3316,7 +3339,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::fixed::at(const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; @@ -3331,7 +3354,7 @@ eT& Cube::fixed::operator() (const uword i) { - arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): out of bounds"); + arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } @@ -3342,10 +3365,10 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::fixed::operator() (const uword i) const { - arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): out of bounds"); + arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } @@ -3370,7 +3393,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::fixed::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; @@ -3393,7 +3416,7 @@ (in_col >= fixed_n_cols ) || (in_slice >= fixed_n_slices) , - "Cube::operator(): index out of bounds" + "operator(): index out of bounds" ); const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; @@ -3407,7 +3430,7 @@ template arma_inline arma_warn_unused -eT +const eT& Cube::fixed::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_bones.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_bones.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_bones.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,5 +1,5 @@ -// Copyright (C) 2011 NICTA (www.nicta.com.au) -// Copyright (C) 2011 Conrad Sanderson +// Copyright (C) 2011-2013 NICTA (www.nicta.com.au) +// Copyright (C) 2011-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -32,6 +32,7 @@ arma_inline eT operator[] (const uword i) const; arma_inline eT at (const uword row, const uword col, const uword slice) const; + arma_inline eT at_alt (const uword i) const; inline void apply (Cube& out) const; inline void apply_inplace_plus (Cube& out) const; Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_meat.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_meat.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/GenCube_meat.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,5 +1,5 @@ -// Copyright (C) 2011 NICTA (www.nicta.com.au) -// Copyright (C) 2011 Conrad Sanderson +// Copyright (C) 2011-2013 NICTA (www.nicta.com.au) +// Copyright (C) 2011-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -67,6 +67,16 @@ template +arma_inline +eT +GenCube::at_alt(const uword) const + { + return GenCube::generate(); + } + + + +template inline void GenCube::apply(Cube& out) const Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_bones.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_bones.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_bones.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,5 +1,5 @@ -// Copyright (C) 2011-2012 NICTA (www.nicta.com.au) -// Copyright (C) 2011-2012 Conrad Sanderson +// Copyright (C) 2011-2013 NICTA (www.nicta.com.au) +// Copyright (C) 2011-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -34,6 +34,7 @@ arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; + arma_inline elem_type at_alt (const uword ii) const; inline void apply (Mat& out) const; inline void apply_inplace_plus (Mat& out) const; Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_meat.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_meat.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Gen_meat.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -1,5 +1,5 @@ -// Copyright (C) 2011-2012 NICTA (www.nicta.com.au) -// Copyright (C) 2011-2012 Conrad Sanderson +// Copyright (C) 2011-2013 NICTA (www.nicta.com.au) +// Copyright (C) 2011-2013 Conrad Sanderson // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -86,6 +86,16 @@ template +arma_inline +typename T1::elem_type +Gen::at_alt(const uword ii) const + { + return operator[](ii); + } + + + +template inline void Gen::apply(Mat& out) const Modified: pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp =================================================================== --- pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp 2013-05-31 09:25:26 UTC (rev 4327) +++ pkg/RcppArmadillo/inst/include/armadillo_bits/Mat_bones.hpp 2013-06-05 00:03:18 UTC (rev 4328) @@ -40,7 +40,7 @@ arma_aligned const eT* const mem; //!< pointer to the memory used by the matrix (memory is read-only) protected: - arma_aligned eT mem_local[ arma_config::mat_prealloc ]; + arma_align_mem eT mem_local[ arma_config::mat_prealloc ]; public: @@ -99,7 +99,11 @@ inline const Mat& operator*=(const subview& X); inline const Mat& operator%=(const subview& X); inline const Mat& operator/=(const subview& X); - + + inline Mat(const subview_row_strans& X); // subview_row_strans can only be generated by the Proxy class + inline Mat(const subview_row_htrans& X); // subview_row_htrans can only be generated by the Proxy class + inline Mat(const xvec_htrans& X); // xvec_htrans can only be generated by the Proxy class + //inline explicit Mat(const subview_cube& X); inline Mat(const subview_cube& X); inline const Mat& operator=(const subview_cube& X); @@ -291,18 +295,20 @@ template inline const Mat& operator/=(const mtGlue& X); - arma_inline arma_warn_unused eT& operator[] (const uword ii); - arma_inline arma_warn_unused eT operator[] (const uword ii) const; - arma_inline arma_warn_unused eT& at (const uword ii); - arma_inline arma_warn_unused eT at (const uword ii) const; - arma_inline arma_warn_unused eT& operator() (const uword ii); - arma_inline arma_warn_unused eT operator() (const uword ii) const; + arma_inline arma_warn_unused const eT& at_alt (const uword ii) const; - arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); - arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col) const; - arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); - arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT& operator[] (const uword ii); + arma_inline arma_warn_unused const eT& operator[] (const uword ii) const; + arma_inline arma_warn_unused eT& at (const uword ii); + arma_inline arma_warn_unused const eT& at (const uword ii) const; + arma_inline arma_warn_unused eT& operator() (const uword ii); + arma_inline arma_warn_unused const eT& operator() (const uword ii) const; + arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); + arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; + arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); + arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; + arma_inline const Mat& operator++(); arma_inline void operator++(int); @@ -541,7 +547,7 @@ static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols; static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); - arma_aligned eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; + arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; public: @@ -581,18 +587,20 @@ arma_inline const Op< Mat_fixed_type, op_htrans > ht() const; arma_inline const Op< Mat_fixed_type, op_strans > st() const; - arma_inline arma_warn_unused eT& operator[] (const uword i); - arma_inline arma_warn_unused eT operator[] (const uword i) const; - arma_inline arma_warn_unused eT& at (const uword i); - arma_inline arma_warn_unused eT at (const uword i) const; [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4328 From noreply at r-forge.r-project.org Wed Jun 5 13:29:19 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 13:29:19 +0200 (CEST) Subject: [Rcpp-commits] r4329 - in pkg/RcppArmadillo: . debian inst Message-ID: <20130605112919.A94C7184BB4@r-forge.r-project.org> Author: edd Date: 2013-06-05 13:29:19 +0200 (Wed, 05 Jun 2013) New Revision: 4329 Modified: pkg/RcppArmadillo/DESCRIPTION pkg/RcppArmadillo/debian/control pkg/RcppArmadillo/inst/NEWS.Rd Log: three minor metadata updates that should have been in 0.3.900.0 Modified: pkg/RcppArmadillo/DESCRIPTION =================================================================== --- pkg/RcppArmadillo/DESCRIPTION 2013-06-05 00:03:18 UTC (rev 4328) +++ pkg/RcppArmadillo/DESCRIPTION 2013-06-05 11:29:19 UTC (rev 4329) @@ -21,7 +21,7 @@ (due to speed and/or integration capabilities), rather than another language. . The RcppArmadillo package includes the header files from the templated - Armadillo library (currently version 3.820). Thus users do not need to + Armadillo library (currently version 3.900.0). Thus users do not need to install Armadillo itself in order to use RcppArmadillo. . This Armadillo integration provides a nice illustration of the Modified: pkg/RcppArmadillo/debian/control =================================================================== --- pkg/RcppArmadillo/debian/control 2013-06-05 00:03:18 UTC (rev 4328) +++ pkg/RcppArmadillo/debian/control 2013-06-05 11:29:19 UTC (rev 4329) @@ -25,7 +25,7 @@ (due to speed and/or integration capabilities), rather than another language. . The RcppArmadillo package includes the header files from the templated - Armadillo library (currently version 3.810.0). Thus users do not need to + Armadillo library (currently version 3.900.0). Thus users do not need to install Armadillo itself in order to use RcppArmadillo. . This Armadillo integration provides a nice illustration of the Modified: pkg/RcppArmadillo/inst/NEWS.Rd =================================================================== --- pkg/RcppArmadillo/inst/NEWS.Rd 2013-06-05 00:03:18 UTC (rev 4328) +++ pkg/RcppArmadillo/inst/NEWS.Rd 2013-06-05 11:29:19 UTC (rev 4329) @@ -17,6 +17,8 @@ \item faster handling of compound expressions with transposes of complex vectors } + \item Kalman filter example switched from inline to \code{sourceCpp}, + which simplifies / streamlines the C++ side a little } } From noreply at r-forge.r-project.org Wed Jun 5 16:25:55 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 16:25:55 +0200 (CEST) Subject: [Rcpp-commits] r4330 - in pkg/Rcpp: . inst inst/include/Rcpp/api/meat inst/unitTests inst/unitTests/cpp Message-ID: <20130605142555.DD8DD185363@r-forge.r-project.org> Author: romain Date: 2013-06-05 16:25:55 +0200 (Wed, 05 Jun 2013) New Revision: 4330 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h pkg/Rcpp/inst/unitTests/cpp/Vector.cpp pkg/Rcpp/inst/unitTests/runit.Vector.R Log: fixed Vector<>::erase( iterator, iterator ) Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-05 11:29:19 UTC (rev 4329) +++ pkg/Rcpp/ChangeLog 2013-06-05 14:25:55 UTC (rev 4330) @@ -1,3 +1,9 @@ +2013-06-05 Romain Francois + + * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator) + * unitTests/cpp/Vector.cpp : added regression test for the above fix + * unitTests/runit.Vector.R : added regression test for the above fix + 2013-05-31 Romain Francois * unitTests/runit.sugar.R : new test for is_infinite and is_nan Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-05 11:29:19 UTC (rev 4329) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-05 14:25:55 UTC (rev 4330) @@ -24,6 +24,9 @@ \item The \code{operator-()} semantics for \code{Date} and \code{Datetime} are now more inline with standard C++ behaviour. \item RNGScope counter now uses unsigned long rather than int. + \item \code{Vector<*>::erase(iterator, iterator)} was fixed. Now it does + not remove the element pointed by last (similar to what is done on stl types + and what was intended initially). Reported on Rcpp-devel by Toni Giorgino. } \item Changes in Rcpp sugar: \itemize{ Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 11:29:19 UTC (rev 4329) +++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 14:25:55 UTC (rev 4330) @@ -285,7 +285,7 @@ iterator it = begin() ; iterator this_end = end() ; - int nremoved = std::distance(first,last)+1 ; + int nremoved = std::distance(first,last) ; int target_size = size() - nremoved ; Vector target( target_size ) ; iterator target_it = target.begin() ; @@ -297,7 +297,7 @@ *target_it = *it ; } result = it ; - for( it = last +1 ; it < this_end; ++it, ++target_it ){ + for( it = last ; it < this_end; ++it, ++target_it ){ *target_it = *it ; } } else{ @@ -308,7 +308,7 @@ SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ); } result = it ; - for( it = last +1 ; it < this_end; ++it, ++target_it, i++ ){ + for( it = last ; it < this_end; ++it, ++target_it, i++ ){ *target_it = *it ; SET_STRING_ELT( newnames, i, STRING_ELT(names, i + nremoved ) ); } Modified: pkg/Rcpp/inst/unitTests/cpp/Vector.cpp =================================================================== --- pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-05 11:29:19 UTC (rev 4329) +++ pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-05 14:25:55 UTC (rev 4330) @@ -219,6 +219,13 @@ } // [[Rcpp::export]] +List integer_erase_range( IntegerVector x, IntegerVector y ){ + x.erase(x.begin()+5, x.end()-1 ); + y.erase(y.begin()+5, y.end()-1 ); + return List::create( x, y ) ; +} + +// [[Rcpp::export]] IntegerVector integer_erase2( IntegerVector y ){ y.erase(1,2) ; return y ; @@ -382,7 +389,7 @@ // [[Rcpp::export]] List list_erase_range( List list ){ - list.erase( 0, 1 ) ; + list.erase( 0, 2 ) ; return list ; } Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R =================================================================== --- pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-05 11:29:19 UTC (rev 4329) +++ pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-05 14:25:55 UTC (rev 4330) @@ -211,15 +211,25 @@ checkEquals( fun(x), target, msg = "IntegerVector erase" ) } +test.IntegerVector.erase.range <- function(){ + x <- y <- 1:10 + names(y) <- letters[1:10] + res <- integer_erase_range( x, y ) + checkEquals( res[[1L]], c(1:5, 10L) , msg = "IntegerVector erase range unnamed" ) + + z <- y[-(6:9)] + checkEquals( res[[2L]], z , msg = "IntegerVector erase range named" ) +} + test.IntegerVector.erase2 <- function(){ fun <- integer_erase2 - checkEquals( fun(1:4), c(1L, 4L), msg = "IntegerVector erase2" ) + checkEquals( fun(1:4), c(1L, 3L, 4L), msg = "IntegerVector erase2" ) x <- 1:4 names(x) <- letters[1:4] - target <- c(1L, 4L) - names(target) <- c( "a", "d" ) + target <- c(1L, 3L, 4L) + names(target) <- c( "a", "c", "d" ) checkEquals( fun(x), target, msg = "IntegerVector erase2" ) } From noreply at r-forge.r-project.org Wed Jun 5 16:29:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 16:29:25 +0200 (CEST) Subject: [Rcpp-commits] r4331 - in pkg/Rcpp: . inst/include/Rcpp/module Message-ID: <20130605142925.2B184184B7B@r-forge.r-project.org> Author: romain Date: 2013-06-05 16:29:24 +0200 (Wed, 05 Jun 2013) New Revision: 4331 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/module/class.h Log: removed useless typedef Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-05 14:25:55 UTC (rev 4330) +++ pkg/Rcpp/ChangeLog 2013-06-05 14:29:24 UTC (rev 4331) @@ -3,6 +3,7 @@ * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator) * unitTests/cpp/Vector.cpp : added regression test for the above fix * unitTests/runit.Vector.R : added regression test for the above fix + * include/Rcpp/module/class.h : removed useless typedef 2013-05-31 Romain Francois Modified: pkg/Rcpp/inst/include/Rcpp/module/class.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/module/class.h 2013-06-05 14:25:55 UTC (rev 4330) +++ pkg/Rcpp/inst/include/Rcpp/module/class.h 2013-06-05 14:29:24 UTC (rev 4331) @@ -2,7 +2,7 @@ // // class.h: Rcpp R/C++ interface class library -- Rcpp modules // -// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -492,7 +492,6 @@ // importing properties - typedef typename parent_class_::prop_class parent_prop_class ; typedef typename parent_class_::PROPERTY_MAP parent_PROPERTY_MAP ; typedef typename parent_PROPERTY_MAP::iterator parent_PROPERTY_MAP_iterator ; From noreply at r-forge.r-project.org Wed Jun 5 17:11:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 17:11:02 +0200 (CEST) Subject: [Rcpp-commits] r4332 - pkg/Rcpp/inst/include/Rcpp/api/meat Message-ID: <20130605151102.249A0185505@r-forge.r-project.org> Author: romain Date: 2013-06-05 17:11:01 +0200 (Wed, 05 Jun 2013) New Revision: 4332 Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h Log: fixed bounds checks Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 14:29:24 UTC (rev 4331) +++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 15:11:01 UTC (rev 4332) @@ -239,7 +239,7 @@ template typename Vector::iterator Vector::erase_single__impl( iterator position ){ - if( position < begin() || position >= end() ) throw index_out_of_bounds( ) ; + if( position < begin() || position > end() ) throw index_out_of_bounds( ) ; int n = size() ; Vector target( n - 1 ) ; iterator target_it(target.begin()) ; @@ -281,7 +281,7 @@ template typename Vector::iterator Vector::erase_range__impl( iterator first, iterator last ){ if( first > last ) throw std::range_error("invalid range") ; - if( last >= end() || first < begin() ) throw index_out_of_bounds() ; + if( last > end() || first < begin() ) throw index_out_of_bounds() ; iterator it = begin() ; iterator this_end = end() ; @@ -296,7 +296,7 @@ for( ; it < first; ++it, ++target_it ){ *target_it = *it ; } - result = it ; + result = target_it +1 ; for( it = last ; it < this_end; ++it, ++target_it ){ *target_it = *it ; } @@ -307,7 +307,7 @@ *target_it = *it ; SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ); } - result = it ; + result = target_it + 1 ; for( it = last ; it < this_end; ++it, ++target_it, i++ ){ *target_it = *it ; SET_STRING_ELT( newnames, i, STRING_ELT(names, i + nremoved ) ); From noreply at r-forge.r-project.org Wed Jun 5 18:51:58 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Jun 2013 18:51:58 +0200 (CEST) Subject: [Rcpp-commits] r4333 - in pkg/Rcpp: . inst/include/Rcpp/api/meat Message-ID: <20130605165158.6BCE3185146@r-forge.r-project.org> Author: romain Date: 2013-06-05 18:51:58 +0200 (Wed, 05 Jun 2013) New Revision: 4333 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h Log: correct return value of erase Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-05 15:11:01 UTC (rev 4332) +++ pkg/Rcpp/ChangeLog 2013-06-05 16:51:58 UTC (rev 4333) @@ -1,6 +1,7 @@ 2013-06-05 Romain Francois * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator) + and correct return value of erase * unitTests/cpp/Vector.cpp : added regression test for the above fix * unitTests/runit.Vector.R : added regression test for the above fix * include/Rcpp/module/class.h : removed useless typedef Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 15:11:01 UTC (rev 4332) +++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h 2013-06-05 16:51:58 UTC (rev 4333) @@ -247,16 +247,16 @@ iterator this_end(end()) ; SEXP names = RCPP_GET_NAMES(RObject::m_sexp) ; if( names == R_NilValue ){ - for( ; it < position; ++it, ++target_it){ + int i=0; + for( ; it < position; ++it, ++target_it, i++){ *target_it = *it; } - iterator result(target_it) ; ++it ; for( ; it < this_end ; ++it, ++target_it){ *target_it = *it; } set_sexp( target.asSexp() ) ; - return result ; + return begin()+i ; } else { SEXP newnames = PROTECT(::Rf_allocVector( STRSXP, n-1 )); int i= 0 ; @@ -264,7 +264,7 @@ *target_it = *it; SET_STRING_ELT( newnames, i , STRING_ELT(names,i) ) ; } - iterator result(target_it) ; + int result=i ; ++it ; i++ ; for( ; it < this_end ; ++it, ++target_it, i++){ @@ -274,7 +274,7 @@ target.attr( "names" ) = newnames ; UNPROTECT(1) ; /* newnames */ set_sexp( target.asSexp() ) ; - return result ; + return begin()+result ; } } @@ -293,10 +293,11 @@ SEXP names = RCPP_GET_NAMES(RObject::m_sexp) ; iterator result ; if( names == R_NilValue ){ - for( ; it < first; ++it, ++target_it ){ + int i=0; + for( ; it < first; ++it, ++target_it, i++ ){ *target_it = *it ; } - result = target_it +1 ; + result = begin() + i + 1 ; for( it = last ; it < this_end; ++it, ++target_it ){ *target_it = *it ; } @@ -307,7 +308,7 @@ *target_it = *it ; SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ); } - result = target_it + 1 ; + result = begin() + i + 1 ; for( it = last ; it < this_end; ++it, ++target_it, i++ ){ *target_it = *it ; SET_STRING_ELT( newnames, i, STRING_ELT(names, i + nremoved ) ); From noreply at r-forge.r-project.org Thu Jun 6 11:11:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 6 Jun 2013 11:11:03 +0200 (CEST) Subject: [Rcpp-commits] r4334 - in pkg/Rcpp: . inst/unitTests inst/unitTests/cpp Message-ID: <20130606091103.7854118589B@r-forge.r-project.org> Author: romain Date: 2013-06-06 11:11:03 +0200 (Thu, 06 Jun 2013) New Revision: 4334 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/unitTests/cpp/Vector.cpp pkg/Rcpp/inst/unitTests/runit.Vector.R Log: more unit tests for erase Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-05 16:51:58 UTC (rev 4333) +++ pkg/Rcpp/ChangeLog 2013-06-06 09:11:03 UTC (rev 4334) @@ -1,3 +1,8 @@ +2013-06-06 Romain Francois + + * unitTests/cpp/Vector.cpp : more unit tests for erase + * unitTests/runit.Vector.R : more unit tests for erase + 2013-06-05 Romain Francois * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator) Modified: pkg/Rcpp/inst/unitTests/cpp/Vector.cpp =================================================================== --- pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-05 16:51:58 UTC (rev 4333) +++ pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-06 09:11:03 UTC (rev 4334) @@ -226,6 +226,33 @@ } // [[Rcpp::export]] +List integer_erase_range_2( IntegerVector x, IntegerVector y ){ + IntegerVector::iterator it = x.begin()+1 ; + while( it != x.end() ){ + it = x.erase(it) ; + } + it = y.begin() + 1 ; + while( it != y.end() ){ + it = y.erase(it) ; + } + return List::create( x, y ) ; +} + +// [[Rcpp::export]] +List List_erase_range_2( List x, List y ){ + List::iterator it = x.begin()+1 ; + while( it != x.end() ){ + it = x.erase(it) ; + } + it = y.begin() + 1 ; + while( it != y.end() ){ + it = y.erase(it) ; + } + return List::create( x, y ) ; +} + + +// [[Rcpp::export]] IntegerVector integer_erase2( IntegerVector y ){ y.erase(1,2) ; return y ; Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R =================================================================== --- pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-05 16:51:58 UTC (rev 4333) +++ pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-06 09:11:03 UTC (rev 4334) @@ -221,9 +221,25 @@ checkEquals( res[[2L]], z , msg = "IntegerVector erase range named" ) } +test.IntegerVector.erase.range.2 <- function(){ + x <- y <- 1:10 + names(y) <- letters[1:10] + res <- integer_erase_range_2( x, y ) + checkEquals( res[[1L]], 1L , msg = "IntegerVector erase range 2 unnamed" ) + checkEquals( res[[2L]], c("a" = 1L ) , msg = "IntegerVector erase range 2 named" ) +} + + +test.IntegerVector.erase.range.2 <- function(){ + x <- y <- as.list(1:10) + names(y) <- letters[1:10] + res <- List_erase_range_2( x, y ) + checkEquals( res[[1L]], list( 1L ) , msg = "List erase range 2 unnamed" ) + checkEquals( res[[2L]], list("a" = 1L ) , msg = "List erase range 2 named" ) +} + test.IntegerVector.erase2 <- function(){ - fun <- integer_erase2 - checkEquals( fun(1:4), c(1L, 3L, 4L), msg = "IntegerVector erase2" ) + checkEquals( integer_erase2(1:4), c(1L, 3L, 4L), msg = "IntegerVector erase2" ) x <- 1:4 names(x) <- letters[1:4] @@ -231,7 +247,7 @@ target <- c(1L, 3L, 4L) names(target) <- c( "a", "c", "d" ) - checkEquals( fun(x), target, msg = "IntegerVector erase2" ) + checkEquals( integer_erase2(x), target, msg = "IntegerVector erase2" ) } test.IntegerVector.fill <- function(){ From noreply at r-forge.r-project.org Sat Jun 8 23:06:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 8 Jun 2013 23:06:07 +0200 (CEST) Subject: [Rcpp-commits] r4335 - in pkg/Rcpp: . inst inst/doc Message-ID: <20130608210607.732511858B4@r-forge.r-project.org> Author: edd Date: 2013-06-08 23:06:07 +0200 (Sat, 08 Jun 2013) New Revision: 4335 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/DESCRIPTION pkg/Rcpp/inst/CITATION pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/THANKS pkg/Rcpp/inst/doc/Rcpp.bib Log: added two entries to THANKS updated Rcpp.bib and CITATION white-space correction in ChangeLog and NEWS rolled Version in DESCRIPTION one more time Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/ChangeLog 2013-06-08 21:06:07 UTC (rev 4335) @@ -1,37 +1,44 @@ -2013-06-06 Romain Francois +2013-06-08 Dirk Eddelbuettel + * inst/doc/Rcpp.bib: Updated entries + +2013-06-06 Romain Francois + * unitTests/cpp/Vector.cpp : more unit tests for erase * unitTests/runit.Vector.R : more unit tests for erase - -2013-06-05 Romain Francois - * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator) - and correct return value of erase +2013-06-05 Romain Francois + + * include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, + iterator) and correct return value of erase * unitTests/cpp/Vector.cpp : added regression test for the above fix * unitTests/runit.Vector.R : added regression test for the above fix * include/Rcpp/module/class.h : removed useless typedef - -2013-05-31 Romain Francois +2013-05-31 Romain Francois + * unitTests/runit.sugar.R : new test for is_infinite and is_nan * unitTests/cpp/sugar.cpp : new test for is_infinite and is_nan - * include/Rcpp/sugar/functions/is_infinite.h : new function is_infinite + * include/Rcpp/sugar/functions/is_infinite.h : new function + is_infinite * include/Rcpp/traits/is_infinite.h : new function is_infinite * include/Rcpp/sugar/functions/is_nan.h : new function is_nan * include/Rcpp/traits/is_nan.h : new function is_nan - -2013-05-30 Romain Francois - * include/Rcpp/sugar/functions/all.h : bug fixed for the NA=false case +2013-05-30 Romain Francois + + * include/Rcpp/sugar/functions/all.h : bug fixed for the NA=false + case * include/Rcpp/sugar/functions/is_na.h : header - * include/Rcpp/sugar/functions/is_finite.h : added sugar is_finite function + * include/Rcpp/sugar/functions/is_finite.h : added sugar is_finite + function * include/Rcpp/traits/is_finite.h : added is_finite trait * unitTests/runit.sugar.R : added test for is_finite * unitTests/cpp/S4.cpp : new cpp file to host S4 unit tests * unitTests/runit.S4.R : rework unit tests to use attributes * unitTests/runit.Reference.R : unit tests for Rcpp::Reference * unitTests/cpp/Reference.cpp : unit tests c++ code - + 2013-05-26 Dirk Eddelbuettel * src/api.cpp: Minor tweak for internal formatting @@ -50,14 +57,15 @@ 2013-05-17 J.J. Allaire * src/attributes.cpp: prevent gc problems with RNGScope destructor - in attributes generated functions; don't include package header file - in generated cpp exports file + in attributes generated functions; don't include package header + file in generated cpp exports file * src/api.cpp: use unsigned long for RNG scope counter 2013-04-28 Dirk Eddelbuettel * src/api.cpp (Rcpp): No longer use Rd_format(Real|Complex) which is - a very verboten R internal; formatting to string is now very bare bones + a very verboten R internal; formatting to string is now very bare + bones 2013-04-27 Dirk Eddelbuettel @@ -66,10 +74,11 @@ 2013-04-16 Romain Francois - * include/Rcpp/sugar/functions/na_omit.h : new function na_omit to remove - missing values from a vector. + * include/Rcpp/sugar/functions/na_omit.h : new function na_omit to + remove missing values from a vector. * src/attributes.cpp : portability fix (from Martyn Plummer) - * include/Rcpp/api/meat/Vector.h : portability fix (from Martyn Plummer) + * include/Rcpp/api/meat/Vector.h : portability fix (from Martyn + Plummer) 2013-04-14 Romain Francois Modified: pkg/Rcpp/DESCRIPTION =================================================================== --- pkg/Rcpp/DESCRIPTION 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/DESCRIPTION 2013-06-08 21:06:07 UTC (rev 4335) @@ -1,6 +1,6 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 0.10.3.3 +Version: 0.10.3.4 Date: $Date$ Author: Dirk Eddelbuettel and Romain Francois, with contributions by Douglas Bates, John Chambers and JJ Allaire @@ -45,6 +45,10 @@ been factored out of Rcpp into the package RcppClassic, and it is still available for code relying on the older interface. New development should always use this Rcpp package instead. + . + Addditional documentation is available via the paper by Eddelbuettel and + Francois (2011, JSS) paper and the book by Eddelbuettel (2013, Springer); + see 'citation("Rcpp")' for details. Depends: R (>= 2.15.1) Imports: methods Suggests: RUnit, inline, rbenchmark Modified: pkg/Rcpp/inst/CITATION =================================================================== --- pkg/Rcpp/inst/CITATION 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/inst/CITATION 2013-06-08 21:06:07 UTC (rev 4335) @@ -12,7 +12,7 @@ url = "http://www.jstatsoft.org/v40/i08/", textVersion = - paste("Dirk Eddelbuettel, Romain Francois (2011).", + paste("Dirk Eddelbuettel and Romain Francois (2011).", "Rcpp: Seamless R and C++ Integration.", "Journal of Statistical Software, 40(8), 1-18.", "URL http://www.jstatsoft.org/v40/i08/.") Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-08 21:06:07 UTC (rev 4335) @@ -22,25 +22,35 @@ to just use \code{List::create} and feed to the \code{DataFrame} constructor \item The \code{operator-()} semantics for \code{Date} and - \code{Datetime} are now more inline with standard C++ behaviour. + \code{Datetime} are now more inline with standard C++ behaviour; + with thanks to Robin Girard for the report. \item RNGScope counter now uses unsigned long rather than int. - \item \code{Vector<*>::erase(iterator, iterator)} was fixed. Now it does - not remove the element pointed by last (similar to what is done on stl types - and what was intended initially). Reported on Rcpp-devel by Toni Giorgino. + \item \code{Vector<*>::erase(iterator, iterator)} was fixed. Now + it does not remove the element pointed by last (similar to what is + done on stl types and what was intended initially). Reported on + Rcpp-devel by Toni Giorgino. } \item Changes in Rcpp sugar: \itemize{ \item New function \code{na_omit} based on the StackOverflow thread - http://stackoverflow.com/questions/15953768/templated-rcpp-function-to-erase-na-values - \item New function \code{is_finite} and \code{is_infinite} that reproduces - the behavior of R's \code{is.finite} and \code{is.infinite} functions + \url{http://stackoverflow.com/questions/15953768/} + \item New function \code{is_finite} and \code{is_infinite} that + reproduces the behavior of R's \code{is.finite} and + \code{is.infinite} functions } \item Changes in Rcpp build tools: \itemize{ - \item Fix (from Martyn Plummer) for solaris in handling SingleLogicalResult. + \item Fix (from Martyn Plummer) for solaris in handling + SingleLogicalResult. \item The \code{src/Makevars} file can now optionally override the path for \code{/usr/bin/install_name_tool} which is used on OS X. } + \item Changes in Rcpp documentation: + \itemize{ + \item Updated the bibliograph in \code{Rcpp.bib} (which is also + sourced by packages using Rcpp). + \item Updated the \code{THANKS} file. + } } } Modified: pkg/Rcpp/inst/THANKS =================================================================== --- pkg/Rcpp/inst/THANKS 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/inst/THANKS 2013-06-08 21:06:07 UTC (rev 4335) @@ -6,6 +6,8 @@ Darren Cook for suggesting to remove exception specifiers Laurent Gautier for helpful discussions on R internals Alistair Gee for a patch making ColDatum more robust +Toni Giorgino for a bug report concerning erase(iter, iter) +Robin Girard for a pointing out that operator+ on Date types was wrong Christian Gunning for a documentation + unit tests patches and reporting bugs Rainer Hurling for help debugging builds issues on FreeBSD Gregor Kastner for noticing a bug in IntegerVector initialization Modified: pkg/Rcpp/inst/doc/Rcpp.bib =================================================================== --- pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-06 09:11:03 UTC (rev 4334) +++ pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-08 21:06:07 UTC (rev 4335) @@ -134,8 +134,8 @@ @Manual{CRAN:Rcpp, title = {{Rcpp}: Seamless {R} and {C++} Integration}, author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, - year = 2012, - note = {R package version 0.10.3}, + year = 2013, + note = {R package version 0.10.4}, url = CRAN # "package=Rcpp" } @@ -145,7 +145,7 @@ author = {Romain Fran\c{c}ois and Dirk Eddelbuettel and Douglas Bates}, year = 2013, - note = {R package version 0.3.800.1}, + note = {R package version 0.3.900.0}, url = CRAN # "package=RcppArmadillo" } @@ -206,8 +206,8 @@ @Manual{CRAN:Rserve, title = {Rserve: Binary R server}, author = {Simon Urbanek}, - year = 2012, - note = {R package version 0.6-8}, + year = 2013, + note = {R package version 0.6-8.1}, url = CRAN # "package=Rserve" } @@ -223,8 +223,8 @@ @Manual{CRAN:highlight, title = {highlight: Syntax highlighter}, author = {Romain Fran\c{c}ois}, - year = 2012, - note = {Archived R package with last version 0.3.2}, + year = 2013, + note = {R package with version 0.4.1}, url = CRAN # "package=highlight" } @@ -242,7 +242,7 @@ title = {\pkg{Matrix}: Sparse and Dense Matrix Classes and Methods}, author = {Douglas Bates and Martin Maechler}, year = 2013, - note = {R package version 1.0-11}, + note = {R package version 1.0-12}, url = CRAN # "package=Matrix" } From noreply at r-forge.r-project.org Sun Jun 9 00:12:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 9 Jun 2013 00:12:54 +0200 (CEST) Subject: [Rcpp-commits] r4336 - in pkg/Rcpp: . inst/doc Message-ID: <20130608221254.8B8A71858B6@r-forge.r-project.org> Author: edd Date: 2013-06-09 00:12:54 +0200 (Sun, 09 Jun 2013) New Revision: 4336 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/doc/Rcpp-introduction.Rnw pkg/Rcpp/inst/doc/Rcpp.bib Log: some cross-referencing Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-08 21:06:07 UTC (rev 4335) +++ pkg/Rcpp/ChangeLog 2013-06-08 22:12:54 UTC (rev 4336) @@ -2,6 +2,9 @@ * inst/doc/Rcpp.bib: Updated entries + * inst/doc/Rcpp-introduction.Rnw: Added pointer to 'Rcpp Attributes' + vignette, as well as to 'Rcpp Sugar' and 'Rcpp Modules' vignettes. + 2013-06-06 Romain Francois * unitTests/cpp/Vector.cpp : more unit tests for erase Modified: pkg/Rcpp/inst/doc/Rcpp-introduction.Rnw =================================================================== --- pkg/Rcpp/inst/doc/Rcpp-introduction.Rnw 2013-06-08 21:06:07 UTC (rev 4335) +++ pkg/Rcpp/inst/doc/Rcpp-introduction.Rnw 2013-06-08 22:12:54 UTC (rev 4336) @@ -107,7 +107,9 @@ This vignette corresponds to the paper published in the \textsl{Journal of Statistical Software}. It is currently still identical to the published paper. Over time, this vignette version may receive minor - updates. For citations, please use the publication \citep{JSS:Rcpp}. + updates. For citations, please use the \cite{JSS:Rcpp} or + \cite{Eddelbuettel:2013:Rcpp}; details are also provided in \proglang{R} via + \texttt{citation("Rcpp")}. This version corresponds to \pkg{Rcpp} version \Sexpr{rcpp.version} and was typeset on \Sexpr{now.date}. @@ -717,6 +719,10 @@ \code{src}---and all this functionality can be used directly from the \proglang{R} prompt making prototyping with \proglang{C++} functions straightforward. +\textsl{Update}: \pkg{Rcpp} version 0.10.0 and later contain new and powerful feature +called 'Rcpp Attributes' which provides an even more powerful mechanism; see +\cite{CRAN:Rcpp:Attributes} for more details. + \section{Using Standard Template Library algorithms} The STL offers a variety of generic @@ -1015,6 +1021,11 @@ functionality for \proglang{Python}. \proglang{C++} classes exposed by \pkg{Rcpp} modules are shadowed by reference classes which have been introduced in \proglang{R} 2.12.0. +\textsl{Update}: Besides the vignettes for '\pkg{Rcpp} Sugar' +\citep{CRAN:Rcpp:Sugar} and '\pkg{Rcpp} Modules' \citep{CRAN:Rcpp:Modules}, +the aforementioned vignette for '\pkg{Rcpp} Attributes' +\citep{CRAN:Rcpp:Attributes} describes a new possibility for even more direct +integration between \proglang{Rcpp} and \proglang{C++}. \section{Summary} Modified: pkg/Rcpp/inst/doc/Rcpp.bib =================================================================== --- pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-08 21:06:07 UTC (rev 4335) +++ pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-08 22:12:54 UTC (rev 4336) @@ -139,6 +139,33 @@ url = CRAN # "package=Rcpp" } + at Manual{CRAN:Rcpp:Attributes, + crossref = {CRAN:Rcpp}, + author = {J. J. Allaire and Dirk Eddelbuettel and Romain Fran\c{c}ois}, + title = {{Rcpp} Attributes}, + year = 2013, + note = {Vignette included in R package Rcpp}, + url = CRAN # "package=Rcpp" +} + + at Manual{CRAN:Rcpp:Modules, + crossref = {CRAN:Rcpp}, + author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, + title = {Exposing {C++} functions and classes with {Rcpp} modules}, + year = 2013, + note = {Vignette included in R package Rcpp}, + url = CRAN # "package=Rcpp" +} + + at Manual{CRAN:Rcpp:Sugar, + crossref = {CRAN:Rcpp}, + author = {Dirk Eddelbuettel and Romain Fran\c{c}ois}, + title = {{Rcpp} syntactic sugar}, + year = 2013, + note = {Vignette included in R package Rcpp}, + url = CRAN # "package=Rcpp" +} + @Manual{CRAN:RcppArmadillo, title = {RcppArmadillo: Rcpp integration for Armadillo templated linear algebra library}, From noreply at r-forge.r-project.org Sun Jun 9 00:51:13 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 9 Jun 2013 00:51:13 +0200 (CEST) Subject: [Rcpp-commits] r4337 - in pkg/Rcpp: . inst/doc/Rcpp-FAQ Message-ID: <20130608225113.DBD1A184FFB@r-forge.r-project.org> Author: edd Date: 2013-06-09 00:51:13 +0200 (Sun, 09 Jun 2013) New Revision: 4337 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw Log: some cross-referencing to Attributes Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-08 22:12:54 UTC (rev 4336) +++ pkg/Rcpp/ChangeLog 2013-06-08 22:51:13 UTC (rev 4337) @@ -4,6 +4,7 @@ * inst/doc/Rcpp-introduction.Rnw: Added pointer to 'Rcpp Attributes' vignette, as well as to 'Rcpp Sugar' and 'Rcpp Modules' vignettes. + * inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Idem 2013-06-06 Romain Francois @@ -1513,7 +1514,7 @@ This covered svn revisions 3264 to 3308. * DESCRIPTION: Remove (for now) Depends: on int64 - * inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Dito for int64_t example + * inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Ditto for int64_t example * inst/unitTests/runit.Module.client.package.R: On Windows, deactivate 'test.Module.package' Modified: pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw =================================================================== --- pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw 2013-06-08 22:12:54 UTC (rev 4336) +++ pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw 2013-06-08 22:51:13 UTC (rev 4337) @@ -72,7 +72,7 @@ \subsection{How do I get started ?} -Please execute the following command in \proglang{R} +If you have \pkg{Rcpp} installed, please execute the following command in \proglang{R} <>= vignette( "Rcpp-introduction" ) @@ -80,6 +80,9 @@ \noindent to access the vignette which provides a detailed introduction. +If you do not have \pkg{Rcpp} installed, the document should also be available +whereever you found this document, \textsl{i.e.,} on every mirror of CRAN site. + \subsection{What do I need ?} Obviously, \proglang{R} must be installed. \pkg{Rcpp} provides a @@ -205,6 +208,8 @@ The \texttt{verbose} argument of \Sexpr{link("cxxfunction")} is very useful as it shows how \pkg{inline} runs the show. +Update: Also see question \ref{using-attributes} below about 'Rcpp +Attributes' \citep{CRAN:Rcpp:Attributes}. \subsection{How do I convert my prototyped code to a package ?} \label{from-inline-to-package} @@ -366,6 +371,17 @@ CXXR and \pkg{Rcpp} both want \proglang{R} to make more use of \proglang{C++} but they do it in very different ways. +\subsection{How do I quickly prototype my code using Attributes?} +\label{using-attributes} + +\pkg{Rcpp} version 0.10.0 and later offer a new feature 'Rcpp Attributes' +which is described in detail in its own vignette +\citep{CRAN:Rcpp:Attributes}. In short, it offers functions \code{evalCpp}, +\code{cppFunction} and \code{sourceCpp} which extend the functionality of the +\code{cxxfunction} function. + + + \section{Examples} The following questions were asked on the \texttt{rcpp-devel} mailing list, @@ -404,6 +420,8 @@ fun(2.2, 3L) @ +Update: Also see question \ref{using-attributes} above about 'Rcpp +Attributes' \citep{CRAN:Rcpp:Attributes} and its \code{sourceCpp} function. \subsection{Can I do matrix algebra with \pkg{Rcpp} ?} From noreply at r-forge.r-project.org Wed Jun 12 20:42:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 12 Jun 2013 20:42:39 +0200 (CEST) Subject: [Rcpp-commits] r4338 - in pkg/Rcpp: . inst inst/doc Message-ID: <20130612184239.774341806EB@r-forge.r-project.org> Author: edd Date: 2013-06-12 20:42:39 +0200 (Wed, 12 Jun 2013) New Revision: 4338 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/doc/Makefile pkg/Rcpp/inst/doc/Rcpp.bib Log: force serial build of vignettes in yet another effort to not let R-Forge fail minor update of Rcpp.bib Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-08 22:51:13 UTC (rev 4337) +++ pkg/Rcpp/ChangeLog 2013-06-12 18:42:39 UTC (rev 4338) @@ -1,3 +1,8 @@ +2013-06-12 Dirk Eddelbuettel + + * inst/doc/Makefile: Force serial build of vignettes in yet another + effort to not let R-Forge fail when trying to rebuild them + 2013-06-08 Dirk Eddelbuettel * inst/doc/Rcpp.bib: Updated entries Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-08 22:51:13 UTC (rev 4337) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-12 18:42:39 UTC (rev 4338) @@ -44,6 +44,7 @@ SingleLogicalResult. \item The \code{src/Makevars} file can now optionally override the path for \code{/usr/bin/install_name_tool} which is used on OS X. + \item Vignettes are trying harder not to be built in parallel. } \item Changes in Rcpp documentation: \itemize{ Modified: pkg/Rcpp/inst/doc/Makefile =================================================================== --- pkg/Rcpp/inst/doc/Makefile 2013-06-08 22:51:13 UTC (rev 4337) +++ pkg/Rcpp/inst/doc/Makefile 2013-06-12 18:42:39 UTC (rev 4338) @@ -12,8 +12,21 @@ @echo The 'make all' target is now empty as eg R-Forge builds fall over @echo So please use 'make pdfclean; make pdfall' to rebuild -pdfall: rotateFiles index.html Rcpp-unitTests.pdf Rcpp-introduction.pdf Rcpp-modules.pdf Rcpp-package.pdf Rcpp-FAQ.pdf Rcpp-extending.pdf Rcpp-sugar.pdf Rcpp-attributes.pdf Rcpp-quickref.pdf +OLDpdfall: rotateFiles index.html Rcpp-unitTests.pdf Rcpp-introduction.pdf Rcpp-modules.pdf Rcpp-package.pdf Rcpp-FAQ.pdf Rcpp-extending.pdf Rcpp-sugar.pdf Rcpp-attributes.pdf Rcpp-quickref.pdf +pdfall: rotateFiles index.html + ## Play some games with explicit targets to avoid parallel make builds + ## This is all just because R-Forge insists on re-making these, seemingly in parallel + make Rcpp-extending.pdf + make Rcpp-FAQ.pdf + make Rcpp-introduction.pdf + make Rcpp-modules.pdf + make Rcpp-package.pdf + make Rcpp-quickref.pdf + make Rcpp-sugar.pdf + make Rcpp-attributes.pdf + make Rcpp-unitTests.pdf + pdfclean: rm -f Rcpp-extending.pdf Rcpp-FAQ.pdf Rcpp-introduction.pdf Rcpp-modules.pdf Rcpp-package.pdf Rcpp-quickref.pdf Rcpp-sugar.pdf Rcpp-attributes.pdf Rcpp-unitTests.pdf Modified: pkg/Rcpp/inst/doc/Rcpp.bib =================================================================== --- pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-08 22:51:13 UTC (rev 4337) +++ pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-12 18:42:39 UTC (rev 4338) @@ -261,7 +261,7 @@ author = {Oleg Sklyar and Duncan Murdoch and Mike Smith and Dirk Eddelbuettel and Romain Fran\c{c}ois}, year = 2013, - note = {R package version 0.3.11}, + note = {R package version 0.3.12}, url = CRAN # "package=inline" } From noreply at r-forge.r-project.org Thu Jun 13 10:49:13 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 13 Jun 2013 10:49:13 +0200 (CEST) Subject: [Rcpp-commits] r4339 - in pkg/Rcpp: . src Message-ID: <20130613084913.F3E83185768@r-forge.r-project.org> Author: romain Date: 2013-06-13 10:49:13 +0200 (Thu, 13 Jun 2013) New Revision: 4339 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/src/Module.cpp Log: typo (reported on Rcpp-devel) Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-12 18:42:39 UTC (rev 4338) +++ pkg/Rcpp/ChangeLog 2013-06-13 08:49:13 UTC (rev 4339) @@ -1,3 +1,7 @@ +2013-06-13 Romain Francois + + * src/Module.cpp: small buglet in macro. Reported on Rcpp-devel + 2013-06-12 Dirk Eddelbuettel * inst/doc/Makefile: Force serial build of vignettes in yet another Modified: pkg/Rcpp/src/Module.cpp =================================================================== --- pkg/Rcpp/src/Module.cpp 2013-06-12 18:42:39 UTC (rev 4338) +++ pkg/Rcpp/src/Module.cpp 2013-06-13 08:49:13 UTC (rev 4339) @@ -2,7 +2,7 @@ // // Module.cpp: Rcpp R/C++ interface class library -- Rcpp modules // -// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -28,7 +28,7 @@ SEXP __CARGS__[MAX_ARGS] ; \ int nargs = 0 ; \ for(; nargs Author: romain Date: 2013-06-14 09:23:41 +0200 (Fri, 14 Jun 2013) New Revision: 4340 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h Log: remove unused variables Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-13 08:49:13 UTC (rev 4339) +++ pkg/Rcpp/ChangeLog 2013-06-14 07:23:41 UTC (rev 4340) @@ -1,3 +1,8 @@ +2013-06-14 Romain Francois + + * include/Rcpp/stats/random/runif.h : removed unused max variable + * include/Rcpp/stats/random/rf.h : removed unused n1 and n2 variables + 2013-06-13 Romain Francois * src/Module.cpp: small buglet in macro. Reported on Rcpp-devel Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h 2013-06-13 08:49:13 UTC (rev 4339) +++ pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h 2013-06-14 07:23:41 UTC (rev 4340) @@ -2,7 +2,7 @@ // // rf.h: Rcpp R/C++ interface class library -- // -// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Douglas Bates, Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -30,7 +30,7 @@ public: FGenerator_Finite_Finite( double n1_, double n2_ ) : - n1(n1_), n2(n2_), n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {} + n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {} inline double operator()() const { // here we know that both n1 and n2 are finite @@ -39,7 +39,7 @@ } private: - double n1, n2, n1__2, n2__2, ratio ; + double n1__2, n2__2, ratio ; } ; Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h 2013-06-13 08:49:13 UTC (rev 4339) +++ pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h 2013-06-14 07:23:41 UTC (rev 4340) @@ -2,7 +2,7 @@ // // runif.h: Rcpp R/C++ interface class library -- // -// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Douglas Bates, Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -30,7 +30,7 @@ public: UnifGenerator( double min_ = 0.0, double max_ = 1.0) : - min(min_), max(max_), diff(max_ - min_) {} + min(min_), diff(max_ - min_) {} inline double operator()() const { double u; @@ -40,7 +40,6 @@ private: double min; - double max ; double diff ; } ; @@ -48,7 +47,7 @@ class UnifGenerator__0__1 : public ::Rcpp::Generator { public: - UnifGenerator__0__1( double min_ = 0.0, double max_ = 1.0) {} + UnifGenerator__0__1() {} inline double operator()() const { double u; From noreply at r-forge.r-project.org Tue Jun 18 19:07:55 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 18 Jun 2013 19:07:55 +0200 (CEST) Subject: [Rcpp-commits] r4341 - in pkg/Rcpp: . inst/include/Rcpp/module Message-ID: <20130618170756.0B0AE18431D@r-forge.r-project.org> Author: romain Date: 2013-06-18 19:07:54 +0200 (Tue, 18 Jun 2013) New Revision: 4341 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppFunction.h Log: ome more BEGIN_RCPP/END_RCPP encapsulation, attemp to deal with exceptions crossing dll boundaries on windows Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-14 07:23:41 UTC (rev 4340) +++ pkg/Rcpp/ChangeLog 2013-06-18 17:07:54 UTC (rev 4341) @@ -1,3 +1,9 @@ +2013-06-18 Romain Francois + + * include/Rcpp/module/Module_generated_CppFunction.h : using BEGIN_RCPP / END_RCPP + as suggested by QRD in Rcpp-devel. This should reduce cross dll exceptions + issues on windows. + 2013-06-14 Romain Francois * include/Rcpp/stats/random/runif.h : removed unused max variable Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppFunction.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppFunction.h 2013-06-14 07:23:41 UTC (rev 4340) +++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppFunction.h 2013-06-18 17:07:54 UTC (rev 4341) @@ -27,7 +27,9 @@ public: CppFunction0(OUT (*fun)(void), const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP*) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun() ) ; + END_RCPP } inline int nargs(){ return 0; } @@ -45,8 +47,9 @@ CppFunction0(void (*fun)(void), const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} ; SEXP operator()(SEXP*) { + BEGIN_RCPP ptr_fun() ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 0; } @@ -64,7 +67,9 @@ public: CppFunction_WithFormals0(OUT (*fun)(void), Rcpp::List, const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP*) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun() ) ; + END_RCPP } inline int nargs(){ return 0; } @@ -82,8 +87,9 @@ CppFunction_WithFormals0(void (*fun)(void), Rcpp::List, const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} ; SEXP operator()(SEXP*) { + BEGIN_RCPP ptr_fun() ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 0; } @@ -102,7 +108,9 @@ CppFunction1(OUT (*fun)(U0) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; + END_RCPP } inline int nargs(){ return 1; } @@ -119,8 +127,9 @@ CppFunction1(void (*fun)(U0) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 1; } @@ -142,7 +151,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; + END_RCPP } inline int nargs(){ return 1; } @@ -162,8 +173,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 1; } @@ -185,7 +197,9 @@ CppFunction2(OUT (*fun)(U0, U1) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; + END_RCPP } inline int nargs(){ return 2; } @@ -202,8 +216,9 @@ CppFunction2(void (*fun)(U0, U1) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 2; } @@ -225,7 +240,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; + END_RCPP } inline int nargs(){ return 2; } @@ -245,8 +262,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 2; } @@ -268,7 +286,9 @@ CppFunction3(OUT (*fun)(U0, U1, U2) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; + END_RCPP } inline int nargs(){ return 3; } @@ -285,8 +305,9 @@ CppFunction3(void (*fun)(U0, U1, U2) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 3; } @@ -308,7 +329,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; + END_RCPP } inline int nargs(){ return 3; } @@ -328,8 +351,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 3; } @@ -351,7 +375,9 @@ CppFunction4(OUT (*fun)(U0, U1, U2, U3) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; + END_RCPP } inline int nargs(){ return 4; } @@ -368,8 +394,9 @@ CppFunction4(void (*fun)(U0, U1, U2, U3) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 4; } @@ -391,7 +418,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; + END_RCPP } inline int nargs(){ return 4; } @@ -411,8 +440,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 4; } @@ -434,7 +464,9 @@ CppFunction5(OUT (*fun)(U0, U1, U2, U3, U4) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; + END_RCPP } inline int nargs(){ return 5; } @@ -451,8 +483,9 @@ CppFunction5(void (*fun)(U0, U1, U2, U3, U4) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 5; } @@ -474,7 +507,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; + END_RCPP } inline int nargs(){ return 5; } @@ -494,8 +529,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 5; } @@ -517,7 +553,9 @@ CppFunction6(OUT (*fun)(U0, U1, U2, U3, U4, U5) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; + END_RCPP } inline int nargs(){ return 6; } @@ -534,8 +572,9 @@ CppFunction6(void (*fun)(U0, U1, U2, U3, U4, U5) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 6; } @@ -557,7 +596,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; + END_RCPP } inline int nargs(){ return 6; } @@ -577,8 +618,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 6; } @@ -600,7 +642,9 @@ CppFunction7(OUT (*fun)(U0, U1, U2, U3, U4, U5, U6) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; + END_RCPP } inline int nargs(){ return 7; } @@ -617,8 +661,9 @@ CppFunction7(void (*fun)(U0, U1, U2, U3, U4, U5, U6) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 7; } @@ -640,7 +685,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; + END_RCPP } inline int nargs(){ return 7; } @@ -660,8 +707,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 7; } @@ -683,7 +731,9 @@ CppFunction8(OUT (*fun)(U0, U1, U2, U3, U4, U5, U6, U7) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; + END_RCPP } inline int nargs(){ return 8; } @@ -700,8 +750,9 @@ CppFunction8(void (*fun)(U0, U1, U2, U3, U4, U5, U6, U7) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7>::type >( args[7] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 8; } @@ -723,7 +774,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; + END_RCPP } inline int nargs(){ return 8; } @@ -743,8 +796,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7>::type >( args[7] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 8; } @@ -766,7 +820,9 @@ CppFunction9(OUT (*fun)(U0, U1, U2, U3, U4, U5, U6, U7, U8) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; + END_RCPP } inline int nargs(){ return 9; } @@ -783,8 +839,9 @@ CppFunction9(void (*fun)(U0, U1, U2, U3, U4, U5, U6, U7, U8) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7>::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8>::type >( args[8] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 9; } @@ -806,7 +863,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; + END_RCPP } inline int nargs(){ return 9; } @@ -826,8 +885,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7>::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8>::type >( args[8] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 9; } @@ -849,7 +909,9 @@ CppFunction10(OUT (*fun)(U0, U1, U2, U3, U4, U5, U6, U7, U8, U9) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; + END_RCPP } inline int nargs(){ return 10; } @@ -866,8 +928,9 @@ CppFunction10(void (*fun)(U0, U1, U2, U3, U4, U5, U6, U7, U8, U9) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0>::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1>::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2>::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3>::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4>::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5>::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6>::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7>::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8>::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9>::type >( args[9] ) ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 10; } @@ -889,7 +952,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; + END_RCPP } inline int nargs(){ return 10; } @@ -909,8 +974,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4341 From noreply at r-forge.r-project.org Tue Jun 18 19:08:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 18 Jun 2013 19:08:36 +0200 (CEST) Subject: [Rcpp-commits] r4342 - scripts Message-ID: <20130618170836.7955218431D@r-forge.r-project.org> Author: romain Date: 2013-06-18 19:08:35 +0200 (Tue, 18 Jun 2013) New Revision: 4342 Modified: scripts/generator_Module_CppFunction.R Log: updated generator Modified: scripts/generator_Module_CppFunction.R =================================================================== --- scripts/generator_Module_CppFunction.R 2013-06-18 17:07:54 UTC (rev 4341) +++ scripts/generator_Module_CppFunction.R 2013-06-18 17:08:35 UTC (rev 4342) @@ -11,7 +11,9 @@ CppFunction%d(OUT (*fun)(%s) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( %s ) ) ; + END_RCPP } inline int nargs(){ return %d; } @@ -28,8 +30,9 @@ CppFunction%d(void (*fun)(%s) , const char* docstring = 0) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( %s ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return %d; } @@ -51,7 +54,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun( %s ) ) ; + END_RCPP } inline int nargs(){ return %d; } @@ -71,8 +76,9 @@ CppFunction(docstring), formals(formals_), ptr_fun(fun){} SEXP operator()(SEXP* args) { + BEGIN_RCPP ptr_fun( %s ) ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return %d; } @@ -161,7 +167,9 @@ public: CppFunction0(OUT (*fun)(void), const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP*) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun() ) ; + END_RCPP } inline int nargs(){ return 0; } @@ -179,8 +187,9 @@ CppFunction0(void (*fun)(void), const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} ; SEXP operator()(SEXP*) { + BEGIN_RCPP ptr_fun() ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 0; } @@ -198,7 +207,9 @@ public: CppFunction_WithFormals0(OUT (*fun)(void), Rcpp::List, const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} SEXP operator()(SEXP*) { + BEGIN_RCPP return Rcpp::module_wrap( ptr_fun() ) ; + END_RCPP } inline int nargs(){ return 0; } @@ -216,8 +227,9 @@ CppFunction_WithFormals0(void (*fun)(void), Rcpp::List, const char* docstring = 0 ) : CppFunction(docstring), ptr_fun(fun){} ; SEXP operator()(SEXP*) { + BEGIN_RCPP ptr_fun() ; - return R_NilValue ; + END_RCPP } inline int nargs(){ return 0; } From noreply at r-forge.r-project.org Wed Jun 19 15:03:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 15:03:51 +0200 (CEST) Subject: [Rcpp-commits] r4343 - in pkg/Rcpp: . inst inst/include/Rcpp/vector inst/unitTests inst/unitTests/cpp Message-ID: <20130619130351.72892184D49@r-forge.r-project.org> Author: romain Date: 2013-06-19 15:03:50 +0200 (Wed, 19 Jun 2013) New Revision: 4343 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h pkg/Rcpp/inst/unitTests/cpp/Vector.cpp pkg/Rcpp/inst/unitTests/runit.Vector.R Log: character vector element equality operator Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-18 17:08:35 UTC (rev 4342) +++ pkg/Rcpp/ChangeLog 2013-06-19 13:03:50 UTC (rev 4343) @@ -1,3 +1,9 @@ +2013-06-19 Romain Francois + + * include/Rcpp/vector/string_proxy.h : added operator + string_proxy::operator==( const string_proxy& ) so that me may compare x[i] + and y[i] (x and y being CharacterVector) + 2013-06-18 Romain Francois * include/Rcpp/module/Module_generated_CppFunction.h : using BEGIN_RCPP / END_RCPP Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-18 17:08:35 UTC (rev 4342) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-19 13:03:50 UTC (rev 4343) @@ -28,7 +28,8 @@ \item \code{Vector<*>::erase(iterator, iterator)} was fixed. Now it does not remove the element pointed by last (similar to what is done on stl types and what was intended initially). Reported on - Rcpp-devel by Toni Giorgino. + Rcpp-devel by Toni Giorgino. + \item Added equality operator between elements of \code{CharacterVector}s. } \item Changes in Rcpp sugar: \itemize{ @@ -48,10 +49,20 @@ } \item Changes in Rcpp documentation: \itemize{ - \item Updated the bibliograph in \code{Rcpp.bib} (which is also + \item Updated the bibliography in \code{Rcpp.bib} (which is also sourced by packages using Rcpp). \item Updated the \code{THANKS} file. } + \item Deprecation plans: + \itemize{ + \item The set of macros \code{RCPP_FUNCTION_} etc ... from the + \code{preprocessor_generated.h} file will be deprecated in the next version + of \code{Rcpp}, i.e they willl still be available but will generate some + warning in addition to their expected behavior. + In release +2 the macros will be removed + from \code{Rcpp}. Users of these macros (if any) should start replacing them + with more up to date code, such as using attributes or modules. + } } } Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h 2013-06-18 17:08:35 UTC (rev 4342) +++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h 2013-06-19 13:03:50 UTC (rev 4343) @@ -182,7 +182,18 @@ bool operator==( const char* other){ return strcmp( begin(), other ) == 0 ; } - + bool operator!=( const char* other){ + return strcmp( begin(), other ) != 0 ; + } + + bool operator==( const string_proxy& other){ + return strcmp( begin(), other.begin() ) == 0 ; + } + bool operator!=( const string_proxy& other){ + return strcmp( begin(), other.begin() ) != 0 ; + } + + private: static std::string buffer ; Modified: pkg/Rcpp/inst/unitTests/cpp/Vector.cpp =================================================================== --- pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-18 17:08:35 UTC (rev 4342) +++ pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-19 13:03:50 UTC (rev 4343) @@ -665,6 +665,17 @@ return l.containsElementNamed(n[0]); } +// [[Rcpp::export]] +List CharacterVectorEqualityOperator( CharacterVector x, CharacterVector y){ + int n = x.size() ; + LogicalVector eq(n), neq(n); + for( int i=0; i Author: romain Date: 2013-06-19 15:42:12 +0200 (Wed, 19 Jun 2013) New Revision: 4344 Modified: pkg/RcppGSL/inst/ Log: ignore auto generated doc directory Property changes on: pkg/RcppGSL/inst ___________________________________________________________________ Added: svn:ignore + doc From noreply at r-forge.r-project.org Wed Jun 19 15:44:55 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 15:44:55 +0200 (CEST) Subject: [Rcpp-commits] r4345 - in pkg/RcppGSL/vignettes: . unitTests Message-ID: <20130619134456.427331858FB@r-forge.r-project.org> Author: romain Date: 2013-06-19 15:44:55 +0200 (Wed, 19 Jun 2013) New Revision: 4345 Removed: pkg/RcppGSL/vignettes/Makefile pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw pkg/RcppGSL/vignettes/RcppGSL/ Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw pkg/RcppGSL/vignettes/unitTests/RcppGSL-unitTests.R Log: back to sensible vignetting with highlight 0.4.2 Deleted: pkg/RcppGSL/vignettes/Makefile =================================================================== --- pkg/RcppGSL/vignettes/Makefile 2013-06-19 13:42:12 UTC (rev 4344) +++ pkg/RcppGSL/vignettes/Makefile 2013-06-19 13:44:55 UTC (rev 4345) @@ -1,50 +0,0 @@ - -## There is an old bug in texidvi that makes it not swallow the ~ -## marker used to denote whitespace. This is actually due to fixing -## another bug whereby you could not run texidvi on directory names -## containing a tilde (as we happen to do for Debian builds of R -## alpha/beta/rc releases). The 'tilde' bug will go away as it -## reportedly has been squashed upstream but I am still bitten by it -## on Ubuntu so for now Dirk will insist on pdflatex and this helps. -whoami=$(shell whoami) - -all: RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -clean: - rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl *~ - rm -rf auto/ - -pdfclean: - rm -f RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -setvars: -ifeq (${R_HOME},) -R_HOME= $(shell R RHOME) -endif -RPROG= $(R_HOME)/bin/R -RSCRIPT=$(R_HOME)/bin/Rscript - -RcppGSL-unitTests.pdf: - rm -fr unitTests-results/* - $(RSCRIPT) --vanilla unitTests/RcppGSL-unitTests.R - $(RPROG) CMD Sweave RcppGSL-unitTests.Rnw - $(RSCRIPT) --vanilla -e "tools::texi2dvi( 'RcppGSL-unitTests.tex', pdf = TRUE, clean = TRUE )" - rm -fr RcppGSL-unitTests.tex - -RcppGSL-intro.pdf: RcppGSL/RcppGSL-intro.Rnw - cp -f RcppGSL/RcppGSL-intro.Rnw . - $(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE); Sweave( 'RcppGSL-intro.Rnw', driver = driver ); " -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = FALSE )" -endif - bibtex RcppGSL-intro -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = TRUE )" -endif - rm -fr RcppGSL-intro.tex RcppGSL-intro.bbl RcppGSL-intro.blg RcppGSL-intro.aux RcppGSL-intro.out RcppGSL-intro.log - cp RcppGSL/RcppGSL-fake.Rnw RcppGSL-intro.Rnw Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-19 13:42:12 UTC (rev 4344) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-19 13:44:55 UTC (rev 4345) @@ -1,11 +1,768 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RcppGSL} +%\VignetteKeywords{R,GSL,Rcpp,data transfer} +%\VignettePackage{RcppGSL} +%\VignetteEngine{highlight::highlight} -\usepackage{url} +\usepackage{url,color} +\usepackage[authoryear,round,longnamesfirst]{natbib} \usepackage[colorlinks]{hyperref} -\setlength{\oddsidemargin}{0pt} -\setlength{\textwidth}{17cm} % uh-oh, I use letter :) +\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} +\usepackage{vmargin} +\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} +\usepackage{booktabs} % fancier \hrule +\newcommand{\proglang}[1]{\textsf{#1}} +\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} + +\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave +\RequirePackage[T1]{fontenc} + +<>= +require(inline) +library(RcppGSL) +options("width"=65) +rcppgsl.version <- packageDescription( "RcppGSL" )$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +@ +% closing $ needed here + +\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} +\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} +\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} + \begin{document} +\maketitle + +\abstract{ + \shortcites{GSL} %% so that we get Galassi et al instead of all names + \noindent + The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical + routines for scientific computing \citep{GSL}. It is particularly useful for + \proglang{C} and \proglang{C++} programs as it provides a standard + \proglang{C} interface to a wide range of mathematical routines such as + special functions, permutations, combinations, fast fourier transforms, + eigensystems, random numbers, quadrature, random distributions, + quasi-random sequences, Monte Carlo integration, N-tuples, differential + equations, simulated annealing, numerical differentiation, interpolation, + series acceleration, Chebyshev approximations, root-finding, discrete + Hankel transforms physical constants, basis splines and wavelets. There + are over 1000 functions in total with an extensive test suite. + + The \pkg{RcppGSL} package provides an easy-to-use interface between + \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} + \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces + between \proglang{R} and C++. +} + +\section{Introduction} + +The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical +routines for scientific computing \citep{GSL}. It is a rigourously developed +and tested library providing support for a wide range of scientific or +numerical tasks. Among the topics covered in the GSL are +%% from the GSL manual +complex numbers, roots of polynomials, +special functions, vector and matrix data structures, +permutations, combinations, sorting, BLAS support, +linear algebra, fast fourier transforms, eigensystems, +random numbers, quadrature, random distributions, quasi-random sequences, +Monte Carlo integration, N-tuples, +differential equations, simulated annealing, +numerical differentiation, interpolation, +series acceleration, Chebyshev approximations, +root-finding, discrete Hankel transforms +least-squares fitting, minimization, +physical constants, basis splines and wavelets. + +Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} +and provides a \proglang{C}-language Application Programming Interface +(API). Access from \proglang{C++} is therefore possible, albeit not at the +abstraction level that can be offered by dedicated \proglang{C++} +implementations.\footnote{Several \proglang{C++} wrappers for the GSL have + been written over the years yet none reached a state of completion + comparable to the GSL itself. Three such wrapping library are + \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, + \url{http://gslwrap.sourceforge.net/} and + \url{http://code.google.com/p/gslcpp/}.} + +The GSL is somewhat unique among numerical libraries. Its combination of +broad coverage of scientific topics, serious implementation effort and the +use of a FLOSS license have lead to a fairly wide usage of the library. As a +concrete example, we can consider the the CRAN repository network for the +\proglang{R} language and environment \citep{R:Main}. CRAN contains over a +dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, +\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, +\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and +\pkg{topicmodels}. This is a clear indication that the GSL is popular among +programmers using either the \proglang{C} or \proglang{C++} language for +solving problems applied science. + +At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a +higher-level abstraction between \proglang{R} and underlying \proglang{C++} +(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like +vectors, matrices, lists, functions, environments, $\ldots$, to be +manipulated directly at the \proglang{C++} level, alleviates the needs for +complicated and error-prone parameter passing and memory allocation. It also +permits compact vectorised expressions similar to what can be written in +\proglang{R} directly at the \proglang{C++} level. + +The \pkg{RcppGSL} package discussed here aims the help close the gap. It +tries to offer access to GSL functions, in particular via the vector and +matrix data structures used throughout the GSL, while staying closer to the +`whole object model' familar to the \proglang{R} programmer. + +The rest of paper is organised as follows. The next section shows a +motivating example of a fast linear model fit routine using \pkg{GSL} functions. +The following section discusses support for \pkg{GSL} vector types, which is +followed by a section on matrices. + +\section{Motivation: FastLm} + +Fitting linear models is a key building block of analysing data and +modeling. \proglang{R} has a very complete and feature-rich function in +\texttt{lm()} which can provide a model fit as we a number of diagnostic +measure, either directly or via the corresponding \texttt{summary()} method +for linear model fits. The \texttt{lm.fit()} function also provides a faster +alternative (which is however recommend only for for advanced users) which +provides estimates only and fewer statistics for inference. This sometimes +leads users request a routine which is both fast and featureful enough. The +\texttt{fastLm} routine shown here provides such an implementation. It uses +the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice +example for \pkg{GSL} integration with \proglang{R}. + +<>= +#include +#include +#include + +extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { + + try { + RcppGSL::vector y = ys; // create gsl data structures from SEXP + RcppGSL::matrix X = Xs; + + int n = X.nrow(), k = X.ncol(); + double chisq; + + RcppGSL::vector coef(k); // to hold the coefficient vector + RcppGSL::matrix 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); + + // 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); + + 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(); + + 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 +} +@ + +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 +as well as complex numbers). We the reserve another vector and matrix to +hold the resulting coefficient estimates as well as the estimate of the +covariance matrix. Next, we allocate workspace using a GSL routine, fit the +linear model and free the workspace. The next step involves extracting the +diagonal element from the covariance matrix. We then employ a so-called +iterator---a common \proglang{C++} idiom from the Standard Template Library +(STL)---to iterate over the vector of diagonal and transforming it by +applying the square root function to compute our standard error of the +estimate. Finally we create a named list with the return value before we free +temporary memory allocation (a step that has to be done because the +underlying objects are really \proglang{C} objects conforming to the +\pkg{GSL} interface and hence without the automatic memory management we +could have with \proglang{C++} vector or matrix structures as used through +the \pkg{Rcpp} package) and return the result to \proglang{R}. + +We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements +a matching \texttt{fastLm} function using the Armadillo library by +\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to +\proglang{C++} features. + +\section{Vectors} + +This section details the different vector represenations, starting with their +definition inside the \pkg{GSL}. We then discuss our layering before showing +how the two types map. A discussion of read-only `vector view' classes +concludes the section. + +\subsection{\pkg{GSL} Vectors} + +\pkg{GSL} defines various vector types to manipulate one-dimensionnal +data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| +structs are defined as: + +<< 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; +@ + +A typical use of the \verb|gsl_vector| struct is given below: + +<>= +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); +} + +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 +@ + +\subsection{RcppGSL::vector} + +\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector} to manipulate +\verb|gsl_vector| pointers taking advantage of C++ templates. Using this +template type, the previous example now becomes: + +<>= +int i; +RcppGSL::vector v(3); // allocate a gsl_vector of size 3 + +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] ; +} + +v.free() ; // free the memory +@ + +The class \texttt{RcppGSL::vector} 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. + +Beyond the convenience of a nicer syntax for allocation and release of +memory, the \texttt{RcppGSL::vector} template faciliates interchange of +\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The +following example defines a \texttt{.Call} compatible function called +\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through +the \texttt{RcppGSL::vector} template specialization: + +<>= +// [[Rcpp::export]] +int sum_gsl_vector_int( RcppGSL::vector vec){ + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return res ; +} +@ + +The function can then simply be called from \proglang{R} : + +<>= + +fx <- cxxfunction( + list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), + c( sum_gsl_vector_int = ' + RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return wrap( res ) ; +' ), plugin = "RcppGSL" ) +<>= +.Call( "sum_gsl_vector_int", 1:10 ) +@ + +A second example shows a simple function that grabs elements of an +R list as \verb|gsl_vector| objects using implicit conversion mechanisms +of \pkg{Rcpp} + +<< example2,lang=cpp,size=small>>= +// [[Rcpp::export]] +double gsl_vector_sum_2( Rcpp::List data ){ + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 ; +} +@ + +called from \proglang{R} : + +<>= +fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ), +c( gsl_vector_sum_2 = ' + List data(data_) ; + + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 wrap(res); +' ), plugin = "RcppGSL" ) +@ +<>= +data <- list( x = seq(0,1,length=10), y = 1:10 ) +.Call( "gsl_vector_sum_2", data ) +@ + +\subsection{Mapping} + +Table~\ref{tab:mappingVectors} shows the mapping between types defined by the +\pkg{GSL} and their corresponding types in the \pkg{RcppGSL} package. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector & RcppGSL \\ + \midrule + \texttt{gsl\_vector} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_int} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_char} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_short} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uchar} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uint} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ushort} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ulong} & \texttt{RcppGSL::vector} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector types and templates defined in \pkg{RcppGSL}.} + \label{tab:mappingVectors} +\end{table} + +\subsection{ Vector Views} + +Several \pkg{GSL} algorithms return \pkg{GSL} vector views as their result +type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view} +to handle vector views using \proglang{C++} syntax. + +<>= +// [[Rcpp::export]] +Rcpp::List test_gsl_vector_view(){ + int n = 10 ; + RcppGSL::vector v(n) ; + for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); + RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); + + List res = List::create( + _["even"] = v_even, + _["odd" ] = v_odd + ) ; + v.free() ; // we only need to free v, the views do not own data + return res ; +} +@ + +As with vectors, \proglang{C++} objects of type +\texttt{RcppGSL::vector\_view} can be converted implicitly to their +associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays +the pairwise correspondance so that the \proglang{C++} objects can be passed +to compatible \pkg{GSL} algorithms. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector views & RcppGSL \\ + \midrule + \texttt{gsl\_vector\_view} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_int} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_char} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_short} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uchar} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uint} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ushort} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ulong} & \texttt{RcppGSL::vector\_view} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector view types and templates defined + in \pkg{RcppGSL}.} + \label{tab:mappingVectorViews} +\end{table} + +The vector view class also contains a conversion operator to automatically +transform the data of the view object to a \pkg{GSL} vector object. This +enables use of vector views where \pkg{GSL} would expect a vector. + + +\section{Matrices} + +The \pkg{GSL} also defines a set of matrix data types : \texttt{gsl\_matrix}, +\texttt{gsl\_matrix\_int} etc ... for which \pkg{RcppGSL} defines a corresponding +convenience \proglang{C++} wrapper generated by the \texttt{RcppGSL::matrix} +template. + +\subsection{Creating matrices} + +The \texttt{RcppGSL::matrix} template exposes three constructors. + +<>= +// convert an R matrix to a GSL matrix +matrix( SEXP x) throw(::Rcpp::not_compatible) + +// encapsulate a GSL matrix pointer +matrix( gsl_matrix* x) + +// create a new matrix with the given number of rows and columns +matrix( int nrow, int ncol) +@ + +\subsection{Implicit conversion} + +\texttt{RcppGSL::matrix} defines implicit conversion to a pointer to +the associated \pkg{GSL} matrix type, as well as dereferencing operators, making +the class \texttt{RcppGSL::matrix} look and feel like a pointer to a GSL +matrix type. + +<>= +gsltype* data ; +operator gsltype*(){ return data ; } +gsltype* operator->() const { return data; } +gsltype& operator*() const { return *data; } +@ + +\subsection{Indexing} + +Indexing of \pkg{GSL} matrices is usually the task of the functions +\texttt{gsl\_matrix\_get}, \texttt{gsl\_matrix\_int\_get}, ... and +\texttt{gsl\_matrix\_set}, \texttt{gsl\_matrix\_int\_set}, ... + +\pkg{RcppGSL} takes advantage of both operator overloading and templates +to make indexing a \pkg{GSL} matrix much more convenient. + +<>= +RcppGSL::matrix mat(10,10); // create a matrix of size 10x10 + +for( int i=0; i<10: i++) { // fill the diagonal + mat(i,i) = i ; +} +@ + +\subsection{Methods} + +The \texttt{RcppGSL::matrix} type also defines the following member functions: +\begin{quote} + \begin{itemize} + \item[\texttt{nrow}] extracts the number of rows + \item[\texttt{ncol}] extract the number of columns + \item[\texttt{size}] extracts the number of elements + \item[\texttt{free}] releases the memory + \end{itemize} +\end{quote} + +\subsection{Matrix views} + +Similar to the vector views discussed above, the \pkg{RcppGSL} also provides +an implicit conversion operator which returns the underlying matrix stored in +the matrix view class. + +\section{Using \pkg{RcppGSL} in your package} + +The \pkg{RcppGSL} package contains a complete example providing a single +function \texttt{colNorm} which computes a norm for each column of a +supplied matrix. This example adapts a matrix example from the GSL manual that has +been chose merely as a means to showing how to set up a package to use +\pkg{RcppGSL}. + +Needless to say, we could compute such a matrix norm easily in \proglang{R} +using existing facilities. One such possibility is a simple +\verb|apply(M, 2, function(x) sqrt(sum(x^2)))| as shown on the corresponding +help page in the example package inside \pkg{RcppGSL}. One point in favour of +using the \pkg{GSL} code is that it employs a BLAS function so on +sufficiently large matrices, and with suitable BLAS libraries installed, this +variant could be faster due to the optimised code in high-performance BLAS +libraries and/or the inherent parallelism a multi-core BLAS variant which +compute compute the vector norm in parallel. On all `reasonable' matrix +sizes, however, the performance difference should be neglible. + +\subsection{The \texttt{configure} script} + +\subsubsection{Using autoconf} + +Using \pkg{RcppGSL} means employing both the \pkg{GSL} and \proglang{R}. We +may need to find the location of the \pkg{GSL} headers and library, and this +done easily from a \texttt{configure} source script which \texttt{autoconf} +generates from a \texttt{configure.in} source file such as the following: + +<>= +AC_INIT([RcppGSLExample], 0.1.0) + +## Use gsl-config to find arguments for compiler and linker flags +## +## Check for non-standard programs: gsl-config(1) +AC_PATH_PROG([GSL_CONFIG], [gsl-config]) +## If gsl-config was found, let's use it +if test "${GSL_CONFIG}" != ""; then + # Use gsl-config for header and linker arguments (without BLAS which we get from R) + GSL_CFLAGS=`${GSL_CONFIG} --cflags` + GSL_LIBS=`${GSL_CONFIG} --libs-without-cblas` +else + AC_MSG_ERROR([gsl-config not found, is GSL installed?]) +fi + +## Use Rscript to query Rcpp for compiler and linker flags +## link flag providing libary as well as path to library, and optionally rpath +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'` + +# Now substitute these variables in src/Makevars.in to create src/Makevars +AC_SUBST(GSL_CFLAGS) +AC_SUBST(GSL_LIBS) +AC_SUBST(RCPP_LDFLAGS) + +AC_OUTPUT(src/Makevars) +@ + +Such a source \texttt{configure.in} gets converted into a script +\texttt{configure} by invoking the \texttt{autoconf} program. + +\subsubsection{Using functions provided by RcppGSL} + +\pkg{RcppGSL} provides R functions that allows one to retrieve the same +information. Therefore the configure script can also be written as: + +<>= +#!/bin/sh + +GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars +@ + +Similarly, the configure.win for windows can be written as: + +<>= +GSL_CFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars.win +@ + +\subsection{The \texttt{src} directory} + +The \proglang{C++} source file takes the matrix supplied from \proglang{R} +and applies the \pkg{GSL} function to each column. + +<>= +#include +#include +#include + +extern "C" SEXP colNorm(SEXP sM) { + + try { + + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector + + } catch( std::exception &ex ) { + forward_exception_to_r( ex ); + + } catch(...) { + ::Rf_error( "c++ exception (unknown reason)" ); + } + return R_NilValue; // -Wall +} +@ + +The \proglang{Makevars.in} file governs the compilation and uses the values +supplied by \texttt{configure} during build-time: + +<>= + +# set by configure +GSL_CFLAGS = @GSL_CFLAGS@ +GSL_LIBS = @GSL_LIBS@ +RCPP_LDFLAGS = @RCPP_LDFLAGS@ + +# combine with standard arguments for R +PKG_CPPFLAGS = $(GSL_CFLAGS) +PKG_LIBS = $(GSL_LIBS) $(RCPP_LDFLAGS) +@ + +The variables surrounded by \@ will be filled by \texttt{configure} during +package build-time. + +\subsection{The \texttt{R} directory} + +The \proglang{R} source is very simply: a single matrix is passed to \proglang{C++}: + +<>= +colNorm <- function(M) { + stopifnot(is.matrix(M)) + res <- .Call("colNorm", M, package="RcppGSLExample") +} +@ + +\section{Using \pkg{RcppGSL} with \pkg{inline}} + +The \pkg{inline} package \citep{CRAN:inline} is very helpful for prototyping code in +\proglang{C}, \proglang{C++} or \proglang{Fortran} as it takes care of code +compilation, linking and dynamic loading directly from \proglang{R}. It is +being used extensively by \pkg{Rcpp}, for example in the numerous unit tests. + +The example below shows how \pkg{inline} can be deployed with +\pkg{RcppGSL}. We implement the same column norm example, but this time as an +\proglang{R} script which is compiled, linked and loaded on-the-fly. Compared +to standard use of \pkg{inline}, we have to make sure to add a short section +declaring which header files from \pkg{GSL} we need to use; the \pkg{RcppGSL} +then communicates with \pkg{inline} to tell it about the location and names +of libraries used to build code against \pkg{GSL}. + +<<>>= +require(inline) + +inctxt=' + #include + #include +' + +bodytxt=' + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector +' + +foo <- cxxfunction( + signature(sM="numeric"), + body=bodytxt, inc=inctxt, plugin="RcppGSL") + +## see Section 8.4.13 of the GSL manual: create M as a sum of two outer products +M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*") +foo(M) +@ + +The \texttt{RcppGSL} inline plugin supports creation of a package skeleton +based on the inline function. + +<>= +package.skeleton( "mypackage", foo ) +@ + +\section{Summary} + +The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive +collection of rigorously developed and tested functions for applied +scientific computing under a common Open Source license. This has lead to +widespread deployment of \pkg{GSL} among a number of disciplines. + +Using the automatic wrapping and converters offered by the \pkg{RcppGSL} +package presented here, \proglang{R} users and programmers can now deploy +algorithmns provided by the \pkg{GSL} with greater ease. + +\bibliographystyle{plainnat} +\bibliography{\Sexpr{Rcpp:::bib()}} + \end{document} Deleted: pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-19 13:42:12 UTC (rev 4344) +++ pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-19 13:44:55 UTC (rev 4345) @@ -1,36 +0,0 @@ -\documentclass[10pt]{article} -%\VignetteIndexEntry{RcppGSL-unitTests} -%\VignetteKeywords{R,GSL,Rcpp,unit tests} -%\VignettePackage{RcppGSL} - -\usepackage{vmargin} -\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} - -\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave -\RequirePackage[T1]{fontenc} - -<>= -require( RcppGSL ) -prettyVersion <- packageDescription("RcppGSL")$Version -prettyDate <- format(Sys.Date(), "%B %e, %Y") -@ - -\usepackage[colorlinks]{hyperref} -\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} -\title{\texttt{RcppGSL}: Unit testing results} -\date{\texttt{RcppGSL} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} -\begin{document} -\maketitle - -\begin{verbatim} -<>= -results <- "unitTests-results/RcppGSL-unitTests.txt" -if( file.exists( results ) ){ - writeLines( readLines( results ) ) -} else{ - writeLines( "unit test results not available" ) -} -@ -\end{verbatim} - -\end{document} Modified: pkg/RcppGSL/vignettes/unitTests/RcppGSL-unitTests.R =================================================================== [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4345 From noreply at r-forge.r-project.org Wed Jun 19 15:47:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 15:47:26 +0200 (CEST) Subject: [Rcpp-commits] r4346 - pkg/RcppGSL/vignettes Message-ID: <20130619134727.2A4DA18577E@r-forge.r-project.org> Author: romain Date: 2013-06-19 15:47:26 +0200 (Wed, 19 Jun 2013) New Revision: 4346 Removed: pkg/RcppGSL/vignettes/unitTests-results/ pkg/RcppGSL/vignettes/unitTests/ Log: back to sensible vignetting with highlight 0.4.2 From noreply at r-forge.r-project.org Wed Jun 19 15:51:41 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 15:51:41 +0200 (CEST) Subject: [Rcpp-commits] r4347 - pkg/Rcpp/inst Message-ID: <20130619135141.2D8DA185763@r-forge.r-project.org> Author: romain Date: 2013-06-19 15:51:40 +0200 (Wed, 19 Jun 2013) New Revision: 4347 Modified: pkg/Rcpp/inst/NEWS.Rd Log: comply with Dirk release requirements Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-19 13:47:26 UTC (rev 4346) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-19 13:51:40 UTC (rev 4347) @@ -57,10 +57,13 @@ \itemize{ \item The set of macros \code{RCPP_FUNCTION_} etc ... from the \code{preprocessor_generated.h} file will be deprecated in the next version - of \code{Rcpp}, i.e they willl still be available but will generate some + of \code{Rcpp}, i.e they will still be available but will generate some warning in addition to their expected behavior. - In release +2 the macros will be removed - from \code{Rcpp}. Users of these macros (if any) should start replacing them + + In the first release 12 months after now, the macros will be removed + from \code{Rcpp}. + + Users of these macros (if any) should start replacing them with more up to date code, such as using attributes or modules. } } From noreply at r-forge.r-project.org Wed Jun 19 16:15:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 16:15:47 +0200 (CEST) Subject: [Rcpp-commits] r4348 - in pkg/RcppGSL: . inst Message-ID: <20130619141547.DB3EE184B7B@r-forge.r-project.org> Author: romain Date: 2013-06-19 16:15:47 +0200 (Wed, 19 Jun 2013) New Revision: 4348 Modified: pkg/RcppGSL/DESCRIPTION pkg/RcppGSL/inst/NEWS.Rd Log: mention the highlight vognette engine Modified: pkg/RcppGSL/DESCRIPTION =================================================================== --- pkg/RcppGSL/DESCRIPTION 2013-06-19 13:51:40 UTC (rev 4347) +++ pkg/RcppGSL/DESCRIPTION 2013-06-19 14:15:47 UTC (rev 4348) @@ -1,7 +1,7 @@ Package: RcppGSL Type: Package Title: Rcpp integration for GNU GSL vectors and matrices -Version: 0.2.0 +Version: 0.2.1 Date: $Date$ Author: Romain Francois and Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel @@ -27,7 +27,8 @@ write a similar package against another library. License: GPL (>= 2) LazyLoad: yes -Depends: Rcpp (>= 0.9.8) +Depends: Rcpp (>= 0.10.3) Suggests: RUnit, inline LinkingTo: Rcpp SystemRequirements: GNU GSL +VignetteBuilder: highlight Modified: pkg/RcppGSL/inst/NEWS.Rd =================================================================== --- pkg/RcppGSL/inst/NEWS.Rd 2013-06-19 13:51:40 UTC (rev 4347) +++ pkg/RcppGSL/inst/NEWS.Rd 2013-06-19 14:15:47 UTC (rev 4348) @@ -2,10 +2,13 @@ \title{News for Package \pkg{RcppGSL}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} -\section{Changes in version 0.2.1 (2012-xx-yy)}{ +\section{Changes in version 0.2.1 (2013-xx-yy)}{ \itemize{ \item Added new example based on B-splines example in GSL manual illustrating simple GSL use via Rcpp attributes + \item vignette production has been simplified, relying on version 0.4.2 + of highlight which acts now as a vignette engine for this package + vignette. } } From noreply at r-forge.r-project.org Wed Jun 19 16:42:46 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 16:42:46 +0200 (CEST) Subject: [Rcpp-commits] r4349 - pkg/RcppGSL Message-ID: <20130619144246.A26C6184E1E@r-forge.r-project.org> Author: romain Date: 2013-06-19 16:42:45 +0200 (Wed, 19 Jun 2013) New Revision: 4349 Modified: pkg/RcppGSL/DESCRIPTION Log: typo Modified: pkg/RcppGSL/DESCRIPTION =================================================================== --- pkg/RcppGSL/DESCRIPTION 2013-06-19 14:15:47 UTC (rev 4348) +++ pkg/RcppGSL/DESCRIPTION 2013-06-19 14:42:45 UTC (rev 4349) @@ -22,7 +22,7 @@ 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 + that uses Rcpp to connect to another 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) From noreply at r-forge.r-project.org Wed Jun 19 22:41:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 22:41:29 +0200 (CEST) Subject: [Rcpp-commits] r4350 - in pkg/Rcpp: . inst/include/Rcpp/module Message-ID: <20130619204129.9CA6E185143@r-forge.r-project.org> Author: romain Date: 2013-06-19 22:41:28 +0200 (Wed, 19 Jun 2013) New Revision: 4350 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppMethod.h pkg/Rcpp/inst/include/Rcpp/module/Module_generated_Pointer_CppMethod.h Log: helping module_wrap by removing const and reference decoration from OUT Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-19 14:42:45 UTC (rev 4349) +++ pkg/Rcpp/ChangeLog 2013-06-19 20:41:28 UTC (rev 4350) @@ -3,6 +3,10 @@ * include/Rcpp/vector/string_proxy.h : added operator string_proxy::operator==( const string_proxy& ) so that me may compare x[i] and y[i] (x and y being CharacterVector) + * include/Rcpp/module/Module_generated_Pointer_CppMethod.h : remove const + and reference to OUT type in several places, that was causing problems e.g. + on making the Rcpp-modules vignette + * include/Rcpp/module/Module_generated_CppMethod.h : idem 2013-06-18 Romain Francois Modified: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppMethod.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppMethod.h 2013-06-19 14:42:45 UTC (rev 4349) +++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_CppMethod.h 2013-06-19 20:41:28 UTC (rev 4350) @@ -26,9 +26,11 @@ public: typedef OUT (Class::*Method)(void) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; + CppMethod0( Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP*){ - return Rcpp::module_wrap( (object->*met)( ) ) ; + return Rcpp::module_wrap( (object->*met)( ) ) ; } inline int nargs(){ return 0 ; } inline bool is_void(){ return false ; } @@ -61,9 +63,11 @@ public: typedef OUT (Class::*Method)(void) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; + const_CppMethod0( Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* ){ - return Rcpp::module_wrap( (object->*met)( ) ) ; + return Rcpp::module_wrap( (object->*met)( ) ) ; } inline int nargs(){ return 0 ; } inline bool is_void(){ return false ; } @@ -98,10 +102,11 @@ public: typedef OUT (Class::*Method)(U0 u0) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod1(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; } inline int nargs(){ return 1 ; } inline bool is_void(){ return false ; } @@ -138,10 +143,11 @@ public: typedef OUT (Class::*Method)(U0 u0) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod1(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ) ) ) ; } inline int nargs(){ return 1 ; } inline bool is_void(){ return false ; } @@ -178,10 +184,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod2(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; } inline int nargs(){ return 2 ; } inline bool is_void(){ return false ; } @@ -218,10 +225,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod2(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ) ) ) ; } inline int nargs(){ return 2 ; } inline bool is_void(){ return false ; } @@ -258,10 +266,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod3(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; } inline int nargs(){ return 3 ; } inline bool is_void(){ return false ; } @@ -298,10 +307,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod3(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ) ) ) ; } inline int nargs(){ return 3 ; } inline bool is_void(){ return false ; } @@ -338,10 +348,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod4(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; } inline int nargs(){ return 4 ; } inline bool is_void(){ return false ; } @@ -378,10 +389,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod4(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ) ) ) ; } inline int nargs(){ return 4 ; } inline bool is_void(){ return false ; } @@ -418,10 +430,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod5(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; } inline int nargs(){ return 5 ; } inline bool is_void(){ return false ; } @@ -458,10 +471,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod5(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ) ) ) ; } inline int nargs(){ return 5 ; } inline bool is_void(){ return false ; } @@ -498,10 +512,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod6(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; } inline int nargs(){ return 6 ; } inline bool is_void(){ return false ; } @@ -538,10 +553,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod6(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ) ) ) ; } inline int nargs(){ return 6 ; } inline bool is_void(){ return false ; } @@ -578,10 +594,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod7(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; } inline int nargs(){ return 7 ; } inline bool is_void(){ return false ; } @@ -618,10 +635,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod7(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ) ) ) ; } inline int nargs(){ return 7 ; } inline bool is_void(){ return false ; } @@ -658,10 +676,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod8(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; } inline int nargs(){ return 8 ; } inline bool is_void(){ return false ; } @@ -698,10 +717,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod8(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ) ) ) ; } inline int nargs(){ return 8 ; } inline bool is_void(){ return false ; } @@ -738,10 +758,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7, U8 u8) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod9(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; } inline int nargs(){ return 9 ; } inline bool is_void(){ return false ; } @@ -778,10 +799,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7, U8 u8) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod9(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ) ) ) ; } inline int nargs(){ return 9 ; } inline bool is_void(){ return false ; } @@ -818,10 +840,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7, U8 u8, U9 u9) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod10(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; } inline int nargs(){ return 10 ; } inline bool is_void(){ return false ; } @@ -858,10 +881,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7, U8 u8, U9 u9) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod10(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; + return Rcpp::module_wrap( (object->*met)( Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U0 >::type >( args[0] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U1 >::type >( args[1] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U2 >::type >( args[2] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U3 >::type >( args[3] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U4 >::type >( args[4] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U5 >::type >( args[5] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U6 >::type >( args[6] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U7 >::type >( args[7] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U8 >::type >( args[8] ), Rcpp::as< typename Rcpp::traits::remove_const_and_reference< U9 >::type >( args[9] ) ) ) ; } inline int nargs(){ return 10 ; } inline bool is_void(){ return false ; } @@ -898,10 +922,11 @@ public: typedef OUT (Class::*Method)(U0 u0, U1 u1, U2 u2, U3 u3, U4 u4, U5 u5, U6 u6, U7 u7, U8 u8, U9 u9, U10 u10) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod11(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4350 From noreply at r-forge.r-project.org Wed Jun 19 23:03:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Jun 2013 23:03:22 +0200 (CEST) Subject: [Rcpp-commits] r4351 - scripts Message-ID: <20130619210322.9E8E6184E2D@r-forge.r-project.org> Author: romain Date: 2013-06-19 23:03:21 +0200 (Wed, 19 Jun 2013) New Revision: 4351 Modified: scripts/generator_Module_CppMethod.R scripts/generator_Module_PointerCppMethod.R Log: updated generators Modified: scripts/generator_Module_CppMethod.R =================================================================== --- scripts/generator_Module_CppMethod.R 2013-06-19 20:41:28 UTC (rev 4350) +++ scripts/generator_Module_CppMethod.R 2013-06-19 21:03:21 UTC (rev 4351) @@ -16,10 +16,11 @@ public: typedef OUT (Class::*Method)(%s) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; CppMethod%d(Method m) : method_class(), met(m) {} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( %s ) ) ; + return Rcpp::module_wrap( (object->*met)( %s ) ) ; } inline int nargs(){ return %d ; } inline bool is_void(){ return false ; } @@ -56,10 +57,11 @@ public: typedef OUT (Class::*Method)(%s) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; const_CppMethod%d(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( (object->*met)( %s ) ) ; + return Rcpp::module_wrap( (object->*met)( %s ) ) ; } inline int nargs(){ return %d ; } inline bool is_void(){ return false ; } @@ -158,9 +160,11 @@ public: typedef OUT (Class::*Method)(void) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; + CppMethod0( Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP*){ - return Rcpp::module_wrap( (object->*met)( ) ) ; + return Rcpp::module_wrap( (object->*met)( ) ) ; } inline int nargs(){ return 0 ; } inline bool is_void(){ return false ; } @@ -193,9 +197,11 @@ public: typedef OUT (Class::*Method)(void) const ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; + const_CppMethod0( Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* ){ - return Rcpp::module_wrap( (object->*met)( ) ) ; + return Rcpp::module_wrap( (object->*met)( ) ) ; } inline int nargs(){ return 0 ; } inline bool is_void(){ return false ; } Modified: scripts/generator_Module_PointerCppMethod.R =================================================================== --- scripts/generator_Module_PointerCppMethod.R 2013-06-19 20:41:28 UTC (rev 4350) +++ scripts/generator_Module_PointerCppMethod.R 2013-06-19 21:03:21 UTC (rev 4351) @@ -16,10 +16,11 @@ public: typedef OUT (*Method)(Class*, %s) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; Pointer_CppMethod%d(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( met( object, %s ) ) ; + return Rcpp::module_wrap( met( object, %s ) ) ; } inline int nargs(){ return %d ; } inline bool is_void(){ return false ; } @@ -56,10 +57,11 @@ public: typedef OUT (*Method)(const Class*, %s) ; typedef CppMethod method_class ; + typedef typename Rcpp::traits::remove_const_and_reference< OUT >::type CLEANED_OUT ; Const_Pointer_CppMethod%d(Method m) : method_class(), met(m){} SEXP operator()( Class* object, SEXP* args){ - return Rcpp::module_wrap( met( object, %s ) ) ; + return Rcpp::module_wrap( met( object, %s ) ) ; } inline int nargs(){ return %d ; } inline bool is_void(){ return false ; } From noreply at r-forge.r-project.org Thu Jun 20 00:13:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 00:13:52 +0200 (CEST) Subject: [Rcpp-commits] r4352 - pkg/RcppGSL Message-ID: <20130619221353.01D4B1858FB@r-forge.r-project.org> Author: edd Date: 2013-06-20 00:13:52 +0200 (Thu, 20 Jun 2013) New Revision: 4352 Modified: pkg/RcppGSL/DESCRIPTION Log: lower version number a little; this is not yet a release candidate Modified: pkg/RcppGSL/DESCRIPTION =================================================================== --- pkg/RcppGSL/DESCRIPTION 2013-06-19 21:03:21 UTC (rev 4351) +++ pkg/RcppGSL/DESCRIPTION 2013-06-19 22:13:52 UTC (rev 4352) @@ -1,7 +1,7 @@ Package: RcppGSL Type: Package Title: Rcpp integration for GNU GSL vectors and matrices -Version: 0.2.1 +Version: 0.2.0.1 Date: $Date$ Author: Romain Francois and Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel From noreply at r-forge.r-project.org Thu Jun 20 00:42:17 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 00:42:17 +0200 (CEST) Subject: [Rcpp-commits] r4353 - in pkg/RcppGSL: . vignettes vignettes/RcppGSL vignettes/unitTests Message-ID: <20130619224217.5241C185349@r-forge.r-project.org> Author: romain Date: 2013-06-20 00:42:16 +0200 (Thu, 20 Jun 2013) New Revision: 4353 Added: pkg/RcppGSL/vignettes/Makefile pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw pkg/RcppGSL/vignettes/RcppGSL/ pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-fake.Rnw pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw pkg/RcppGSL/vignettes/unitTests-results/ pkg/RcppGSL/vignettes/unitTests/ pkg/RcppGSL/vignettes/unitTests/RcppGSL-unitTests.R Modified: pkg/RcppGSL/DESCRIPTION Log: revert back to Makefile Modified: pkg/RcppGSL/DESCRIPTION =================================================================== --- pkg/RcppGSL/DESCRIPTION 2013-06-19 22:13:52 UTC (rev 4352) +++ pkg/RcppGSL/DESCRIPTION 2013-06-19 22:42:16 UTC (rev 4353) @@ -31,4 +31,3 @@ Suggests: RUnit, inline LinkingTo: Rcpp SystemRequirements: GNU GSL -VignetteBuilder: highlight Added: pkg/RcppGSL/vignettes/Makefile =================================================================== --- pkg/RcppGSL/vignettes/Makefile (rev 0) +++ pkg/RcppGSL/vignettes/Makefile 2013-06-19 22:42:16 UTC (rev 4353) @@ -0,0 +1,50 @@ + +## There is an old bug in texidvi that makes it not swallow the ~ +## marker used to denote whitespace. This is actually due to fixing +## another bug whereby you could not run texidvi on directory names +## containing a tilde (as we happen to do for Debian builds of R +## alpha/beta/rc releases). The 'tilde' bug will go away as it +## reportedly has been squashed upstream but I am still bitten by it +## on Ubuntu so for now Dirk will insist on pdflatex and this helps. +whoami=$(shell whoami) + +all: RcppGSL-unitTests.pdf RcppGSL-intro.pdf + +clean: + rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl *~ + rm -rf auto/ + +pdfclean: + rm -f RcppGSL-unitTests.pdf RcppGSL-intro.pdf + +setvars: +ifeq (${R_HOME},) +R_HOME= $(shell R RHOME) +endif +RPROG= $(R_HOME)/bin/R +RSCRIPT=$(R_HOME)/bin/Rscript + +RcppGSL-unitTests.pdf: + rm -fr unitTests-results/* + $(RSCRIPT) --vanilla unitTests/RcppGSL-unitTests.R + $(RPROG) CMD Sweave RcppGSL-unitTests.Rnw + $(RSCRIPT) --vanilla -e "tools::texi2dvi( 'RcppGSL-unitTests.tex', pdf = TRUE, clean = TRUE )" + rm -fr RcppGSL-unitTests.tex + +RcppGSL-intro.pdf: RcppGSL/RcppGSL-intro.Rnw + cp -f RcppGSL/RcppGSL-intro.Rnw . + $(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE); Sweave( 'RcppGSL-intro.Rnw', driver = driver ); " +ifneq (,$(findstring edd,$(whoami))) + pdflatex RcppGSL-intro +else + $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = FALSE )" +endif + bibtex RcppGSL-intro +ifneq (,$(findstring edd,$(whoami))) + pdflatex RcppGSL-intro + pdflatex RcppGSL-intro +else + $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = TRUE )" +endif + rm -fr RcppGSL-intro.tex RcppGSL-intro.bbl RcppGSL-intro.blg RcppGSL-intro.aux RcppGSL-intro.out RcppGSL-intro.log + cp RcppGSL/RcppGSL-fake.Rnw RcppGSL-intro.Rnw Added: pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-fake.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-fake.Rnw (rev 0) +++ pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-fake.Rnw 2013-06-19 22:42:16 UTC (rev 4353) @@ -0,0 +1,11 @@ +\documentclass[10pt]{article} +%\VignetteIndexEntry{RcppGSL} + +\usepackage{url} +\usepackage[colorlinks]{hyperref} +\setlength{\oddsidemargin}{0pt} +\setlength{\textwidth}{17cm} % uh-oh, I use letter :) + +\begin{document} +\end{document} + Added: pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw (rev 0) +++ pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw 2013-06-19 22:42:16 UTC (rev 4353) @@ -0,0 +1,1126 @@ +\documentclass[10pt]{article} +%\VignetteIndexEntry{RcppGSL} +%\VignetteKeywords{R,GSL,Rcpp,data transfer} +%\VignettePackage{RcppGSL} + +\usepackage{url,color} +\usepackage[authoryear,round,longnamesfirst]{natbib} +\usepackage[colorlinks]{hyperref} +\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} +\usepackage{vmargin} +\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} +\usepackage{booktabs} % fancier \hrule + +\newcommand{\proglang}[1]{\textsf{#1}} +\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} + +\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave +\RequirePackage[T1]{fontenc} + +<>= +require(inline) +library(RcppGSL) +options("width"=65) +rcppgsl.version <- packageDescription( "RcppGSL" )$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +@ +% closing $ needed here + +\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} +\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} +\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} + +\begin{document} +\maketitle + +\abstract{ + \shortcites{GSL} %% so that we get Galassi et al instead of all names + \noindent + The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical + routines for scientific computing \citep{GSL}. It is particularly useful for + \proglang{C} and \proglang{C++} programs as it provides a standard + \proglang{C} interface to a wide range of mathematical routines such as + special functions, permutations, combinations, fast fourier transforms, + eigensystems, random numbers, quadrature, random distributions, + quasi-random sequences, Monte Carlo integration, N-tuples, differential + equations, simulated annealing, numerical differentiation, interpolation, + series acceleration, Chebyshev approximations, root-finding, discrete + Hankel transforms physical constants, basis splines and wavelets. There + are over 1000 functions in total with an extensive test suite. + + The \pkg{RcppGSL} package provides an easy-to-use interface between + \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} + \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces + between \proglang{R} and C++. +} + +\section{Introduction} + +The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical +routines for scientific computing \citep{GSL}. It is a rigourously developed +and tested library providing support for a wide range of scientific or +numerical tasks. Among the topics covered in the GSL are +%% from the GSL manual +complex numbers, roots of polynomials, +special functions, vector and matrix data structures, +permutations, combinations, sorting, BLAS support, +linear algebra, fast fourier transforms, eigensystems, +random numbers, quadrature, random distributions, quasi-random sequences, +Monte Carlo integration, N-tuples, +differential equations, simulated annealing, +numerical differentiation, interpolation, +series acceleration, Chebyshev approximations, +root-finding, discrete Hankel transforms +least-squares fitting, minimization, +physical constants, basis splines and wavelets. + +Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} +and provides a \proglang{C}-language Application Programming Interface +(API). Access from \proglang{C++} is therefore possible, albeit not at the +abstraction level that can be offered by dedicated \proglang{C++} +implementations.\footnote{Several \proglang{C++} wrappers for the GSL have + been written over the years yet none reached a state of completion + comparable to the GSL itself. Three such wrapping library are + \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, + \url{http://gslwrap.sourceforge.net/} and + \url{http://code.google.com/p/gslcpp/}.} + +The GSL is somewhat unique among numerical libraries. Its combination of +broad coverage of scientific topics, serious implementation effort and the +use of a FLOSS license have lead to a fairly wide usage of the library. As a +concrete example, we can consider the the CRAN repository network for the +\proglang{R} language and environment \citep{R:Main}. CRAN contains over a +dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, +\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, +\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and +\pkg{topicmodels}. This is a clear indication that the GSL is popular among +programmers using either the \proglang{C} or \proglang{C++} language for +solving problems applied science. + +At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a +higher-level abstraction between \proglang{R} and underlying \proglang{C++} +(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like +vectors, matrices, lists, functions, environments, $\ldots$, to be +manipulated directly at the \proglang{C++} level, alleviates the needs for +complicated and error-prone parameter passing and memory allocation. It also +permits compact vectorised expressions similar to what can be written in +\proglang{R} directly at the \proglang{C++} level. + +The \pkg{RcppGSL} package discussed here aims the help close the gap. It +tries to offer access to GSL functions, in particular via the vector and +matrix data structures used throughout the GSL, while staying closer to the +`whole object model' familar to the \proglang{R} programmer. + +The rest of paper is organised as follows. The next section shows a +motivating example of a fast linear model fit routine using \pkg{GSL} functions. +The following section discusses support for \pkg{GSL} vector types, which is +followed by a section on matrices. + +\section{Motivation: FastLm} + +Fitting linear models is a key building block of analysing data and +modeling. \proglang{R} has a very complete and feature-rich function in +\texttt{lm()} which can provide a model fit as we a number of diagnostic +measure, either directly or via the corresponding \texttt{summary()} method +for linear model fits. The \texttt{lm.fit()} function also provides a faster +alternative (which is however recommend only for for advanced users) which +provides estimates only and fewer statistics for inference. This sometimes +leads users request a routine which is both fast and featureful enough. The +\texttt{fastLm} routine shown here provides such an implementation. It uses +the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice +example for \pkg{GSL} integration with \proglang{R}. + +% < < fastLm,lang=cpp,size=small > > = +% #include +% #include +% #include + +% extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { + +% try { +% RcppGSL::vector y = ys; // create gsl data structures from SEXP +% RcppGSL::matrix X = Xs; + +% int n = X.nrow(), k = X.ncol(); +% double chisq; + +% RcppGSL::vector coef(k); // to hold the coefficient vector +% RcppGSL::matrix 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); + +% // 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); + +% 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(); + +% 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 +% } +% @ + +\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 +as well as complex numbers). We the reserve another vector and matrix to +hold the resulting coefficient estimates as well as the estimate of the +covariance matrix. Next, we allocate workspace using a GSL routine, fit the +linear model and free the workspace. The next step involves extracting the +diagonal element from the covariance matrix. We then employ a so-called +iterator---a common \proglang{C++} idiom from the Standard Template Library +(STL)---to iterate over the vector of diagonal and transforming it by +applying the square root function to compute our standard error of the +estimate. Finally we create a named list with the return value before we free +temporary memory allocation (a step that has to be done because the +underlying objects are really \proglang{C} objects conforming to the +\pkg{GSL} interface and hence without the automatic memory management we +could have with \proglang{C++} vector or matrix structures as used through +the \pkg{Rcpp} package) and return the result to \proglang{R}. + +We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements +a matching \texttt{fastLm} function using the Armadillo library by +\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to +\proglang{C++} features. + +\section{Vectors} + +This section details the different vector represenations, starting with their +definition inside the \pkg{GSL}. We then discuss our layering before showing +how the two types map. A discussion of read-only `vector view' classes +concludes the section. + +\subsection{\pkg{GSL} Vectors} + +\pkg{GSL} defines various vector types to manipulate one-dimensionnal +data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| +structs are defined as: + +% < < 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; +% @ + +\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: + +% < > = +% 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); +% } + +% 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 +% @ + +\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} to manipulate +\verb|gsl_vector| pointers taking advantage of C++ templates. Using this +template type, the previous example now becomes: + +% < < vector_sum,lang=cpp,size=small > > = +% int i; +% RcppGSL::vector v(3); // allocate a gsl_vector of size 3 + +% 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] ; +% } + +% 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} 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. + +Beyond the convenience of a nicer syntax for allocation and release of +memory, the \texttt{RcppGSL::vector} template faciliates interchange of +\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The +following example defines a \texttt{.Call} compatible function called +\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through +the \texttt{RcppGSL::vector} template specialization: + +% < > = +% RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector 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} : + +<>= +fx <- cxxfunction( + list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), + c( sum_gsl_vector_int = ' + RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return wrap( res ) ; +' ), plugin = "RcppGSL" ) +<>= +.Call( "sum_gsl_vector_int", 1:10 ) +@ + +A second example shows a simple function that grabs elements of an +R list as \verb|gsl_vector| objects using implicit conversion mechanisms +of \pkg{Rcpp} + +%< < 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 class +% RcppGSL::vector x = data["x"] ; + +% // grab "y" as a gsl_vector through the RcppGSL::vector class +% RcppGSL::vector 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 ; +% } +% @ + +\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}\\ [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4353 From noreply at r-forge.r-project.org Thu Jun 20 01:02:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 01:02:45 +0200 (CEST) Subject: [Rcpp-commits] r4354 - pkg/RcppGSL/vignettes Message-ID: <20130619230246.32163185791@r-forge.r-project.org> Author: romain Date: 2013-06-20 01:02:44 +0200 (Thu, 20 Jun 2013) New Revision: 4354 Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw Log: revert back Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-19 22:42:16 UTC (rev 4353) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-19 23:02:44 UTC (rev 4354) @@ -1,768 +1,11 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RcppGSL} -%\VignetteKeywords{R,GSL,Rcpp,data transfer} -%\VignettePackage{RcppGSL} -%\VignetteEngine{highlight::highlight} -\usepackage{url,color} -\usepackage[authoryear,round,longnamesfirst]{natbib} +\usepackage{url} \usepackage[colorlinks]{hyperref} -\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty -\hypersetup{ - colorlinks,% - citecolor=link,% - filecolor=link,% - linkcolor=link,% - urlcolor=link -} -\usepackage{vmargin} -\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} -\usepackage{booktabs} % fancier \hrule +\setlength{\oddsidemargin}{0pt} +\setlength{\textwidth}{17cm} % uh-oh, I use letter :) -\newcommand{\proglang}[1]{\textsf{#1}} -\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} - -\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave -\RequirePackage[T1]{fontenc} - -<>= -require(inline) -library(RcppGSL) -options("width"=65) -rcppgsl.version <- packageDescription( "RcppGSL" )$Version -prettyDate <- format(Sys.Date(), "%B %e, %Y") -@ -% closing $ needed here - -\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} -\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} -\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} - \begin{document} -\maketitle - -\abstract{ - \shortcites{GSL} %% so that we get Galassi et al instead of all names - \noindent - The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical - routines for scientific computing \citep{GSL}. It is particularly useful for - \proglang{C} and \proglang{C++} programs as it provides a standard - \proglang{C} interface to a wide range of mathematical routines such as - special functions, permutations, combinations, fast fourier transforms, - eigensystems, random numbers, quadrature, random distributions, - quasi-random sequences, Monte Carlo integration, N-tuples, differential - equations, simulated annealing, numerical differentiation, interpolation, - series acceleration, Chebyshev approximations, root-finding, discrete - Hankel transforms physical constants, basis splines and wavelets. There - are over 1000 functions in total with an extensive test suite. - - The \pkg{RcppGSL} package provides an easy-to-use interface between - \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} - \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces - between \proglang{R} and C++. -} - -\section{Introduction} - -The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical -routines for scientific computing \citep{GSL}. It is a rigourously developed -and tested library providing support for a wide range of scientific or -numerical tasks. Among the topics covered in the GSL are -%% from the GSL manual -complex numbers, roots of polynomials, -special functions, vector and matrix data structures, -permutations, combinations, sorting, BLAS support, -linear algebra, fast fourier transforms, eigensystems, -random numbers, quadrature, random distributions, quasi-random sequences, -Monte Carlo integration, N-tuples, -differential equations, simulated annealing, -numerical differentiation, interpolation, -series acceleration, Chebyshev approximations, -root-finding, discrete Hankel transforms -least-squares fitting, minimization, -physical constants, basis splines and wavelets. - -Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} -and provides a \proglang{C}-language Application Programming Interface -(API). Access from \proglang{C++} is therefore possible, albeit not at the -abstraction level that can be offered by dedicated \proglang{C++} -implementations.\footnote{Several \proglang{C++} wrappers for the GSL have - been written over the years yet none reached a state of completion - comparable to the GSL itself. Three such wrapping library are - \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, - \url{http://gslwrap.sourceforge.net/} and - \url{http://code.google.com/p/gslcpp/}.} - -The GSL is somewhat unique among numerical libraries. Its combination of -broad coverage of scientific topics, serious implementation effort and the -use of a FLOSS license have lead to a fairly wide usage of the library. As a -concrete example, we can consider the the CRAN repository network for the -\proglang{R} language and environment \citep{R:Main}. CRAN contains over a -dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, -\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, -\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and -\pkg{topicmodels}. This is a clear indication that the GSL is popular among -programmers using either the \proglang{C} or \proglang{C++} language for -solving problems applied science. - -At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a -higher-level abstraction between \proglang{R} and underlying \proglang{C++} -(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like -vectors, matrices, lists, functions, environments, $\ldots$, to be -manipulated directly at the \proglang{C++} level, alleviates the needs for -complicated and error-prone parameter passing and memory allocation. It also -permits compact vectorised expressions similar to what can be written in -\proglang{R} directly at the \proglang{C++} level. - -The \pkg{RcppGSL} package discussed here aims the help close the gap. It -tries to offer access to GSL functions, in particular via the vector and -matrix data structures used throughout the GSL, while staying closer to the -`whole object model' familar to the \proglang{R} programmer. - -The rest of paper is organised as follows. The next section shows a -motivating example of a fast linear model fit routine using \pkg{GSL} functions. -The following section discusses support for \pkg{GSL} vector types, which is -followed by a section on matrices. - -\section{Motivation: FastLm} - -Fitting linear models is a key building block of analysing data and -modeling. \proglang{R} has a very complete and feature-rich function in -\texttt{lm()} which can provide a model fit as we a number of diagnostic -measure, either directly or via the corresponding \texttt{summary()} method -for linear model fits. The \texttt{lm.fit()} function also provides a faster -alternative (which is however recommend only for for advanced users) which -provides estimates only and fewer statistics for inference. This sometimes -leads users request a routine which is both fast and featureful enough. The -\texttt{fastLm} routine shown here provides such an implementation. It uses -the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice -example for \pkg{GSL} integration with \proglang{R}. - -<>= -#include -#include -#include - -extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { - - try { - RcppGSL::vector y = ys; // create gsl data structures from SEXP - RcppGSL::matrix X = Xs; - - int n = X.nrow(), k = X.ncol(); - double chisq; - - RcppGSL::vector coef(k); // to hold the coefficient vector - RcppGSL::matrix 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); - - // 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); - - 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(); - - 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 -} -@ - -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 -as well as complex numbers). We the reserve another vector and matrix to -hold the resulting coefficient estimates as well as the estimate of the -covariance matrix. Next, we allocate workspace using a GSL routine, fit the -linear model and free the workspace. The next step involves extracting the -diagonal element from the covariance matrix. We then employ a so-called -iterator---a common \proglang{C++} idiom from the Standard Template Library -(STL)---to iterate over the vector of diagonal and transforming it by -applying the square root function to compute our standard error of the -estimate. Finally we create a named list with the return value before we free -temporary memory allocation (a step that has to be done because the -underlying objects are really \proglang{C} objects conforming to the -\pkg{GSL} interface and hence without the automatic memory management we -could have with \proglang{C++} vector or matrix structures as used through -the \pkg{Rcpp} package) and return the result to \proglang{R}. - -We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements -a matching \texttt{fastLm} function using the Armadillo library by -\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to -\proglang{C++} features. - -\section{Vectors} - -This section details the different vector represenations, starting with their -definition inside the \pkg{GSL}. We then discuss our layering before showing -how the two types map. A discussion of read-only `vector view' classes -concludes the section. - -\subsection{\pkg{GSL} Vectors} - -\pkg{GSL} defines various vector types to manipulate one-dimensionnal -data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| -structs are defined as: - -<< 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; -@ - -A typical use of the \verb|gsl_vector| struct is given below: - -<>= -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); -} - -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 -@ - -\subsection{RcppGSL::vector} - -\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector} to manipulate -\verb|gsl_vector| pointers taking advantage of C++ templates. Using this -template type, the previous example now becomes: - -<>= -int i; -RcppGSL::vector v(3); // allocate a gsl_vector of size 3 - -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] ; -} - -v.free() ; // free the memory -@ - -The class \texttt{RcppGSL::vector} 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. - -Beyond the convenience of a nicer syntax for allocation and release of -memory, the \texttt{RcppGSL::vector} template faciliates interchange of -\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The -following example defines a \texttt{.Call} compatible function called -\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through -the \texttt{RcppGSL::vector} template specialization: - -<>= -// [[Rcpp::export]] -int sum_gsl_vector_int( RcppGSL::vector vec){ - int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; - vec.free() ; // we need to free vec after use - return res ; -} -@ - -The function can then simply be called from \proglang{R} : - -<>= - -fx <- cxxfunction( - list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), - c( sum_gsl_vector_int = ' - RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; - int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; - vec.free() ; // we need to free vec after use - return wrap( res ) ; -' ), plugin = "RcppGSL" ) -<>= -.Call( "sum_gsl_vector_int", 1:10 ) -@ - -A second example shows a simple function that grabs elements of an -R list as \verb|gsl_vector| objects using implicit conversion mechanisms -of \pkg{Rcpp} - -<< example2,lang=cpp,size=small>>= -// [[Rcpp::export]] -double gsl_vector_sum_2( Rcpp::List data ){ - // grab "x" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector x = data["x"] ; - - // grab "y" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector 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 ; -} -@ - -called from \proglang{R} : - -<>= -fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ), -c( gsl_vector_sum_2 = ' - List data(data_) ; - - // grab "x" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector x = data["x"] ; - - // grab "y" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector 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 wrap(res); -' ), plugin = "RcppGSL" ) -@ -<>= -data <- list( x = seq(0,1,length=10), y = 1:10 ) -.Call( "gsl_vector_sum_2", data ) -@ - -\subsection{Mapping} - -Table~\ref{tab:mappingVectors} shows the mapping between types defined by the -\pkg{GSL} and their corresponding types in the \pkg{RcppGSL} package. - -\begin{table}[htb] - \centering - \begin{small} - \begin{tabular}{ll} - \toprule - gsl vector & RcppGSL \\ - \midrule - \texttt{gsl\_vector} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_int} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_float} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_long} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_char} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex\_float} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex\_long\_double} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_long\_double} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_short} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_uchar} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_uint} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_ushort} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_ulong} & \texttt{RcppGSL::vector} \\ - \bottomrule - \end{tabular} - \end{small} - \caption{Correspondance between \pkg{GSL} vector types and templates defined in \pkg{RcppGSL}.} - \label{tab:mappingVectors} -\end{table} - -\subsection{ Vector Views} - -Several \pkg{GSL} algorithms return \pkg{GSL} vector views as their result -type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view} -to handle vector views using \proglang{C++} syntax. - -<>= -// [[Rcpp::export]] -Rcpp::List test_gsl_vector_view(){ - int n = 10 ; - RcppGSL::vector v(n) ; - for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); - RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); - - List res = List::create( - _["even"] = v_even, - _["odd" ] = v_odd - ) ; - v.free() ; // we only need to free v, the views do not own data - return res ; -} -@ - -As with vectors, \proglang{C++} objects of type -\texttt{RcppGSL::vector\_view} can be converted implicitly to their -associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays -the pairwise correspondance so that the \proglang{C++} objects can be passed -to compatible \pkg{GSL} algorithms. - -\begin{table}[htb] - \centering - \begin{small} - \begin{tabular}{ll} - \toprule - gsl vector views & RcppGSL \\ - \midrule - \texttt{gsl\_vector\_view} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_int} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_float} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_long} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_char} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex\_float} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex\_long\_double} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_long\_double} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_short} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_uchar} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_uint} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_ushort} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_ulong} & \texttt{RcppGSL::vector\_view} \\ - \bottomrule - \end{tabular} - \end{small} - \caption{Correspondance between \pkg{GSL} vector view types and templates defined - in \pkg{RcppGSL}.} - \label{tab:mappingVectorViews} -\end{table} - -The vector view class also contains a conversion operator to automatically -transform the data of the view object to a \pkg{GSL} vector object. This -enables use of vector views where \pkg{GSL} would expect a vector. - - -\section{Matrices} - -The \pkg{GSL} also defines a set of matrix data types : \texttt{gsl\_matrix}, -\texttt{gsl\_matrix\_int} etc ... for which \pkg{RcppGSL} defines a corresponding -convenience \proglang{C++} wrapper generated by the \texttt{RcppGSL::matrix} -template. - -\subsection{Creating matrices} - -The \texttt{RcppGSL::matrix} template exposes three constructors. - -<>= -// convert an R matrix to a GSL matrix -matrix( SEXP x) throw(::Rcpp::not_compatible) - -// encapsulate a GSL matrix pointer -matrix( gsl_matrix* x) - -// create a new matrix with the given number of rows and columns -matrix( int nrow, int ncol) -@ - -\subsection{Implicit conversion} - -\texttt{RcppGSL::matrix} defines implicit conversion to a pointer to -the associated \pkg{GSL} matrix type, as well as dereferencing operators, making -the class \texttt{RcppGSL::matrix} look and feel like a pointer to a GSL -matrix type. - -<>= -gsltype* data ; -operator gsltype*(){ return data ; } -gsltype* operator->() const { return data; } -gsltype& operator*() const { return *data; } -@ - -\subsection{Indexing} - -Indexing of \pkg{GSL} matrices is usually the task of the functions -\texttt{gsl\_matrix\_get}, \texttt{gsl\_matrix\_int\_get}, ... and -\texttt{gsl\_matrix\_set}, \texttt{gsl\_matrix\_int\_set}, ... - -\pkg{RcppGSL} takes advantage of both operator overloading and templates -to make indexing a \pkg{GSL} matrix much more convenient. - -<>= -RcppGSL::matrix mat(10,10); // create a matrix of size 10x10 - -for( int i=0; i<10: i++) { // fill the diagonal - mat(i,i) = i ; -} -@ - -\subsection{Methods} - -The \texttt{RcppGSL::matrix} type also defines the following member functions: -\begin{quote} - \begin{itemize} - \item[\texttt{nrow}] extracts the number of rows - \item[\texttt{ncol}] extract the number of columns - \item[\texttt{size}] extracts the number of elements - \item[\texttt{free}] releases the memory - \end{itemize} -\end{quote} - -\subsection{Matrix views} - -Similar to the vector views discussed above, the \pkg{RcppGSL} also provides -an implicit conversion operator which returns the underlying matrix stored in -the matrix view class. - -\section{Using \pkg{RcppGSL} in your package} - -The \pkg{RcppGSL} package contains a complete example providing a single -function \texttt{colNorm} which computes a norm for each column of a -supplied matrix. This example adapts a matrix example from the GSL manual that has -been chose merely as a means to showing how to set up a package to use -\pkg{RcppGSL}. - -Needless to say, we could compute such a matrix norm easily in \proglang{R} -using existing facilities. One such possibility is a simple -\verb|apply(M, 2, function(x) sqrt(sum(x^2)))| as shown on the corresponding -help page in the example package inside \pkg{RcppGSL}. One point in favour of -using the \pkg{GSL} code is that it employs a BLAS function so on -sufficiently large matrices, and with suitable BLAS libraries installed, this -variant could be faster due to the optimised code in high-performance BLAS -libraries and/or the inherent parallelism a multi-core BLAS variant which -compute compute the vector norm in parallel. On all `reasonable' matrix -sizes, however, the performance difference should be neglible. - -\subsection{The \texttt{configure} script} - -\subsubsection{Using autoconf} - -Using \pkg{RcppGSL} means employing both the \pkg{GSL} and \proglang{R}. We -may need to find the location of the \pkg{GSL} headers and library, and this -done easily from a \texttt{configure} source script which \texttt{autoconf} -generates from a \texttt{configure.in} source file such as the following: - -<>= -AC_INIT([RcppGSLExample], 0.1.0) - -## Use gsl-config to find arguments for compiler and linker flags -## -## Check for non-standard programs: gsl-config(1) -AC_PATH_PROG([GSL_CONFIG], [gsl-config]) -## If gsl-config was found, let's use it -if test "${GSL_CONFIG}" != ""; then - # Use gsl-config for header and linker arguments (without BLAS which we get from R) - GSL_CFLAGS=`${GSL_CONFIG} --cflags` - GSL_LIBS=`${GSL_CONFIG} --libs-without-cblas` -else - AC_MSG_ERROR([gsl-config not found, is GSL installed?]) -fi - -## Use Rscript to query Rcpp for compiler and linker flags -## link flag providing libary as well as path to library, and optionally rpath -RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'` - -# Now substitute these variables in src/Makevars.in to create src/Makevars -AC_SUBST(GSL_CFLAGS) -AC_SUBST(GSL_LIBS) -AC_SUBST(RCPP_LDFLAGS) - -AC_OUTPUT(src/Makevars) -@ - -Such a source \texttt{configure.in} gets converted into a script -\texttt{configure} by invoking the \texttt{autoconf} program. - -\subsubsection{Using functions provided by RcppGSL} - -\pkg{RcppGSL} provides R functions that allows one to retrieve the same -information. Therefore the configure script can also be written as: - -<>= -#!/bin/sh - -GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` -GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` -RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"` - -sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ - -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ - -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ - src/Makevars.in > src/Makevars -@ - -Similarly, the configure.win for windows can be written as: - -<>= -GSL_CFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::CFlags()"` -GSL_LIBS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::LdFlags()"` -RCPP_LDFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()"` - -sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ - -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ - -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ - src/Makevars.in > src/Makevars.win -@ - -\subsection{The \texttt{src} directory} - -The \proglang{C++} source file takes the matrix supplied from \proglang{R} -and applies the \pkg{GSL} function to each column. - -<>= -#include -#include -#include - -extern "C" SEXP colNorm(SEXP sM) { - - try { - - RcppGSL::matrix M = sM; // create gsl data structures from SEXP - int k = M.ncol(); - Rcpp::NumericVector n(k); // to store results - - for (int j = 0; j < k; j++) { - RcppGSL::vector_view colview = gsl_matrix_column (M, j); - n[j] = gsl_blas_dnrm2(colview); - } - M.free() ; - return n; // return vector - - } catch( std::exception &ex ) { - forward_exception_to_r( ex ); - - } catch(...) { - ::Rf_error( "c++ exception (unknown reason)" ); - } - return R_NilValue; // -Wall -} -@ - -The \proglang{Makevars.in} file governs the compilation and uses the values -supplied by \texttt{configure} during build-time: - -<>= - -# set by configure -GSL_CFLAGS = @GSL_CFLAGS@ -GSL_LIBS = @GSL_LIBS@ -RCPP_LDFLAGS = @RCPP_LDFLAGS@ - -# combine with standard arguments for R -PKG_CPPFLAGS = $(GSL_CFLAGS) -PKG_LIBS = $(GSL_LIBS) $(RCPP_LDFLAGS) -@ - -The variables surrounded by \@ will be filled by \texttt{configure} during -package build-time. - -\subsection{The \texttt{R} directory} - -The \proglang{R} source is very simply: a single matrix is passed to \proglang{C++}: - -<>= -colNorm <- function(M) { - stopifnot(is.matrix(M)) - res <- .Call("colNorm", M, package="RcppGSLExample") -} -@ - -\section{Using \pkg{RcppGSL} with \pkg{inline}} - -The \pkg{inline} package \citep{CRAN:inline} is very helpful for prototyping code in -\proglang{C}, \proglang{C++} or \proglang{Fortran} as it takes care of code -compilation, linking and dynamic loading directly from \proglang{R}. It is -being used extensively by \pkg{Rcpp}, for example in the numerous unit tests. - -The example below shows how \pkg{inline} can be deployed with -\pkg{RcppGSL}. We implement the same column norm example, but this time as an -\proglang{R} script which is compiled, linked and loaded on-the-fly. Compared -to standard use of \pkg{inline}, we have to make sure to add a short section -declaring which header files from \pkg{GSL} we need to use; the \pkg{RcppGSL} -then communicates with \pkg{inline} to tell it about the location and names -of libraries used to build code against \pkg{GSL}. - -<<>>= -require(inline) - -inctxt=' - #include - #include -' - -bodytxt=' - RcppGSL::matrix M = sM; // create gsl data structures from SEXP - int k = M.ncol(); - Rcpp::NumericVector n(k); // to store results - - for (int j = 0; j < k; j++) { - RcppGSL::vector_view colview = gsl_matrix_column (M, j); - n[j] = gsl_blas_dnrm2(colview); - } - M.free() ; - return n; // return vector -' - -foo <- cxxfunction( - signature(sM="numeric"), - body=bodytxt, inc=inctxt, plugin="RcppGSL") - -## see Section 8.4.13 of the GSL manual: create M as a sum of two outer products -M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*") -foo(M) -@ - -The \texttt{RcppGSL} inline plugin supports creation of a package skeleton -based on the inline function. - -<>= -package.skeleton( "mypackage", foo ) -@ - -\section{Summary} - -The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive -collection of rigorously developed and tested functions for applied -scientific computing under a common Open Source license. This has lead to -widespread deployment of \pkg{GSL} among a number of disciplines. - -Using the automatic wrapping and converters offered by the \pkg{RcppGSL} -package presented here, \proglang{R} users and programmers can now deploy -algorithmns provided by the \pkg{GSL} with greater ease. - -\bibliographystyle{plainnat} -\bibliography{\Sexpr{Rcpp:::bib()}} - \end{document} From noreply at r-forge.r-project.org Thu Jun 20 03:15:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 03:15:27 +0200 (CEST) Subject: [Rcpp-commits] r4355 - in pkg/RcppGSL: . vignettes Message-ID: <20130620011528.37291185763@r-forge.r-project.org> Author: edd Date: 2013-06-20 03:15:22 +0200 (Thu, 20 Jun 2013) New Revision: 4355 Removed: pkg/RcppGSL/vignettes/Makefile pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw pkg/RcppGSL/vignettes/RcppGSL/ pkg/RcppGSL/vignettes/unitTests-results/ pkg/RcppGSL/vignettes/unitTests/ Modified: pkg/RcppGSL/DESCRIPTION pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw Log: undoing 4353 and 4354 Modified: pkg/RcppGSL/DESCRIPTION =================================================================== --- pkg/RcppGSL/DESCRIPTION 2013-06-19 23:02:44 UTC (rev 4354) +++ pkg/RcppGSL/DESCRIPTION 2013-06-20 01:15:22 UTC (rev 4355) @@ -31,3 +31,4 @@ Suggests: RUnit, inline LinkingTo: Rcpp SystemRequirements: GNU GSL +VignetteBuilder: highlight Deleted: pkg/RcppGSL/vignettes/Makefile =================================================================== --- pkg/RcppGSL/vignettes/Makefile 2013-06-19 23:02:44 UTC (rev 4354) +++ pkg/RcppGSL/vignettes/Makefile 2013-06-20 01:15:22 UTC (rev 4355) @@ -1,50 +0,0 @@ - -## There is an old bug in texidvi that makes it not swallow the ~ -## marker used to denote whitespace. This is actually due to fixing -## another bug whereby you could not run texidvi on directory names -## containing a tilde (as we happen to do for Debian builds of R -## alpha/beta/rc releases). The 'tilde' bug will go away as it -## reportedly has been squashed upstream but I am still bitten by it -## on Ubuntu so for now Dirk will insist on pdflatex and this helps. -whoami=$(shell whoami) - -all: RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -clean: - rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl *~ - rm -rf auto/ - -pdfclean: - rm -f RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -setvars: -ifeq (${R_HOME},) -R_HOME= $(shell R RHOME) -endif -RPROG= $(R_HOME)/bin/R -RSCRIPT=$(R_HOME)/bin/Rscript - -RcppGSL-unitTests.pdf: - rm -fr unitTests-results/* - $(RSCRIPT) --vanilla unitTests/RcppGSL-unitTests.R - $(RPROG) CMD Sweave RcppGSL-unitTests.Rnw - $(RSCRIPT) --vanilla -e "tools::texi2dvi( 'RcppGSL-unitTests.tex', pdf = TRUE, clean = TRUE )" - rm -fr RcppGSL-unitTests.tex - -RcppGSL-intro.pdf: RcppGSL/RcppGSL-intro.Rnw - cp -f RcppGSL/RcppGSL-intro.Rnw . - $(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE); Sweave( 'RcppGSL-intro.Rnw', driver = driver ); " -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = FALSE )" -endif - bibtex RcppGSL-intro -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = TRUE )" -endif - rm -fr RcppGSL-intro.tex RcppGSL-intro.bbl RcppGSL-intro.blg RcppGSL-intro.aux RcppGSL-intro.out RcppGSL-intro.log - cp RcppGSL/RcppGSL-fake.Rnw RcppGSL-intro.Rnw Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-19 23:02:44 UTC (rev 4354) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-20 01:15:22 UTC (rev 4355) @@ -1,11 +1,768 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RcppGSL} +%\VignetteKeywords{R,GSL,Rcpp,data transfer} +%\VignettePackage{RcppGSL} +%\VignetteEngine{highlight::highlight} -\usepackage{url} +\usepackage{url,color} +\usepackage[authoryear,round,longnamesfirst]{natbib} \usepackage[colorlinks]{hyperref} -\setlength{\oddsidemargin}{0pt} -\setlength{\textwidth}{17cm} % uh-oh, I use letter :) +\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} +\usepackage{vmargin} +\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} +\usepackage{booktabs} % fancier \hrule +\newcommand{\proglang}[1]{\textsf{#1}} +\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} + +\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave +\RequirePackage[T1]{fontenc} + +<>= +require(inline) +library(RcppGSL) +options("width"=65) +rcppgsl.version <- packageDescription( "RcppGSL" )$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +@ +% closing $ needed here + +\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} +\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} +\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} + \begin{document} +\maketitle + +\abstract{ + \shortcites{GSL} %% so that we get Galassi et al instead of all names + \noindent + The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical + routines for scientific computing \citep{GSL}. It is particularly useful for + \proglang{C} and \proglang{C++} programs as it provides a standard + \proglang{C} interface to a wide range of mathematical routines such as + special functions, permutations, combinations, fast fourier transforms, + eigensystems, random numbers, quadrature, random distributions, + quasi-random sequences, Monte Carlo integration, N-tuples, differential + equations, simulated annealing, numerical differentiation, interpolation, + series acceleration, Chebyshev approximations, root-finding, discrete + Hankel transforms physical constants, basis splines and wavelets. There + are over 1000 functions in total with an extensive test suite. + + The \pkg{RcppGSL} package provides an easy-to-use interface between + \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} + \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces + between \proglang{R} and C++. +} + +\section{Introduction} + +The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical +routines for scientific computing \citep{GSL}. It is a rigourously developed +and tested library providing support for a wide range of scientific or +numerical tasks. Among the topics covered in the GSL are +%% from the GSL manual +complex numbers, roots of polynomials, +special functions, vector and matrix data structures, +permutations, combinations, sorting, BLAS support, +linear algebra, fast fourier transforms, eigensystems, +random numbers, quadrature, random distributions, quasi-random sequences, +Monte Carlo integration, N-tuples, +differential equations, simulated annealing, +numerical differentiation, interpolation, +series acceleration, Chebyshev approximations, +root-finding, discrete Hankel transforms +least-squares fitting, minimization, +physical constants, basis splines and wavelets. + +Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} +and provides a \proglang{C}-language Application Programming Interface +(API). Access from \proglang{C++} is therefore possible, albeit not at the +abstraction level that can be offered by dedicated \proglang{C++} +implementations.\footnote{Several \proglang{C++} wrappers for the GSL have + been written over the years yet none reached a state of completion + comparable to the GSL itself. Three such wrapping library are + \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, + \url{http://gslwrap.sourceforge.net/} and + \url{http://code.google.com/p/gslcpp/}.} + +The GSL is somewhat unique among numerical libraries. Its combination of +broad coverage of scientific topics, serious implementation effort and the +use of a FLOSS license have lead to a fairly wide usage of the library. As a +concrete example, we can consider the the CRAN repository network for the +\proglang{R} language and environment \citep{R:Main}. CRAN contains over a +dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, +\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, +\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and +\pkg{topicmodels}. This is a clear indication that the GSL is popular among +programmers using either the \proglang{C} or \proglang{C++} language for +solving problems applied science. + +At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a +higher-level abstraction between \proglang{R} and underlying \proglang{C++} +(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like +vectors, matrices, lists, functions, environments, $\ldots$, to be +manipulated directly at the \proglang{C++} level, alleviates the needs for +complicated and error-prone parameter passing and memory allocation. It also +permits compact vectorised expressions similar to what can be written in +\proglang{R} directly at the \proglang{C++} level. + +The \pkg{RcppGSL} package discussed here aims the help close the gap. It +tries to offer access to GSL functions, in particular via the vector and +matrix data structures used throughout the GSL, while staying closer to the +`whole object model' familar to the \proglang{R} programmer. + +The rest of paper is organised as follows. The next section shows a +motivating example of a fast linear model fit routine using \pkg{GSL} functions. +The following section discusses support for \pkg{GSL} vector types, which is +followed by a section on matrices. + +\section{Motivation: FastLm} + +Fitting linear models is a key building block of analysing data and +modeling. \proglang{R} has a very complete and feature-rich function in +\texttt{lm()} which can provide a model fit as we a number of diagnostic +measure, either directly or via the corresponding \texttt{summary()} method +for linear model fits. The \texttt{lm.fit()} function also provides a faster +alternative (which is however recommend only for for advanced users) which +provides estimates only and fewer statistics for inference. This sometimes +leads users request a routine which is both fast and featureful enough. The +\texttt{fastLm} routine shown here provides such an implementation. It uses +the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice +example for \pkg{GSL} integration with \proglang{R}. + +<>= +#include +#include +#include + +extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { + + try { + RcppGSL::vector y = ys; // create gsl data structures from SEXP + RcppGSL::matrix X = Xs; + + int n = X.nrow(), k = X.ncol(); + double chisq; + + RcppGSL::vector coef(k); // to hold the coefficient vector + RcppGSL::matrix 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); + + // 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); + + 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(); + + 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 +} +@ + +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 +as well as complex numbers). We the reserve another vector and matrix to +hold the resulting coefficient estimates as well as the estimate of the +covariance matrix. Next, we allocate workspace using a GSL routine, fit the +linear model and free the workspace. The next step involves extracting the +diagonal element from the covariance matrix. We then employ a so-called +iterator---a common \proglang{C++} idiom from the Standard Template Library +(STL)---to iterate over the vector of diagonal and transforming it by +applying the square root function to compute our standard error of the +estimate. Finally we create a named list with the return value before we free +temporary memory allocation (a step that has to be done because the +underlying objects are really \proglang{C} objects conforming to the +\pkg{GSL} interface and hence without the automatic memory management we +could have with \proglang{C++} vector or matrix structures as used through +the \pkg{Rcpp} package) and return the result to \proglang{R}. + +We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements +a matching \texttt{fastLm} function using the Armadillo library by +\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to +\proglang{C++} features. + +\section{Vectors} + +This section details the different vector represenations, starting with their +definition inside the \pkg{GSL}. We then discuss our layering before showing +how the two types map. A discussion of read-only `vector view' classes +concludes the section. + +\subsection{\pkg{GSL} Vectors} + +\pkg{GSL} defines various vector types to manipulate one-dimensionnal +data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| +structs are defined as: + +<< 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; +@ + +A typical use of the \verb|gsl_vector| struct is given below: + +<>= +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); +} + +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 +@ + +\subsection{RcppGSL::vector} + +\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector} to manipulate +\verb|gsl_vector| pointers taking advantage of C++ templates. Using this +template type, the previous example now becomes: + +<>= +int i; +RcppGSL::vector v(3); // allocate a gsl_vector of size 3 + +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] ; +} + +v.free() ; // free the memory +@ + +The class \texttt{RcppGSL::vector} 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. + +Beyond the convenience of a nicer syntax for allocation and release of +memory, the \texttt{RcppGSL::vector} template faciliates interchange of +\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The +following example defines a \texttt{.Call} compatible function called +\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through +the \texttt{RcppGSL::vector} template specialization: + +<>= +// [[Rcpp::export]] +int sum_gsl_vector_int( RcppGSL::vector vec){ + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return res ; +} +@ + +The function can then simply be called from \proglang{R} : + +<>= + +fx <- cxxfunction( + list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), + c( sum_gsl_vector_int = ' + RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return wrap( res ) ; +' ), plugin = "RcppGSL" ) +<>= +.Call( "sum_gsl_vector_int", 1:10 ) +@ + +A second example shows a simple function that grabs elements of an +R list as \verb|gsl_vector| objects using implicit conversion mechanisms +of \pkg{Rcpp} + +<< example2,lang=cpp,size=small>>= +// [[Rcpp::export]] +double gsl_vector_sum_2( Rcpp::List data ){ + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 ; +} +@ + +called from \proglang{R} : + +<>= +fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ), +c( gsl_vector_sum_2 = ' + List data(data_) ; + + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 wrap(res); +' ), plugin = "RcppGSL" ) +@ +<>= +data <- list( x = seq(0,1,length=10), y = 1:10 ) +.Call( "gsl_vector_sum_2", data ) +@ + +\subsection{Mapping} + +Table~\ref{tab:mappingVectors} shows the mapping between types defined by the +\pkg{GSL} and their corresponding types in the \pkg{RcppGSL} package. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector & RcppGSL \\ + \midrule + \texttt{gsl\_vector} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_int} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_char} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_short} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uchar} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uint} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ushort} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ulong} & \texttt{RcppGSL::vector} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector types and templates defined in \pkg{RcppGSL}.} + \label{tab:mappingVectors} +\end{table} + +\subsection{ Vector Views} + +Several \pkg{GSL} algorithms return \pkg{GSL} vector views as their result +type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view} +to handle vector views using \proglang{C++} syntax. + +<>= +// [[Rcpp::export]] +Rcpp::List test_gsl_vector_view(){ + int n = 10 ; + RcppGSL::vector v(n) ; + for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); + RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); + + List res = List::create( + _["even"] = v_even, + _["odd" ] = v_odd + ) ; + v.free() ; // we only need to free v, the views do not own data + return res ; +} +@ + +As with vectors, \proglang{C++} objects of type +\texttt{RcppGSL::vector\_view} can be converted implicitly to their +associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays +the pairwise correspondance so that the \proglang{C++} objects can be passed +to compatible \pkg{GSL} algorithms. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector views & RcppGSL \\ + \midrule + \texttt{gsl\_vector\_view} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_int} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_char} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_short} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uchar} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uint} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ushort} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ulong} & \texttt{RcppGSL::vector\_view} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector view types and templates defined + in \pkg{RcppGSL}.} + \label{tab:mappingVectorViews} +\end{table} + +The vector view class also contains a conversion operator to automatically +transform the data of the view object to a \pkg{GSL} vector object. This +enables use of vector views where \pkg{GSL} would expect a vector. + + +\section{Matrices} + +The \pkg{GSL} also defines a set of matrix data types : \texttt{gsl\_matrix}, +\texttt{gsl\_matrix\_int} etc ... for which \pkg{RcppGSL} defines a corresponding +convenience \proglang{C++} wrapper generated by the \texttt{RcppGSL::matrix} +template. + +\subsection{Creating matrices} + +The \texttt{RcppGSL::matrix} template exposes three constructors. + +<>= +// convert an R matrix to a GSL matrix +matrix( SEXP x) throw(::Rcpp::not_compatible) + +// encapsulate a GSL matrix pointer +matrix( gsl_matrix* x) + +// create a new matrix with the given number of rows and columns +matrix( int nrow, int ncol) +@ + +\subsection{Implicit conversion} + +\texttt{RcppGSL::matrix} defines implicit conversion to a pointer to +the associated \pkg{GSL} matrix type, as well as dereferencing operators, making +the class \texttt{RcppGSL::matrix} look and feel like a pointer to a GSL +matrix type. + +<>= +gsltype* data ; +operator gsltype*(){ return data ; } +gsltype* operator->() const { return data; } +gsltype& operator*() const { return *data; } +@ + +\subsection{Indexing} + +Indexing of \pkg{GSL} matrices is usually the task of the functions +\texttt{gsl\_matrix\_get}, \texttt{gsl\_matrix\_int\_get}, ... and +\texttt{gsl\_matrix\_set}, \texttt{gsl\_matrix\_int\_set}, ... + +\pkg{RcppGSL} takes advantage of both operator overloading and templates +to make indexing a \pkg{GSL} matrix much more convenient. + +<>= +RcppGSL::matrix mat(10,10); // create a matrix of size 10x10 + +for( int i=0; i<10: i++) { // fill the diagonal + mat(i,i) = i ; +} +@ + +\subsection{Methods} + +The \texttt{RcppGSL::matrix} type also defines the following member functions: +\begin{quote} + \begin{itemize} + \item[\texttt{nrow}] extracts the number of rows + \item[\texttt{ncol}] extract the number of columns + \item[\texttt{size}] extracts the number of elements + \item[\texttt{free}] releases the memory + \end{itemize} +\end{quote} + +\subsection{Matrix views} + +Similar to the vector views discussed above, the \pkg{RcppGSL} also provides +an implicit conversion operator which returns the underlying matrix stored in +the matrix view class. + +\section{Using \pkg{RcppGSL} in your package} + +The \pkg{RcppGSL} package contains a complete example providing a single +function \texttt{colNorm} which computes a norm for each column of a +supplied matrix. This example adapts a matrix example from the GSL manual that has +been chose merely as a means to showing how to set up a package to use +\pkg{RcppGSL}. + +Needless to say, we could compute such a matrix norm easily in \proglang{R} +using existing facilities. One such possibility is a simple +\verb|apply(M, 2, function(x) sqrt(sum(x^2)))| as shown on the corresponding +help page in the example package inside \pkg{RcppGSL}. One point in favour of +using the \pkg{GSL} code is that it employs a BLAS function so on +sufficiently large matrices, and with suitable BLAS libraries installed, this +variant could be faster due to the optimised code in high-performance BLAS +libraries and/or the inherent parallelism a multi-core BLAS variant which +compute compute the vector norm in parallel. On all `reasonable' matrix +sizes, however, the performance difference should be neglible. + +\subsection{The \texttt{configure} script} + +\subsubsection{Using autoconf} + +Using \pkg{RcppGSL} means employing both the \pkg{GSL} and \proglang{R}. We +may need to find the location of the \pkg{GSL} headers and library, and this +done easily from a \texttt{configure} source script which \texttt{autoconf} +generates from a \texttt{configure.in} source file such as the following: + +<>= +AC_INIT([RcppGSLExample], 0.1.0) + +## Use gsl-config to find arguments for compiler and linker flags +## +## Check for non-standard programs: gsl-config(1) +AC_PATH_PROG([GSL_CONFIG], [gsl-config]) +## If gsl-config was found, let's use it +if test "${GSL_CONFIG}" != ""; then + # Use gsl-config for header and linker arguments (without BLAS which we get from R) + GSL_CFLAGS=`${GSL_CONFIG} --cflags` + GSL_LIBS=`${GSL_CONFIG} --libs-without-cblas` +else + AC_MSG_ERROR([gsl-config not found, is GSL installed?]) +fi + +## Use Rscript to query Rcpp for compiler and linker flags +## link flag providing libary as well as path to library, and optionally rpath +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'` + +# Now substitute these variables in src/Makevars.in to create src/Makevars +AC_SUBST(GSL_CFLAGS) +AC_SUBST(GSL_LIBS) +AC_SUBST(RCPP_LDFLAGS) + +AC_OUTPUT(src/Makevars) +@ + +Such a source \texttt{configure.in} gets converted into a script +\texttt{configure} by invoking the \texttt{autoconf} program. + +\subsubsection{Using functions provided by RcppGSL} + +\pkg{RcppGSL} provides R functions that allows one to retrieve the same +information. Therefore the configure script can also be written as: + +<>= +#!/bin/sh + +GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars +@ + +Similarly, the configure.win for windows can be written as: + +<>= +GSL_CFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars.win +@ + +\subsection{The \texttt{src} directory} + +The \proglang{C++} source file takes the matrix supplied from \proglang{R} +and applies the \pkg{GSL} function to each column. + +<>= +#include +#include +#include + +extern "C" SEXP colNorm(SEXP sM) { + + try { + + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector + + } catch( std::exception &ex ) { + forward_exception_to_r( ex ); + + } catch(...) { + ::Rf_error( "c++ exception (unknown reason)" ); + } + return R_NilValue; // -Wall +} +@ + +The \proglang{Makevars.in} file governs the compilation and uses the values +supplied by \texttt{configure} during build-time: + +<>= + +# set by configure +GSL_CFLAGS = @GSL_CFLAGS@ +GSL_LIBS = @GSL_LIBS@ +RCPP_LDFLAGS = @RCPP_LDFLAGS@ + +# combine with standard arguments for R +PKG_CPPFLAGS = $(GSL_CFLAGS) +PKG_LIBS = $(GSL_LIBS) $(RCPP_LDFLAGS) +@ + +The variables surrounded by \@ will be filled by \texttt{configure} during +package build-time. + +\subsection{The \texttt{R} directory} + +The \proglang{R} source is very simply: a single matrix is passed to \proglang{C++}: + +<>= +colNorm <- function(M) { + stopifnot(is.matrix(M)) + res <- .Call("colNorm", M, package="RcppGSLExample") +} +@ + +\section{Using \pkg{RcppGSL} with \pkg{inline}} + +The \pkg{inline} package \citep{CRAN:inline} is very helpful for prototyping code in +\proglang{C}, \proglang{C++} or \proglang{Fortran} as it takes care of code +compilation, linking and dynamic loading directly from \proglang{R}. It is +being used extensively by \pkg{Rcpp}, for example in the numerous unit tests. + +The example below shows how \pkg{inline} can be deployed with +\pkg{RcppGSL}. We implement the same column norm example, but this time as an +\proglang{R} script which is compiled, linked and loaded on-the-fly. Compared +to standard use of \pkg{inline}, we have to make sure to add a short section +declaring which header files from \pkg{GSL} we need to use; the \pkg{RcppGSL} +then communicates with \pkg{inline} to tell it about the location and names +of libraries used to build code against \pkg{GSL}. + +<<>>= +require(inline) + +inctxt=' + #include + #include +' + +bodytxt=' + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector +' + +foo <- cxxfunction( + signature(sM="numeric"), + body=bodytxt, inc=inctxt, plugin="RcppGSL") + +## see Section 8.4.13 of the GSL manual: create M as a sum of two outer products +M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*") +foo(M) +@ + +The \texttt{RcppGSL} inline plugin supports creation of a package skeleton +based on the inline function. + +<>= +package.skeleton( "mypackage", foo ) +@ + +\section{Summary} + +The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive +collection of rigorously developed and tested functions for applied +scientific computing under a common Open Source license. This has lead to +widespread deployment of \pkg{GSL} among a number of disciplines. + +Using the automatic wrapping and converters offered by the \pkg{RcppGSL} +package presented here, \proglang{R} users and programmers can now deploy +algorithmns provided by the \pkg{GSL} with greater ease. + +\bibliographystyle{plainnat} +\bibliography{\Sexpr{Rcpp:::bib()}} + \end{document} Deleted: pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-19 23:02:44 UTC (rev 4354) +++ pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-20 01:15:22 UTC (rev 4355) @@ -1,36 +0,0 @@ -\documentclass[10pt]{article} -%\VignetteIndexEntry{RcppGSL-unitTests} -%\VignetteKeywords{R,GSL,Rcpp,unit tests} -%\VignettePackage{RcppGSL} - -\usepackage{vmargin} -\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} - -\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave -\RequirePackage[T1]{fontenc} - -<>= -require( RcppGSL ) -prettyVersion <- packageDescription("RcppGSL")$Version -prettyDate <- format(Sys.Date(), "%B %e, %Y") -@ - -\usepackage[colorlinks]{hyperref} -\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} -\title{\texttt{RcppGSL}: Unit testing results} -\date{\texttt{RcppGSL} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} -\begin{document} -\maketitle - -\begin{verbatim} -<>= [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4355 From noreply at r-forge.r-project.org Thu Jun 20 03:17:34 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 03:17:34 +0200 (CEST) Subject: [Rcpp-commits] r4356 - pkg/RcppGSL/vignettes Message-ID: <20130620011734.C5900185900@r-forge.r-project.org> Author: edd Date: 2013-06-20 03:17:33 +0200 (Thu, 20 Jun 2013) New Revision: 4356 Added: pkg/RcppGSL/vignettes/Makefile pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw pkg/RcppGSL/vignettes/RcppGSL/ pkg/RcppGSL/vignettes/unitTests-results/ pkg/RcppGSL/vignettes/unitTests/ Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw Log: undoing 4345 and 4346 Copied: pkg/RcppGSL/vignettes/Makefile (from rev 4344, pkg/RcppGSL/vignettes/Makefile) =================================================================== --- pkg/RcppGSL/vignettes/Makefile (rev 0) +++ pkg/RcppGSL/vignettes/Makefile 2013-06-20 01:17:33 UTC (rev 4356) @@ -0,0 +1,50 @@ + +## There is an old bug in texidvi that makes it not swallow the ~ +## marker used to denote whitespace. This is actually due to fixing +## another bug whereby you could not run texidvi on directory names +## containing a tilde (as we happen to do for Debian builds of R +## alpha/beta/rc releases). The 'tilde' bug will go away as it +## reportedly has been squashed upstream but I am still bitten by it +## on Ubuntu so for now Dirk will insist on pdflatex and this helps. +whoami=$(shell whoami) + +all: RcppGSL-unitTests.pdf RcppGSL-intro.pdf + +clean: + rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl *~ + rm -rf auto/ + +pdfclean: + rm -f RcppGSL-unitTests.pdf RcppGSL-intro.pdf + +setvars: +ifeq (${R_HOME},) +R_HOME= $(shell R RHOME) +endif +RPROG= $(R_HOME)/bin/R +RSCRIPT=$(R_HOME)/bin/Rscript + +RcppGSL-unitTests.pdf: + rm -fr unitTests-results/* + $(RSCRIPT) --vanilla unitTests/RcppGSL-unitTests.R + $(RPROG) CMD Sweave RcppGSL-unitTests.Rnw + $(RSCRIPT) --vanilla -e "tools::texi2dvi( 'RcppGSL-unitTests.tex', pdf = TRUE, clean = TRUE )" + rm -fr RcppGSL-unitTests.tex + +RcppGSL-intro.pdf: RcppGSL/RcppGSL-intro.Rnw + cp -f RcppGSL/RcppGSL-intro.Rnw . + $(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE); Sweave( 'RcppGSL-intro.Rnw', driver = driver ); " +ifneq (,$(findstring edd,$(whoami))) + pdflatex RcppGSL-intro +else + $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = FALSE )" +endif + bibtex RcppGSL-intro +ifneq (,$(findstring edd,$(whoami))) + pdflatex RcppGSL-intro + pdflatex RcppGSL-intro +else + $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = TRUE )" +endif + rm -fr RcppGSL-intro.tex RcppGSL-intro.bbl RcppGSL-intro.blg RcppGSL-intro.aux RcppGSL-intro.out RcppGSL-intro.log + cp RcppGSL/RcppGSL-fake.Rnw RcppGSL-intro.Rnw Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-20 01:15:22 UTC (rev 4355) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-20 01:17:33 UTC (rev 4356) @@ -1,768 +1,11 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RcppGSL} -%\VignetteKeywords{R,GSL,Rcpp,data transfer} -%\VignettePackage{RcppGSL} -%\VignetteEngine{highlight::highlight} -\usepackage{url,color} -\usepackage[authoryear,round,longnamesfirst]{natbib} +\usepackage{url} \usepackage[colorlinks]{hyperref} -\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty -\hypersetup{ - colorlinks,% - citecolor=link,% - filecolor=link,% - linkcolor=link,% - urlcolor=link -} -\usepackage{vmargin} -\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} -\usepackage{booktabs} % fancier \hrule +\setlength{\oddsidemargin}{0pt} +\setlength{\textwidth}{17cm} % uh-oh, I use letter :) -\newcommand{\proglang}[1]{\textsf{#1}} -\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} - -\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave -\RequirePackage[T1]{fontenc} - -<>= -require(inline) -library(RcppGSL) -options("width"=65) -rcppgsl.version <- packageDescription( "RcppGSL" )$Version -prettyDate <- format(Sys.Date(), "%B %e, %Y") -@ -% closing $ needed here - -\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} -\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} -\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} - \begin{document} -\maketitle - -\abstract{ - \shortcites{GSL} %% so that we get Galassi et al instead of all names - \noindent - The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical - routines for scientific computing \citep{GSL}. It is particularly useful for - \proglang{C} and \proglang{C++} programs as it provides a standard - \proglang{C} interface to a wide range of mathematical routines such as - special functions, permutations, combinations, fast fourier transforms, - eigensystems, random numbers, quadrature, random distributions, - quasi-random sequences, Monte Carlo integration, N-tuples, differential - equations, simulated annealing, numerical differentiation, interpolation, - series acceleration, Chebyshev approximations, root-finding, discrete - Hankel transforms physical constants, basis splines and wavelets. There - are over 1000 functions in total with an extensive test suite. - - The \pkg{RcppGSL} package provides an easy-to-use interface between - \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} - \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces - between \proglang{R} and C++. -} - -\section{Introduction} - -The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical -routines for scientific computing \citep{GSL}. It is a rigourously developed -and tested library providing support for a wide range of scientific or -numerical tasks. Among the topics covered in the GSL are -%% from the GSL manual -complex numbers, roots of polynomials, -special functions, vector and matrix data structures, -permutations, combinations, sorting, BLAS support, -linear algebra, fast fourier transforms, eigensystems, -random numbers, quadrature, random distributions, quasi-random sequences, -Monte Carlo integration, N-tuples, -differential equations, simulated annealing, -numerical differentiation, interpolation, -series acceleration, Chebyshev approximations, -root-finding, discrete Hankel transforms -least-squares fitting, minimization, -physical constants, basis splines and wavelets. - -Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} -and provides a \proglang{C}-language Application Programming Interface -(API). Access from \proglang{C++} is therefore possible, albeit not at the -abstraction level that can be offered by dedicated \proglang{C++} -implementations.\footnote{Several \proglang{C++} wrappers for the GSL have - been written over the years yet none reached a state of completion - comparable to the GSL itself. Three such wrapping library are - \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, - \url{http://gslwrap.sourceforge.net/} and - \url{http://code.google.com/p/gslcpp/}.} - -The GSL is somewhat unique among numerical libraries. Its combination of -broad coverage of scientific topics, serious implementation effort and the -use of a FLOSS license have lead to a fairly wide usage of the library. As a -concrete example, we can consider the the CRAN repository network for the -\proglang{R} language and environment \citep{R:Main}. CRAN contains over a -dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, -\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, -\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and -\pkg{topicmodels}. This is a clear indication that the GSL is popular among -programmers using either the \proglang{C} or \proglang{C++} language for -solving problems applied science. - -At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a -higher-level abstraction between \proglang{R} and underlying \proglang{C++} -(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like -vectors, matrices, lists, functions, environments, $\ldots$, to be -manipulated directly at the \proglang{C++} level, alleviates the needs for -complicated and error-prone parameter passing and memory allocation. It also -permits compact vectorised expressions similar to what can be written in -\proglang{R} directly at the \proglang{C++} level. - -The \pkg{RcppGSL} package discussed here aims the help close the gap. It -tries to offer access to GSL functions, in particular via the vector and -matrix data structures used throughout the GSL, while staying closer to the -`whole object model' familar to the \proglang{R} programmer. - -The rest of paper is organised as follows. The next section shows a -motivating example of a fast linear model fit routine using \pkg{GSL} functions. -The following section discusses support for \pkg{GSL} vector types, which is -followed by a section on matrices. - -\section{Motivation: FastLm} - -Fitting linear models is a key building block of analysing data and -modeling. \proglang{R} has a very complete and feature-rich function in -\texttt{lm()} which can provide a model fit as we a number of diagnostic -measure, either directly or via the corresponding \texttt{summary()} method -for linear model fits. The \texttt{lm.fit()} function also provides a faster -alternative (which is however recommend only for for advanced users) which -provides estimates only and fewer statistics for inference. This sometimes -leads users request a routine which is both fast and featureful enough. The -\texttt{fastLm} routine shown here provides such an implementation. It uses -the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice -example for \pkg{GSL} integration with \proglang{R}. - -<>= -#include -#include -#include - -extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { - - try { - RcppGSL::vector y = ys; // create gsl data structures from SEXP - RcppGSL::matrix X = Xs; - - int n = X.nrow(), k = X.ncol(); - double chisq; - - RcppGSL::vector coef(k); // to hold the coefficient vector - RcppGSL::matrix 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); - - // 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); - - 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(); - - 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 -} -@ - -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 -as well as complex numbers). We the reserve another vector and matrix to -hold the resulting coefficient estimates as well as the estimate of the -covariance matrix. Next, we allocate workspace using a GSL routine, fit the -linear model and free the workspace. The next step involves extracting the -diagonal element from the covariance matrix. We then employ a so-called -iterator---a common \proglang{C++} idiom from the Standard Template Library -(STL)---to iterate over the vector of diagonal and transforming it by -applying the square root function to compute our standard error of the -estimate. Finally we create a named list with the return value before we free -temporary memory allocation (a step that has to be done because the -underlying objects are really \proglang{C} objects conforming to the -\pkg{GSL} interface and hence without the automatic memory management we -could have with \proglang{C++} vector or matrix structures as used through -the \pkg{Rcpp} package) and return the result to \proglang{R}. - -We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements -a matching \texttt{fastLm} function using the Armadillo library by -\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to -\proglang{C++} features. - -\section{Vectors} - -This section details the different vector represenations, starting with their -definition inside the \pkg{GSL}. We then discuss our layering before showing -how the two types map. A discussion of read-only `vector view' classes -concludes the section. - -\subsection{\pkg{GSL} Vectors} - -\pkg{GSL} defines various vector types to manipulate one-dimensionnal -data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| -structs are defined as: - -<< 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; -@ - -A typical use of the \verb|gsl_vector| struct is given below: - -<>= -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); -} - -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 -@ - -\subsection{RcppGSL::vector} - -\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector} to manipulate -\verb|gsl_vector| pointers taking advantage of C++ templates. Using this -template type, the previous example now becomes: - -<>= -int i; -RcppGSL::vector v(3); // allocate a gsl_vector of size 3 - -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] ; -} - -v.free() ; // free the memory -@ - -The class \texttt{RcppGSL::vector} 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. - -Beyond the convenience of a nicer syntax for allocation and release of -memory, the \texttt{RcppGSL::vector} template faciliates interchange of -\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The -following example defines a \texttt{.Call} compatible function called -\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through -the \texttt{RcppGSL::vector} template specialization: - -<>= -// [[Rcpp::export]] -int sum_gsl_vector_int( RcppGSL::vector vec){ - int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; - vec.free() ; // we need to free vec after use - return res ; -} -@ - -The function can then simply be called from \proglang{R} : - -<>= - -fx <- cxxfunction( - list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), - c( sum_gsl_vector_int = ' - RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; - int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; - vec.free() ; // we need to free vec after use - return wrap( res ) ; -' ), plugin = "RcppGSL" ) -<>= -.Call( "sum_gsl_vector_int", 1:10 ) -@ - -A second example shows a simple function that grabs elements of an -R list as \verb|gsl_vector| objects using implicit conversion mechanisms -of \pkg{Rcpp} - -<< example2,lang=cpp,size=small>>= -// [[Rcpp::export]] -double gsl_vector_sum_2( Rcpp::List data ){ - // grab "x" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector x = data["x"] ; - - // grab "y" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector 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 ; -} -@ - -called from \proglang{R} : - -<>= -fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ), -c( gsl_vector_sum_2 = ' - List data(data_) ; - - // grab "x" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector x = data["x"] ; - - // grab "y" as a gsl_vector through the RcppGSL::vector class - RcppGSL::vector 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 wrap(res); -' ), plugin = "RcppGSL" ) -@ -<>= -data <- list( x = seq(0,1,length=10), y = 1:10 ) -.Call( "gsl_vector_sum_2", data ) -@ - -\subsection{Mapping} - -Table~\ref{tab:mappingVectors} shows the mapping between types defined by the -\pkg{GSL} and their corresponding types in the \pkg{RcppGSL} package. - -\begin{table}[htb] - \centering - \begin{small} - \begin{tabular}{ll} - \toprule - gsl vector & RcppGSL \\ - \midrule - \texttt{gsl\_vector} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_int} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_float} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_long} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_char} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex\_float} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_complex\_long\_double} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_long\_double} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_short} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_uchar} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_uint} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_ushort} & \texttt{RcppGSL::vector} \\ - \texttt{gsl\_vector\_ulong} & \texttt{RcppGSL::vector} \\ - \bottomrule - \end{tabular} - \end{small} - \caption{Correspondance between \pkg{GSL} vector types and templates defined in \pkg{RcppGSL}.} - \label{tab:mappingVectors} -\end{table} - -\subsection{ Vector Views} - -Several \pkg{GSL} algorithms return \pkg{GSL} vector views as their result -type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view} -to handle vector views using \proglang{C++} syntax. - -<>= -// [[Rcpp::export]] -Rcpp::List test_gsl_vector_view(){ - int n = 10 ; - RcppGSL::vector v(n) ; - for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); - RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); - - List res = List::create( - _["even"] = v_even, - _["odd" ] = v_odd - ) ; - v.free() ; // we only need to free v, the views do not own data - return res ; -} -@ - -As with vectors, \proglang{C++} objects of type -\texttt{RcppGSL::vector\_view} can be converted implicitly to their -associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays -the pairwise correspondance so that the \proglang{C++} objects can be passed -to compatible \pkg{GSL} algorithms. - -\begin{table}[htb] - \centering - \begin{small} - \begin{tabular}{ll} - \toprule - gsl vector views & RcppGSL \\ - \midrule - \texttt{gsl\_vector\_view} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_int} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_float} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_long} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_char} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex\_float} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_complex\_long\_double} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_long\_double} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_short} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_uchar} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_uint} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_ushort} & \texttt{RcppGSL::vector\_view} \\ - \texttt{gsl\_vector\_view\_ulong} & \texttt{RcppGSL::vector\_view} \\ - \bottomrule - \end{tabular} - \end{small} - \caption{Correspondance between \pkg{GSL} vector view types and templates defined - in \pkg{RcppGSL}.} - \label{tab:mappingVectorViews} -\end{table} - -The vector view class also contains a conversion operator to automatically -transform the data of the view object to a \pkg{GSL} vector object. This -enables use of vector views where \pkg{GSL} would expect a vector. - - -\section{Matrices} - -The \pkg{GSL} also defines a set of matrix data types : \texttt{gsl\_matrix}, -\texttt{gsl\_matrix\_int} etc ... for which \pkg{RcppGSL} defines a corresponding -convenience \proglang{C++} wrapper generated by the \texttt{RcppGSL::matrix} -template. - -\subsection{Creating matrices} - -The \texttt{RcppGSL::matrix} template exposes three constructors. - -<>= -// convert an R matrix to a GSL matrix -matrix( SEXP x) throw(::Rcpp::not_compatible) - -// encapsulate a GSL matrix pointer -matrix( gsl_matrix* x) - -// create a new matrix with the given number of rows and columns -matrix( int nrow, int ncol) -@ - -\subsection{Implicit conversion} - -\texttt{RcppGSL::matrix} defines implicit conversion to a pointer to -the associated \pkg{GSL} matrix type, as well as dereferencing operators, making -the class \texttt{RcppGSL::matrix} look and feel like a pointer to a GSL -matrix type. - -<>= -gsltype* data ; -operator gsltype*(){ return data ; } -gsltype* operator->() const { return data; } -gsltype& operator*() const { return *data; } -@ - -\subsection{Indexing} - -Indexing of \pkg{GSL} matrices is usually the task of the functions -\texttt{gsl\_matrix\_get}, \texttt{gsl\_matrix\_int\_get}, ... and -\texttt{gsl\_matrix\_set}, \texttt{gsl\_matrix\_int\_set}, ... - -\pkg{RcppGSL} takes advantage of both operator overloading and templates -to make indexing a \pkg{GSL} matrix much more convenient. - -<>= -RcppGSL::matrix mat(10,10); // create a matrix of size 10x10 - -for( int i=0; i<10: i++) { // fill the diagonal - mat(i,i) = i ; -} -@ - -\subsection{Methods} - -The \texttt{RcppGSL::matrix} type also defines the following member functions: -\begin{quote} - \begin{itemize} - \item[\texttt{nrow}] extracts the number of rows - \item[\texttt{ncol}] extract the number of columns - \item[\texttt{size}] extracts the number of elements - \item[\texttt{free}] releases the memory - \end{itemize} -\end{quote} - -\subsection{Matrix views} - -Similar to the vector views discussed above, the \pkg{RcppGSL} also provides -an implicit conversion operator which returns the underlying matrix stored in -the matrix view class. - -\section{Using \pkg{RcppGSL} in your package} - -The \pkg{RcppGSL} package contains a complete example providing a single -function \texttt{colNorm} which computes a norm for each column of a -supplied matrix. This example adapts a matrix example from the GSL manual that has -been chose merely as a means to showing how to set up a package to use -\pkg{RcppGSL}. - -Needless to say, we could compute such a matrix norm easily in \proglang{R} -using existing facilities. One such possibility is a simple -\verb|apply(M, 2, function(x) sqrt(sum(x^2)))| as shown on the corresponding -help page in the example package inside \pkg{RcppGSL}. One point in favour of -using the \pkg{GSL} code is that it employs a BLAS function so on -sufficiently large matrices, and with suitable BLAS libraries installed, this -variant could be faster due to the optimised code in high-performance BLAS -libraries and/or the inherent parallelism a multi-core BLAS variant which -compute compute the vector norm in parallel. On all `reasonable' matrix -sizes, however, the performance difference should be neglible. - -\subsection{The \texttt{configure} script} - -\subsubsection{Using autoconf} - -Using \pkg{RcppGSL} means employing both the \pkg{GSL} and \proglang{R}. We -may need to find the location of the \pkg{GSL} headers and library, and this -done easily from a \texttt{configure} source script which \texttt{autoconf} -generates from a \texttt{configure.in} source file such as the following: - -<>= -AC_INIT([RcppGSLExample], 0.1.0) - -## Use gsl-config to find arguments for compiler and linker flags -## -## Check for non-standard programs: gsl-config(1) -AC_PATH_PROG([GSL_CONFIG], [gsl-config]) -## If gsl-config was found, let's use it -if test "${GSL_CONFIG}" != ""; then - # Use gsl-config for header and linker arguments (without BLAS which we get from R) - GSL_CFLAGS=`${GSL_CONFIG} --cflags` - GSL_LIBS=`${GSL_CONFIG} --libs-without-cblas` -else - AC_MSG_ERROR([gsl-config not found, is GSL installed?]) -fi - -## Use Rscript to query Rcpp for compiler and linker flags -## link flag providing libary as well as path to library, and optionally rpath -RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'` - -# Now substitute these variables in src/Makevars.in to create src/Makevars -AC_SUBST(GSL_CFLAGS) -AC_SUBST(GSL_LIBS) -AC_SUBST(RCPP_LDFLAGS) - -AC_OUTPUT(src/Makevars) -@ - -Such a source \texttt{configure.in} gets converted into a script -\texttt{configure} by invoking the \texttt{autoconf} program. - -\subsubsection{Using functions provided by RcppGSL} - -\pkg{RcppGSL} provides R functions that allows one to retrieve the same -information. Therefore the configure script can also be written as: - -<>= -#!/bin/sh - -GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` -GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` -RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"` - -sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ - -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ - -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ - src/Makevars.in > src/Makevars -@ - -Similarly, the configure.win for windows can be written as: - -<>= -GSL_CFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::CFlags()"` -GSL_LIBS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::LdFlags()"` -RCPP_LDFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()"` - -sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ - -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ - -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ - src/Makevars.in > src/Makevars.win -@ - -\subsection{The \texttt{src} directory} - -The \proglang{C++} source file takes the matrix supplied from \proglang{R} -and applies the \pkg{GSL} function to each column. - -<>= -#include -#include -#include - -extern "C" SEXP colNorm(SEXP sM) { - - try { - - RcppGSL::matrix M = sM; // create gsl data structures from SEXP - int k = M.ncol(); - Rcpp::NumericVector n(k); // to store results - - for (int j = 0; j < k; j++) { - RcppGSL::vector_view colview = gsl_matrix_column (M, j); - n[j] = gsl_blas_dnrm2(colview); - } - M.free() ; - return n; // return vector - - } catch( std::exception &ex ) { - forward_exception_to_r( ex ); - - } catch(...) { - ::Rf_error( "c++ exception (unknown reason)" ); - } - return R_NilValue; // -Wall -} -@ - -The \proglang{Makevars.in} file governs the compilation and uses the values -supplied by \texttt{configure} during build-time: - -<>= - -# set by configure -GSL_CFLAGS = @GSL_CFLAGS@ -GSL_LIBS = @GSL_LIBS@ -RCPP_LDFLAGS = @RCPP_LDFLAGS@ - -# combine with standard arguments for R -PKG_CPPFLAGS = $(GSL_CFLAGS) -PKG_LIBS = $(GSL_LIBS) $(RCPP_LDFLAGS) -@ - -The variables surrounded by \@ will be filled by \texttt{configure} during -package build-time. - -\subsection{The \texttt{R} directory} - -The \proglang{R} source is very simply: a single matrix is passed to \proglang{C++}: - -<>= -colNorm <- function(M) { - stopifnot(is.matrix(M)) - res <- .Call("colNorm", M, package="RcppGSLExample") -} -@ - -\section{Using \pkg{RcppGSL} with \pkg{inline}} - -The \pkg{inline} package \citep{CRAN:inline} is very helpful for prototyping code in -\proglang{C}, \proglang{C++} or \proglang{Fortran} as it takes care of code -compilation, linking and dynamic loading directly from \proglang{R}. It is -being used extensively by \pkg{Rcpp}, for example in the numerous unit tests. - -The example below shows how \pkg{inline} can be deployed with -\pkg{RcppGSL}. We implement the same column norm example, but this time as an -\proglang{R} script which is compiled, linked and loaded on-the-fly. Compared -to standard use of \pkg{inline}, we have to make sure to add a short section -declaring which header files from \pkg{GSL} we need to use; the \pkg{RcppGSL} -then communicates with \pkg{inline} to tell it about the location and names -of libraries used to build code against \pkg{GSL}. - -<<>>= -require(inline) - -inctxt=' - #include - #include -' - -bodytxt=' - RcppGSL::matrix M = sM; // create gsl data structures from SEXP - int k = M.ncol(); - Rcpp::NumericVector n(k); // to store results - - for (int j = 0; j < k; j++) { - RcppGSL::vector_view colview = gsl_matrix_column (M, j); - n[j] = gsl_blas_dnrm2(colview); - } - M.free() ; - return n; // return vector -' - -foo <- cxxfunction( - signature(sM="numeric"), - body=bodytxt, inc=inctxt, plugin="RcppGSL") - -## see Section 8.4.13 of the GSL manual: create M as a sum of two outer products -M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*") -foo(M) -@ - -The \texttt{RcppGSL} inline plugin supports creation of a package skeleton -based on the inline function. - -<>= -package.skeleton( "mypackage", foo ) -@ - -\section{Summary} - -The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive -collection of rigorously developed and tested functions for applied -scientific computing under a common Open Source license. This has lead to -widespread deployment of \pkg{GSL} among a number of disciplines. - -Using the automatic wrapping and converters offered by the \pkg{RcppGSL} -package presented here, \proglang{R} users and programmers can now deploy -algorithmns provided by the \pkg{GSL} with greater ease. - -\bibliographystyle{plainnat} -\bibliography{\Sexpr{Rcpp:::bib()}} - \end{document} Copied: pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw (from rev 4344, pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw) =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw (rev 0) +++ pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-20 01:17:33 UTC (rev 4356) @@ -0,0 +1,36 @@ +\documentclass[10pt]{article} +%\VignetteIndexEntry{RcppGSL-unitTests} +%\VignetteKeywords{R,GSL,Rcpp,unit tests} +%\VignettePackage{RcppGSL} + +\usepackage{vmargin} +\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} + +\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave +\RequirePackage[T1]{fontenc} + +<>= +require( RcppGSL ) +prettyVersion <- packageDescription("RcppGSL")$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +@ + +\usepackage[colorlinks]{hyperref} +\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} +\title{\texttt{RcppGSL}: Unit testing results} +\date{\texttt{RcppGSL} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} +\begin{document} +\maketitle + +\begin{verbatim} +<>= +results <- "unitTests-results/RcppGSL-unitTests.txt" +if( file.exists( results ) ){ + writeLines( readLines( results ) ) +} else{ + writeLines( "unit test results not available" ) +} +@ +\end{verbatim} + +\end{document} From noreply at r-forge.r-project.org Thu Jun 20 03:19:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 03:19:30 +0200 (CEST) Subject: [Rcpp-commits] r4357 - in pkg/RcppGSL/inst/examples: . bSpline Message-ID: <20130620011931.3DC13185900@r-forge.r-project.org> Author: edd Date: 2013-06-20 03:19:29 +0200 (Thu, 20 Jun 2013) New Revision: 4357 Added: pkg/RcppGSL/inst/examples/bSpline/ pkg/RcppGSL/inst/examples/bSpline/bSpline.R pkg/RcppGSL/inst/examples/bSpline/bSpline.cpp pkg/RcppGSL/inst/examples/bSpline/plotHelper.R Log: actually adding + committing bSpline which should have gone in in rev4198 Added: pkg/RcppGSL/inst/examples/bSpline/bSpline.R =================================================================== --- pkg/RcppGSL/inst/examples/bSpline/bSpline.R (rev 0) +++ pkg/RcppGSL/inst/examples/bSpline/bSpline.R 2013-06-20 01:19:29 UTC (rev 4357) @@ -0,0 +1,27 @@ + +## This example illustrated use of RcppGSL using the 'Rcpp attributes' feature +## +## The example comes from Section 39.7 of the GSL Reference manual, and constructs +## a data set from the curve y(x) = \cos(x) \exp(-x/10) on the interval [0, 15] with +## added Gaussian noise --- which is then fit via linear least squares using a cubic +## B-spline basis functions with uniform breakpoints. +## +## Obviously all this could be done in R too as R can both generate data, and fit +## models including (B-)splines. But the point to be made here is that we can very +## easily translate a given GSL program (thanks to RcppGSL), and get it into R with +## ease thanks to Rcpp and Rcpp attributes. + +require(Rcpp) # load Rcpp + +sourceCpp("bSpline.cpp") # compile two functions + +dat <- genData() # generate the data +fit <- fitData(dat) # fit the model, returns matrix and gof measures + +X <- fit[["X"]] # extract vectors +Y <- fit[["Y"]] + +op <- par(mar=c(3,3,1,1)) +plot(dat[,"x"], dat[,"y"], pch=19, col="#00000044") +lines(X, Y, col="orange", lwd=2) +par(op) Added: pkg/RcppGSL/inst/examples/bSpline/bSpline.cpp =================================================================== --- pkg/RcppGSL/inst/examples/bSpline/bSpline.cpp (rev 0) +++ pkg/RcppGSL/inst/examples/bSpline/bSpline.cpp 2013-06-20 01:19:29 UTC (rev 4357) @@ -0,0 +1,137 @@ +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- + +// [[Rcpp::depends(RcppGSL)]] +#include + +#include +#include +#include +#include +#include + +const int N = 200; // number of data points to fit +const int NCOEFFS = 12; // number of fit coefficients */ +const int NBREAK = (NCOEFFS - 2); // nbreak = ncoeffs + 2 - k = ncoeffs - 2 since k = 4 */ + +// [[Rcpp::export]] +Rcpp::List genData() { + + const size_t n = N; + size_t i; + double dy; + gsl_rng *r; + RcppGSL::vector w(n), x(n), y(n); + + gsl_rng_env_setup(); + r = gsl_rng_alloc(gsl_rng_default); + + //printf("#m=0,S=0\n"); + /* this is the data to be fitted */ + + for (i = 0; i < n; ++i) { + double sigma; + double xi = (15.0 / (N - 1)) * i; + double yi = cos(xi) * exp(-0.1 * xi); + + sigma = 0.1 * yi; + dy = gsl_ran_gaussian(r, sigma); + yi += dy; + + gsl_vector_set(x, i, xi); + gsl_vector_set(y, i, yi); + gsl_vector_set(w, i, 1.0 / (sigma * sigma)); + + //printf("%f %f\n", xi, yi); + } + + Rcpp::DataFrame res = Rcpp::DataFrame::create(Rcpp::Named("x") = x, + Rcpp::Named("y") = y, + Rcpp::Named("w") = w); + + x.free(); + y.free(); + w.free(); + gsl_rng_free(r); + + return(res); +} + + + +// [[Rcpp::export]] +Rcpp::List fitData(Rcpp::DataFrame ds) { + + const size_t ncoeffs = NCOEFFS; + const size_t nbreak = NBREAK; + + const size_t n = N; + size_t i, j; + + Rcpp::DataFrame D(ds); // construct the data.frame object + RcppGSL::vector y = D["y"]; // access columns by name, + RcppGSL::vector x = D["x"]; // assigning to GSL vectors + RcppGSL::vector w = D["w"]; + + gsl_bspline_workspace *bw; + gsl_vector *B; + gsl_vector *c; + gsl_matrix *X, *cov; + gsl_multifit_linear_workspace *mw; + double chisq, Rsq, dof, tss; + + bw = gsl_bspline_alloc(4, nbreak); // allocate a cubic bspline workspace (k = 4) + B = gsl_vector_alloc(ncoeffs); + + X = gsl_matrix_alloc(n, ncoeffs); + c = gsl_vector_alloc(ncoeffs); + cov = gsl_matrix_alloc(ncoeffs, ncoeffs); + mw = gsl_multifit_linear_alloc(n, ncoeffs); + + gsl_bspline_knots_uniform(0.0, 15.0, bw); // use uniform breakpoints on [0, 15] + + for (i = 0; i < n; ++i) { // construct the fit matrix X + double xi = gsl_vector_get(x, i); + + gsl_bspline_eval(xi, B, bw); // compute B_j(xi) for all j + + for (j = 0; j < ncoeffs; ++j) { // fill in row i of X + double Bj = gsl_vector_get(B, j); + gsl_matrix_set(X, i, j, Bj); + } + } + + gsl_multifit_wlinear(X, w, y, c, cov, &chisq, mw); // do the fit + + dof = n - ncoeffs; + tss = gsl_stats_wtss(w->data, 1, y->data, 1, y->size); + Rsq = 1.0 - chisq / tss; + + Rcpp::NumericVector FX(151), FY(151); // output the smoothed curve + double xi, yi, yerr; + for (xi = 0.0, i=0; xi < 15.0; xi += 0.1, i++) { + gsl_bspline_eval(xi, B, bw); + gsl_multifit_linear_est(B, c, cov, &yi, &yerr); + FX[i] = xi; + FY[i] = yi; + } + + Rcpp::List res = + Rcpp::List::create(Rcpp::Named("X")=FX, + Rcpp::Named("Y")=FY, + Rcpp::Named("chisqdof")=Rcpp::wrap(chisq/dof), + Rcpp::Named("rsq")=Rcpp::wrap(Rsq)); + + gsl_bspline_free(bw); + gsl_vector_free(B); + gsl_matrix_free(X); + gsl_vector_free(c); + gsl_matrix_free(cov); + gsl_multifit_linear_free(mw); + + y.free(); + x.free(); + w.free(); + + return(res); +} + Added: pkg/RcppGSL/inst/examples/bSpline/plotHelper.R =================================================================== --- pkg/RcppGSL/inst/examples/bSpline/plotHelper.R (rev 0) +++ pkg/RcppGSL/inst/examples/bSpline/plotHelper.R 2013-06-20 01:19:29 UTC (rev 4357) @@ -0,0 +1,21 @@ + +library(Rcpp) +sourceCpp("bSpline.cpp") # compile two functions +dat <- genData() # generate the data +fit <- fitData(dat) # fit the model, returns matrix and gof measures + +op <- par(mar=c(3,3,1,1)) +plot(dat[,"x"], dat[,"y"], pch=19, col="#00000044") +lines(fit[[1]], fit[[2]], col="orange", lwd=2) +par(op) + +#spl <- read.table("/tmp/spline.txt") +#splA <- spl[1:200,] +#splB <- spl[-c(1:200),] +#pdf("/tmp/plotHelper.pdf") +#op <- par(mar=c(3,3,1,1)) +#plot(splA, pch=19, col="#00000044") +#lines(splB, col="orange") +#par(op) +#dev.off() + From noreply at r-forge.r-project.org Thu Jun 20 04:24:34 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Jun 2013 04:24:34 +0200 (CEST) Subject: [Rcpp-commits] r4358 - in pkg/RcppGSL: . inst vignettes/RcppGSL Message-ID: <20130620022434.5C1D41852C6@r-forge.r-project.org> Author: edd Date: 2013-06-20 04:24:33 +0200 (Thu, 20 Jun 2013) New Revision: 4358 Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/cleanup pkg/RcppGSL/inst/NEWS.Rd pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw Log: reverting vignette back to highlighting on demand Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-20 01:19:29 UTC (rev 4357) +++ pkg/RcppGSL/ChangeLog 2013-06-20 02:24:33 UTC (rev 4358) @@ -1,3 +1,12 @@ +2013-06-19 Dirk Eddelbuettel + + * vignettes/RcppGSL/RcppGSL-intro.Rnw: Some fixes + +2013-06-19 Romain Francois + + * vignettes/RcppGSL/RcppGSL-intro.Rnw: Converted back to use with + package highlight (>= 0.4.2) + 2012-11-11 Dirk Eddelbuettel * inst/examples/bSpline/bSpline.cpp: New example for B-spline fit Modified: pkg/RcppGSL/cleanup =================================================================== --- pkg/RcppGSL/cleanup 2013-06-20 01:19:29 UTC (rev 4357) +++ pkg/RcppGSL/cleanup 2013-06-20 02:24:33 UTC (rev 4358) @@ -14,5 +14,5 @@ (cd vignettes && \ make clean && \ - rm -rf auto unitTests-results/ ) + rm -rf auto unitTests-results/* ) Modified: pkg/RcppGSL/inst/NEWS.Rd =================================================================== --- pkg/RcppGSL/inst/NEWS.Rd 2013-06-20 01:19:29 UTC (rev 4357) +++ pkg/RcppGSL/inst/NEWS.Rd 2013-06-20 02:24:33 UTC (rev 4358) @@ -6,9 +6,9 @@ \itemize{ \item Added new example based on B-splines example in GSL manual illustrating simple GSL use via Rcpp attributes - \item vignette production has been simplified, relying on version 0.4.2 - of highlight which acts now as a vignette engine for this package - vignette. + \item Vignette compilation has been reverted to using \pkg{highlight} + since version 0.4.2 or greater can be used as a vignette engine + (with R 3.0.* or later). } } Modified: pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw 2013-06-20 01:19:29 UTC (rev 4357) +++ pkg/RcppGSL/vignettes/RcppGSL/RcppGSL-intro.Rnw 2013-06-20 02:24:33 UTC (rev 4358) @@ -2,6 +2,7 @@ %\VignetteIndexEntry{RcppGSL} %\VignetteKeywords{R,GSL,Rcpp,data transfer} %\VignettePackage{RcppGSL} +%\VignetteEngine{highlight::highlight} \usepackage{url,color} \usepackage[authoryear,round,longnamesfirst]{natbib} @@ -137,111 +138,56 @@ the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice example for \pkg{GSL} integration with \proglang{R}. -% < < fastLm,lang=cpp,size=small > > = -% #include -% #include -% #include +<>= +#include +#include +#include -% extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { +extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { -% try { -% RcppGSL::vector y = ys; // create gsl data structures from SEXP -% RcppGSL::matrix X = Xs; + try { + RcppGSL::vector y = ys; // create gsl data structures from SEXP + RcppGSL::matrix X = Xs; -% int n = X.nrow(), k = X.ncol(); -% double chisq; + int n = X.nrow(), k = X.ncol(); + double chisq; -% RcppGSL::vector coef(k); // to hold the coefficient vector -% RcppGSL::matrix cov(k,k); // and the covariance matrix + RcppGSL::vector coef(k); // to hold the coefficient vector + RcppGSL::matrix 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 @@ -278,134 +224,66 @@ data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| structs are defined as: -% < < 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; + 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: -% < > = -% int i; -% gsl_vector * v = gsl_vector_alloc (3); // allocate a gsl_vector of size 3 +<>= +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} to manipulate \verb|gsl_vector| pointers taking advantage of C++ templates. Using this template type, the previous example now becomes: -% < < vector_sum,lang=cpp,size=small > > = -% int i; -% RcppGSL::vector v(3); // allocate a gsl_vector of size 3 +<>= +int i; +RcppGSL::vector 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} is a smart pointer, that can be used anywhere where a raw pointer \verb|gsl_vector| can be used, such as the @@ -418,27 +296,14 @@ \verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through the \texttt{RcppGSL::vector} template specialization: -% < > = -% RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector vec){ -% int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; -% vec.free() ; // we need to free vec after use -% return res ; -% } -% @ +<>= +RCPP_FUNCTION_1( int, sum_gsl_vector_int, RcppGSL::vector 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} : @@ -460,53 +325,27 @@ R list as \verb|gsl_vector| objects using implicit conversion mechanisms of \pkg{Rcpp} -%< < 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 class -% RcppGSL::vector x = data["x"] ; +<>= +RCPP_FUNCTION_1( double, gsl_vector_sum_2, Rcpp::List data ){ + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; -% // grab "y" as a gsl_vector through the RcppGSL::vector class -% RcppGSL::vector 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 class + RcppGSL::vector 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} : @@ -577,50 +416,25 @@ 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 v(n) ; -% for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); -% RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); +<>= +extern "C" SEXP test_gsl_vector_view(){ + int n = 10 ; + RcppGSL::vector v(n) ; + for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); + RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); -% List res = List::create( -% _["even"] = v_even, -% _["odd" ] = v_odd -% ) ; -% v.free() ; // we only need to free v, the views do not own data -% return res ; -% } -% @ + List res = List::create( + _["even"] = v_even, + _["odd" ] = v_odd + ) ; + v.free() ; // we only need to free v, the views do not own data + return res ; +} +@ -\begin{small} -\begin{Hchunk} -\noindent -\ttfamily -\hlstd{}\hlkwc{extern\ }\hlstd{}\hlstr{"C"}\hlstd{\ SEXP\ }\hlkwd{test\textunderscore gsl\textunderscore vector\textunderscore view}\hlstd{}\hlsym{()\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwb{int\ }\hlstd{n\ }\hlsym{=\ }\hlstd{}\hlnum{10\ }\hlstd{}\hlsym{;}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{}\hlkwd{v}\hlstd{}\hlsym{(}\hlstd{n}\hlsym{)\ ;}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlsym{(\ }\hlstd{}\hlkwb{int\ }\hlstd{i}\hlsym{=}\hlstd{}\hlnum{0\ }\hlstd{}\hlsym{;\ }\hlstd{i}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{n}\hlsym{;\ }\hlstd{i}\hlsym{++)\usebox{\hlsmallboxopenbrace}}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ \ \ }\hlstd{v}\hlsym{{[}}\hlstd{i}\hlsym{{]}\ =\ }\hlstd{i\ }\hlsym{;}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{}\hlsym{\usebox{\hlsmallboxclosebrace}}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector\textunderscore view}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{v\textunderscore even\ }\hlsym{=\ }\hlstd{}\hlkwd{gsl\textunderscore vector\textunderscore subvector\textunderscore with\textunderscore stride}\hlstd{}\hlsym{(}\hlstd{v}\hlsym{,}\hlstd{}\hlnum{0}\hlstd{}\hlsym{,}\hlstd{}\hlnum{2}\hlstd{}\hlsym{,}\hlstd{n}\hlsym{/}\hlstd{}\hlnum{2}\hlstd{}\hlsym{);}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{RcppGSL}\hlsym{::}\hlstd{vector\textunderscore view}\hlsym{\usebox{\hlsmallboxlessthan}}\hlstd{}\hlkwb{double}\hlstd{}\hlsym{\usebox{\hlsmallboxgreaterthan}\ }\hlstd{v\textunderscore odd}\hlstd{\ \ }\hlstd{}\hlsym{=\ }\hlstd{}\hlkwd{gsl\textunderscore vector\textunderscore subvector\textunderscore with\textunderscore stride}\hlstd{}\hlsym{(}\hlstd{v}\hlsym{,}\hlstd{}\hlnum{1}\hlstd{}\hlsym{,}\hlstd{}\hlnum{2}\hlstd{}\hlsym{,}\hlstd{n}\hlsym{/}\hlstd{}\hlnum{2}\hlstd{}\hlsym{);}\hspace*{\fill}\\ -\hlstd{\hspace*{\fill}\\ -}\hlstd{\ \ }\hlstd{List\ res\ }\hlsym{=\ }\hlstd{List}\hlsym{::}\hlstd{}\hlkwd{create}\hlstd{}\hlsym{(}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ \ \ }\hlstd{\textunderscore }\hlsym{{[}}\hlstd{}\hlstr{"even"}\hlstd{}\hlsym{{]}\ =\ }\hlstd{v\textunderscore even}\hlsym{,}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ \ \ }\hlstd{\textunderscore }\hlsym{{[}}\hlstd{}\hlstr{"odd"}\hlstd{\ }\hlsym{{]}\ =\ }\hlstd{v\textunderscore odd\hspace*{\fill}\\ -}\hlstd{\ \ \ \ }\hlstd{}\hlsym{)\ ;}\hspace*{\fill}\\ -\hlstd{}\hlstd{\ \ }\hlstd{v}\hlsym{.}\hlstd{}\hlkwd{free}\hlstd{}\hlsym{()\ ;}\hlstd{\ \ \ }\hlsym{}\hlstd{}\hlslc{//\ we\ only\ need\ to\ free\ v,\ the\ views\ do\ not\ own\ data}\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} - As with vectors, \proglang{C++} objects of type \texttt{RcppGSL::vector\_view} can be converted implicitly to their associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays @@ -672,33 +486,17 @@ The \texttt{RcppGSL::matrix} template exposes three constructors. -% < < lang=cpp,size=small > > = -% // convert an R matrix to a GSL matrix -% matrix( SEXP x) throw(::Rcpp::not_compatible) +<>= +// convert an R matrix to a GSL matrix +matrix( SEXP x) throw(::Rcpp::not_compatible) -% // encapsulate a GSL matrix pointer -% matrix( gsl_matrix* x) +// encapsulate a GSL matrix pointer +matrix( gsl_matrix* x) -% // create a new matrix with the given number of rows and columns -% matrix( int nrow, int ncol) -% @ +// create a new matrix with the given number of rows and columns +matrix( int nrow, int ncol) +@ -\begin{small} -\begin{Hchunk} -\noindent -\ttfamily [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4358 From noreply at r-forge.r-project.org Fri Jun 21 13:41:10 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 21 Jun 2013 13:41:10 +0200 (CEST) Subject: [Rcpp-commits] r4359 - in pkg/RcppGSL: . inst vignettes Message-ID: <20130621114110.A70D31856E5@r-forge.r-project.org> Author: edd Date: 2013-06-21 13:41:09 +0200 (Fri, 21 Jun 2013) New Revision: 4359 Added: pkg/RcppGSL/vignettes/buildVignette.R Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/cleanup pkg/RcppGSL/inst/NEWS.Rd pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw Log: committing work-in-progress for vignettes/ reorgination this works with the new scheme but has not yet removed Makefile or the old directories Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-20 02:24:33 UTC (rev 4358) +++ pkg/RcppGSL/ChangeLog 2013-06-21 11:41:09 UTC (rev 4359) @@ -1,3 +1,10 @@ +2013-06-21 Dirk Eddelbuettel + + * vignettes/buildVignette.R: Added simple helper script to build + the vignette(s) on the command-line (which requires highlight) + + * cleanup: Take some tasks that the vignette/Makefile had + 2013-06-19 Dirk Eddelbuettel * vignettes/RcppGSL/RcppGSL-intro.Rnw: Some fixes Modified: pkg/RcppGSL/cleanup =================================================================== --- pkg/RcppGSL/cleanup 2013-06-20 02:24:33 UTC (rev 4358) +++ pkg/RcppGSL/cleanup 2013-06-21 11:41:09 UTC (rev 4359) @@ -13,6 +13,6 @@ rm -rf autom4te.cache) (cd vignettes && \ - make clean && \ - rm -rf auto unitTests-results/* ) + rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl && \ + rm -rf auto unitTests-results/ ) Modified: pkg/RcppGSL/inst/NEWS.Rd =================================================================== --- pkg/RcppGSL/inst/NEWS.Rd 2013-06-20 02:24:33 UTC (rev 4358) +++ pkg/RcppGSL/inst/NEWS.Rd 2013-06-21 11:41:09 UTC (rev 4359) @@ -9,6 +9,10 @@ \item Vignette compilation has been reverted to using \pkg{highlight} since version 0.4.2 or greater can be used as a vignette engine (with R 3.0.* or later). + \item Vignette compilation is now being done by \code{R CMD build} + as R 3.0.0 supports different vignette engines, so the vignette + build process has been simplified. A convenience helper script has + also been added for command-line builds. } } Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-20 02:24:33 UTC (rev 4358) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-21 11:41:09 UTC (rev 4359) @@ -1,11 +1,767 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RcppGSL} +%\VignetteKeywords{R,GSL,Rcpp,data transfer} +%\VignettePackage{RcppGSL} +%\VignetteEngine{highlight::highlight} -\usepackage{url} +\usepackage{url,color} +\usepackage[authoryear,round,longnamesfirst]{natbib} \usepackage[colorlinks]{hyperref} -\setlength{\oddsidemargin}{0pt} -\setlength{\textwidth}{17cm} % uh-oh, I use letter :) +\definecolor{link}{rgb}{0,0,0.3} %% next few lines courtesy of RJournal.sty +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} +\usepackage{vmargin} +\setmargrb{0.75in}{0.75in}{0.75in}{0.75in} +\usepackage{booktabs} % fancier \hrule +\newcommand{\proglang}[1]{\textsf{#1}} +\newcommand{\pkg}[1]{{\fontseries{b}\selectfont #1}} + +\RequirePackage{ae,mathpple} % ae as a default font pkg works with Sweave +\RequirePackage[T1]{fontenc} + +<>= +require(inline) +library(RcppGSL) +options("width"=65) +rcppgsl.version <- packageDescription( "RcppGSL" )$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +@ +% closing $ needed here + +\author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} +\title{\pkg{RcppGSL}: Easier \pkg{GSL} use from \proglang{R} via \pkg{Rcpp}} +\date{Version \Sexpr{rcppgsl.version} as of \Sexpr{prettyDate}} + \begin{document} +\maketitle + +\abstract{ + \shortcites{GSL} %% so that we get Galassi et al instead of all names + \noindent + The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical + routines for scientific computing \citep{GSL}. It is particularly useful for + \proglang{C} and \proglang{C++} programs as it provides a standard + \proglang{C} interface to a wide range of mathematical routines such as + special functions, permutations, combinations, fast fourier transforms, + eigensystems, random numbers, quadrature, random distributions, + quasi-random sequences, Monte Carlo integration, N-tuples, differential + equations, simulated annealing, numerical differentiation, interpolation, + series acceleration, Chebyshev approximations, root-finding, discrete + Hankel transforms physical constants, basis splines and wavelets. There + are over 1000 functions in total with an extensive test suite. + + The \pkg{RcppGSL} package provides an easy-to-use interface between + \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} + \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces + between \proglang{R} and C++. +} + +\section{Introduction} + +The GNU Scientific Library, or \pkg{GSL}, is a collection of numerical +routines for scientific computing \citep{GSL}. It is a rigourously developed +and tested library providing support for a wide range of scientific or +numerical tasks. Among the topics covered in the GSL are +%% from the GSL manual +complex numbers, roots of polynomials, +special functions, vector and matrix data structures, +permutations, combinations, sorting, BLAS support, +linear algebra, fast fourier transforms, eigensystems, +random numbers, quadrature, random distributions, quasi-random sequences, +Monte Carlo integration, N-tuples, +differential equations, simulated annealing, +numerical differentiation, interpolation, +series acceleration, Chebyshev approximations, +root-finding, discrete Hankel transforms +least-squares fitting, minimization, +physical constants, basis splines and wavelets. + +Support for \proglang{C} programming with the GSL is readily available: the GSL itself is written in \proglang{C} +and provides a \proglang{C}-language Application Programming Interface +(API). Access from \proglang{C++} is therefore possible, albeit not at the +abstraction level that can be offered by dedicated \proglang{C++} +implementations.\footnote{Several \proglang{C++} wrappers for the GSL have + been written over the years yet none reached a state of completion + comparable to the GSL itself. Three such wrapping library are + \url{http://cholm.home.cern.ch/cholm/misc/gslmm/}, + \url{http://gslwrap.sourceforge.net/} and + \url{http://code.google.com/p/gslcpp/}.} + +The GSL is somewhat unique among numerical libraries. Its combination of +broad coverage of scientific topics, serious implementation effort and the +use of a FLOSS license have lead to a fairly wide usage of the library. As a +concrete example, we can consider the the CRAN repository network for the +\proglang{R} language and environment \citep{R:Main}. CRAN contains over a +dozen packages interfacing the GSL: \pkg{copula}, \pkg{dynamo}, \pkg{gsl}, +\pkg{gstat}, \pkg{magnets}, \pkg{mvabund}, \pkg{QRMlib}, \pkg{RBrownie}, +\pkg{RDieHarder}, \pkg{RHmm}, \pkg{segclust}, \pkg{surveillance}, and +\pkg{topicmodels}. This is a clear indication that the GSL is popular among +programmers using either the \proglang{C} or \proglang{C++} language for +solving problems applied science. + +At the same time, the \pkg{Rcpp} package \citep{JSS:Rcpp,CRAN:Rcpp} offers a +higher-level abstraction between \proglang{R} and underlying \proglang{C++} +(or \proglang{C}) code. \pkg{Rcpp} permits \proglang{R} objects like +vectors, matrices, lists, functions, environments, $\ldots$, to be +manipulated directly at the \proglang{C++} level, alleviates the needs for +complicated and error-prone parameter passing and memory allocation. It also +permits compact vectorised expressions similar to what can be written in +\proglang{R} directly at the \proglang{C++} level. + +The \pkg{RcppGSL} package discussed here aims the help close the gap. It +tries to offer access to GSL functions, in particular via the vector and +matrix data structures used throughout the GSL, while staying closer to the +`whole object model' familar to the \proglang{R} programmer. + +The rest of paper is organised as follows. The next section shows a +motivating example of a fast linear model fit routine using \pkg{GSL} functions. +The following section discusses support for \pkg{GSL} vector types, which is +followed by a section on matrices. + +\section{Motivation: FastLm} + +Fitting linear models is a key building block of analysing data and +modeling. \proglang{R} has a very complete and feature-rich function in +\texttt{lm()} which can provide a model fit as we a number of diagnostic +measure, either directly or via the corresponding \texttt{summary()} method +for linear model fits. The \texttt{lm.fit()} function also provides a faster +alternative (which is however recommend only for for advanced users) which +provides estimates only and fewer statistics for inference. This sometimes +leads users request a routine which is both fast and featureful enough. The +\texttt{fastLm} routine shown here provides such an implementation. It uses +the \pkg{GSL} for the least-squares fitting functions and therefore provides a nice +example for \pkg{GSL} integration with \proglang{R}. + +<>= +#include +#include +#include + +extern "C" SEXP fastLm(SEXP ys, SEXP Xs) { + + try { + RcppGSL::vector y = ys; // create gsl data structures from SEXP + RcppGSL::matrix X = Xs; + + int n = X.nrow(), k = X.ncol(); + double chisq; + + RcppGSL::vector coef(k); // to hold the coefficient vector + RcppGSL::matrix 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); + + // 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); + + 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(); + + 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 +} +@ + +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 +as well as complex numbers). We the reserve another vector and matrix to +hold the resulting coefficient estimates as well as the estimate of the +covariance matrix. Next, we allocate workspace using a GSL routine, fit the +linear model and free the workspace. The next step involves extracting the +diagonal element from the covariance matrix. We then employ a so-called +iterator---a common \proglang{C++} idiom from the Standard Template Library +(STL)---to iterate over the vector of diagonal and transforming it by +applying the square root function to compute our standard error of the +estimate. Finally we create a named list with the return value before we free +temporary memory allocation (a step that has to be done because the +underlying objects are really \proglang{C} objects conforming to the +\pkg{GSL} interface and hence without the automatic memory management we +could have with \proglang{C++} vector or matrix structures as used through +the \pkg{Rcpp} package) and return the result to \proglang{R}. + +We should note that \pkg{RcppArmadillo} \citep{CRAN:RcppArmadillo} implements +a matching \texttt{fastLm} function using the Armadillo library by +\cite{Sanderson:2010:Armadillo}, and can do so with more compact code due to +\proglang{C++} features. + +\section{Vectors} + +This section details the different vector represenations, starting with their +definition inside the \pkg{GSL}. We then discuss our layering before showing +how the two types map. A discussion of read-only `vector view' classes +concludes the section. + +\subsection{\pkg{GSL} Vectors} + +\pkg{GSL} defines various vector types to manipulate one-dimensionnal +data, similar to \proglang{R} arrays. For example the \verb|gsl_vector| and \verb|gsl_vector_int| +structs are defined as: + +<>= +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; +@ + +A typical use of the \verb|gsl_vector| struct is given below: + +<>= +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); +} + +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 +@ + +\subsection{RcppGSL::vector} + +\pkg{RcppGSL} defines the template \texttt{RcppGSL::vector} to manipulate +\verb|gsl_vector| pointers taking advantage of C++ templates. Using this +template type, the previous example now becomes: + +<>= +int i; +RcppGSL::vector v(3); // allocate a gsl_vector of size 3 + +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] ; +} + +v.free() ; // free the memory +@ + +The class \texttt{RcppGSL::vector} 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. + +Beyond the convenience of a nicer syntax for allocation and release of +memory, the \texttt{RcppGSL::vector} template faciliates interchange of +\pkg{GSL} vectors with \pkg{Rcpp} objects, and hence \pkg{R} objects. The +following example defines a \texttt{.Call} compatible function called +\verb|sum_gsl_vector_int| that operates on a \verb|gsl_vector_int| through +the \texttt{RcppGSL::vector} template specialization: + +<>= +// [[Rcpp::export]] +int sum_gsl_vector_int( RcppGSL::vector vec){ + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return res ; +} +@ +p +The function can then simply be called from \proglang{R} : + +<>= +fx <- cxxfunction( + list( sum_gsl_vector_int = signature( vec_ = "integer" ) ), + c( sum_gsl_vector_int = ' + RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; + int res = std::accumulate( vec.begin(), vec.end(), 0 ) ; + vec.free() ; // we need to free vec after use + return wrap( res ) ; +' ), plugin = "RcppGSL" ) +<>= +.Call( "sum_gsl_vector_int", 1:10 ) +@ + +A second example shows a simple function that grabs elements of an +R list as \verb|gsl_vector| objects using implicit conversion mechanisms +of \pkg{Rcpp} + +<< example2,lang=cpp,size=small>>= +// [[Rcpp::export]] +double gsl_vector_sum_2( Rcpp::List data ){ + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 ; +} +@ + +called from \proglang{R} : + +<>= +fx2 <- cxxfunction( list( gsl_vector_sum_2 = signature( data_ = "list" ) ), +c( gsl_vector_sum_2 = ' + List data(data_) ; + + // grab "x" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector x = data["x"] ; + + // grab "y" as a gsl_vector through the RcppGSL::vector class + RcppGSL::vector 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 wrap(res); +' ), plugin = "RcppGSL" ) +@ +<>= +data <- list( x = seq(0,1,length=10), y = 1:10 ) +.Call( "gsl_vector_sum_2", data ) +@ + +\subsection{Mapping} + +Table~\ref{tab:mappingVectors} shows the mapping between types defined by the +\pkg{GSL} and their corresponding types in the \pkg{RcppGSL} package. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector & RcppGSL \\ + \midrule + \texttt{gsl\_vector} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_int} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_char} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_float} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_complex\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_long\_double} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_short} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uchar} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_uint} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ushort} & \texttt{RcppGSL::vector} \\ + \texttt{gsl\_vector\_ulong} & \texttt{RcppGSL::vector} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector types and templates defined in \pkg{RcppGSL}.} + \label{tab:mappingVectors} +\end{table} + +\subsection{ Vector Views} + +Several \pkg{GSL} algorithms return \pkg{GSL} vector views as their result +type. \pkg{RcppGSL} defines the template class \texttt{RcppGSL::vector\_view} +to handle vector views using \proglang{C++} syntax. + +<>= +// [[Rcpp::export]] +Rcpp::List test_gsl_vector_view(){ + int n = 10 ; + RcppGSL::vector v(n) ; + for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(v,0,2,n/2); + RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(v,1,2,n/2); + + List res = List::create( + _["even"] = v_even, + _["odd" ] = v_odd + ) ; + v.free() ; // we only need to free v, the views do not own data + return res ; +} +@ + +As with vectors, \proglang{C++} objects of type +\texttt{RcppGSL::vector\_view} can be converted implicitly to their +associated \pkg{GSL} view type. Table~\ref{tab:mappingVectorViews} displays +the pairwise correspondance so that the \proglang{C++} objects can be passed +to compatible \pkg{GSL} algorithms. + +\begin{table}[htb] + \centering + \begin{small} + \begin{tabular}{ll} + \toprule + gsl vector views & RcppGSL \\ + \midrule + \texttt{gsl\_vector\_view} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_int} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_char} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_float} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_complex\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_long\_double} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_short} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uchar} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_uint} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ushort} & \texttt{RcppGSL::vector\_view} \\ + \texttt{gsl\_vector\_view\_ulong} & \texttt{RcppGSL::vector\_view} \\ + \bottomrule + \end{tabular} + \end{small} + \caption{Correspondance between \pkg{GSL} vector view types and templates defined + in \pkg{RcppGSL}.} + \label{tab:mappingVectorViews} +\end{table} + +The vector view class also contains a conversion operator to automatically +transform the data of the view object to a \pkg{GSL} vector object. This +enables use of vector views where \pkg{GSL} would expect a vector. + + +\section{Matrices} + +The \pkg{GSL} also defines a set of matrix data types : \texttt{gsl\_matrix}, +\texttt{gsl\_matrix\_int} etc ... for which \pkg{RcppGSL} defines a corresponding +convenience \proglang{C++} wrapper generated by the \texttt{RcppGSL::matrix} +template. + +\subsection{Creating matrices} + +The \texttt{RcppGSL::matrix} template exposes three constructors. + +<>= +// convert an R matrix to a GSL matrix +matrix( SEXP x) throw(::Rcpp::not_compatible) + +// encapsulate a GSL matrix pointer +matrix( gsl_matrix* x) + +// create a new matrix with the given number of rows and columns +matrix( int nrow, int ncol) +@ + +\subsection{Implicit conversion} + +\texttt{RcppGSL::matrix} defines implicit conversion to a pointer to +the associated \pkg{GSL} matrix type, as well as dereferencing operators, making +the class \texttt{RcppGSL::matrix} look and feel like a pointer to a GSL +matrix type. + +<>= +gsltype* data ; +operator gsltype*(){ return data ; } +gsltype* operator->() const { return data; } +gsltype& operator*() const { return *data; } +@ + +\subsection{Indexing} + +Indexing of \pkg{GSL} matrices is usually the task of the functions +\texttt{gsl\_matrix\_get}, \texttt{gsl\_matrix\_int\_get}, ... and +\texttt{gsl\_matrix\_set}, \texttt{gsl\_matrix\_int\_set}, ... + +\pkg{RcppGSL} takes advantage of both operator overloading and templates +to make indexing a \pkg{GSL} matrix much more convenient. + +<>= +RcppGSL::matrix mat(10,10); // create a matrix of size 10x10 + +for( int i=0; i<10: i++) { // fill the diagonal + mat(i,i) = i ; +} +@ + +\subsection{Methods} + +The \texttt{RcppGSL::matrix} type also defines the following member functions: +\begin{quote} + \begin{itemize} + \item[\texttt{nrow}] extracts the number of rows + \item[\texttt{ncol}] extract the number of columns + \item[\texttt{size}] extracts the number of elements + \item[\texttt{free}] releases the memory + \end{itemize} +\end{quote} + +\subsection{Matrix views} + +Similar to the vector views discussed above, the \pkg{RcppGSL} also provides +an implicit conversion operator which returns the underlying matrix stored in +the matrix view class. + +\section{Using \pkg{RcppGSL} in your package} + +The \pkg{RcppGSL} package contains a complete example providing a single +function \texttt{colNorm} which computes a norm for each column of a +supplied matrix. This example adapts a matrix example from the GSL manual that has +been chose merely as a means to showing how to set up a package to use +\pkg{RcppGSL}. + +Needless to say, we could compute such a matrix norm easily in \proglang{R} +using existing facilities. One such possibility is a simple +\verb|apply(M, 2, function(x) sqrt(sum(x^2)))| as shown on the corresponding +help page in the example package inside \pkg{RcppGSL}. One point in favour of +using the \pkg{GSL} code is that it employs a BLAS function so on +sufficiently large matrices, and with suitable BLAS libraries installed, this +variant could be faster due to the optimised code in high-performance BLAS +libraries and/or the inherent parallelism a multi-core BLAS variant which +compute compute the vector norm in parallel. On all `reasonable' matrix +sizes, however, the performance difference should be neglible. + +\subsection{The \texttt{configure} script} + +\subsubsection{Using autoconf} + +Using \pkg{RcppGSL} means employing both the \pkg{GSL} and \proglang{R}. We +may need to find the location of the \pkg{GSL} headers and library, and this +done easily from a \texttt{configure} source script which \texttt{autoconf} +generates from a \texttt{configure.in} source file such as the following: + +<>= +AC_INIT([RcppGSLExample], 0.1.0) + +## Use gsl-config to find arguments for compiler and linker flags +## +## Check for non-standard programs: gsl-config(1) +AC_PATH_PROG([GSL_CONFIG], [gsl-config]) +## If gsl-config was found, let's use it +if test "${GSL_CONFIG}" != ""; then + # Use gsl-config for header and linker arguments (without BLAS which we get from R) + GSL_CFLAGS=`${GSL_CONFIG} --cflags` + GSL_LIBS=`${GSL_CONFIG} --libs-without-cblas` +else + AC_MSG_ERROR([gsl-config not found, is GSL installed?]) +fi + +## Use Rscript to query Rcpp for compiler and linker flags +## link flag providing libary as well as path to library, and optionally rpath +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e 'Rcpp:::LdFlags()'` + +# Now substitute these variables in src/Makevars.in to create src/Makevars +AC_SUBST(GSL_CFLAGS) +AC_SUBST(GSL_LIBS) +AC_SUBST(RCPP_LDFLAGS) + +AC_OUTPUT(src/Makevars) +@ + +Such a source \texttt{configure.in} gets converted into a script +\texttt{configure} by invoking the \texttt{autoconf} program. + +\subsubsection{Using functions provided by RcppGSL} + +\pkg{RcppGSL} provides R functions that allows one to retrieve the same +information. Therefore the configure script can also be written as: + +<>= +#!/bin/sh + +GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars +@ + +Similarly, the configure.win for windows can be written as: + +<>= +GSL_CFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "RcppGSL:::LdFlags()"` +RCPP_LDFLAGS=`${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe -e "Rcpp:::LdFlags()"` + +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" \ + -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" \ + -e "s|@RCPP_LDFLAGS@|${RCPP_LDFLAGS}|" \ + src/Makevars.in > src/Makevars.win +@ + +\subsection{The \texttt{src} directory} + +The \proglang{C++} source file takes the matrix supplied from \proglang{R} +and applies the \pkg{GSL} function to each column. + +<>= +#include +#include +#include + +extern "C" SEXP colNorm(SEXP sM) { + + try { + + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector + + } catch( std::exception &ex ) { + forward_exception_to_r( ex ); + + } catch(...) { + ::Rf_error( "c++ exception (unknown reason)" ); + } + return R_NilValue; // -Wall +} +@ + +The \proglang{Makevars.in} file governs the compilation and uses the values +supplied by \texttt{configure} during build-time: + +<>= + +# set by configure +GSL_CFLAGS = @GSL_CFLAGS@ +GSL_LIBS = @GSL_LIBS@ +RCPP_LDFLAGS = @RCPP_LDFLAGS@ + +# combine with standard arguments for R +PKG_CPPFLAGS = $(GSL_CFLAGS) +PKG_LIBS = $(GSL_LIBS) $(RCPP_LDFLAGS) +@ + +The variables surrounded by \@ will be filled by \texttt{configure} during +package build-time. + +\subsection{The \texttt{R} directory} + +The \proglang{R} source is very simply: a single matrix is passed to \proglang{C++}: + +<>= +colNorm <- function(M) { + stopifnot(is.matrix(M)) + res <- .Call("colNorm", M, package="RcppGSLExample") +} +@ + +\section{Using \pkg{RcppGSL} with \pkg{inline}} + +The \pkg{inline} package \citep{CRAN:inline} is very helpful for prototyping code in +\proglang{C}, \proglang{C++} or \proglang{Fortran} as it takes care of code +compilation, linking and dynamic loading directly from \proglang{R}. It is +being used extensively by \pkg{Rcpp}, for example in the numerous unit tests. + +The example below shows how \pkg{inline} can be deployed with +\pkg{RcppGSL}. We implement the same column norm example, but this time as an +\proglang{R} script which is compiled, linked and loaded on-the-fly. Compared +to standard use of \pkg{inline}, we have to make sure to add a short section +declaring which header files from \pkg{GSL} we need to use; the \pkg{RcppGSL} +then communicates with \pkg{inline} to tell it about the location and names +of libraries used to build code against \pkg{GSL}. + +<<>>= +require(inline) + +inctxt=' + #include + #include +' + +bodytxt=' + RcppGSL::matrix M = sM; // create gsl data structures from SEXP + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector +' + +foo <- cxxfunction( + signature(sM="numeric"), + body=bodytxt, inc=inctxt, plugin="RcppGSL") + +## see Section 8.4.13 of the GSL manual: create M as a sum of two outer products +M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*") +foo(M) +@ + +The \texttt{RcppGSL} inline plugin supports creation of a package skeleton +based on the inline function. + +<>= +package.skeleton( "mypackage", foo ) +@ + +\section{Summary} + +The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive +collection of rigorously developed and tested functions for applied +scientific computing under a common Open Source license. This has lead to +widespread deployment of \pkg{GSL} among a number of disciplines. + +Using the automatic wrapping and converters offered by the \pkg{RcppGSL} +package presented here, \proglang{R} users and programmers can now deploy +algorithmns provided by the \pkg{GSL} with greater ease. + +\bibliographystyle{plainnat} +\bibliography{\Sexpr{Rcpp:::bib()}} + \end{document} Modified: pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-20 02:24:33 UTC (rev 4358) +++ pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-21 11:41:09 UTC (rev 4359) @@ -10,7 +10,7 @@ \RequirePackage[T1]{fontenc} <>= -require( RcppGSL ) +require(RcppGSL) prettyVersion <- packageDescription("RcppGSL")$Version prettyDate <- format(Sys.Date(), "%B %e, %Y") @ @@ -19,16 +19,47 @@ \author{Dirk Eddelbuettel \and Romain Fran\c{c}ois} \title{\texttt{RcppGSL}: Unit testing results} \date{\texttt{RcppGSL} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} + \begin{document} \maketitle + +<>= +library(inline) +library(RUnit) + +pkg <- "RcppGSL" +cppfunction <- function(...) cxxfunction(..., plugin=pkg) + +if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) +dir.create("unitTests-results") + +path <- system.file("unitTests", package=pkg) + +testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) +tests <- runTestSuite(testSuite, verbose=FALSE) +err <- getErrors(tests) + +if (err$nFail > 0) stop(sprintf("unit test problems: %d failures", err$nFail)) +if (err$nErr > 0) stop( sprintf("unit test problems: %d errors", err$nErr)) + +printHTMLProtocol(tests, fileName= sprintf("unitTests-results/%s-unitTests.html", pkg)) +printTextProtocol(tests, fileName= sprintf("unitTests-results/%s-unitTests.txt" , pkg)) + +if (file.exists("/tmp")) { + invisible(file.copy(sprintf("unitTests-results/%s-unitTests.txt", pkg), "/tmp", overwrite=TRUE)) + invisible(file.copy(sprintf("unitTests-results/%s-unitTests.html", pkg), "/tmp", overwrite=TRUE)) +} +@ + + \begin{verbatim} -<>= [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4359 From noreply at r-forge.r-project.org Fri Jun 21 13:50:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 21 Jun 2013 13:50:22 +0200 (CEST) Subject: [Rcpp-commits] r4360 - pkg/RcppGSL/vignettes Message-ID: <20130621115022.9CD8418573E@r-forge.r-project.org> Author: edd Date: 2013-06-21 13:50:21 +0200 (Fri, 21 Jun 2013) New Revision: 4360 Removed: pkg/RcppGSL/vignettes/Makefile pkg/RcppGSL/vignettes/RcppGSL/ pkg/RcppGSL/vignettes/unitTests-results/ pkg/RcppGSL/vignettes/unitTests/ Log: the vignette/ cleanup commit: - removing Makefile (no longer needed) - removing vignettes/RcppGSL (no longer need a fake Rnw, RcppGSL-intro.Rnw is complete) - removing vignettes/unitTests (as Rcpp-unitTests.Rnw now calls directly) Deleted: pkg/RcppGSL/vignettes/Makefile =================================================================== --- pkg/RcppGSL/vignettes/Makefile 2013-06-21 11:41:09 UTC (rev 4359) +++ pkg/RcppGSL/vignettes/Makefile 2013-06-21 11:50:21 UTC (rev 4360) @@ -1,50 +0,0 @@ - -## There is an old bug in texidvi that makes it not swallow the ~ -## marker used to denote whitespace. This is actually due to fixing -## another bug whereby you could not run texidvi on directory names -## containing a tilde (as we happen to do for Debian builds of R -## alpha/beta/rc releases). The 'tilde' bug will go away as it -## reportedly has been squashed upstream but I am still bitten by it -## on Ubuntu so for now Dirk will insist on pdflatex and this helps. -whoami=$(shell whoami) - -all: RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -clean: - rm -f RcppGSL*.log RcppGSL*.aux RcppGSL*.out RcppGSL*.tex *.blg *.bbl *~ - rm -rf auto/ - -pdfclean: - rm -f RcppGSL-unitTests.pdf RcppGSL-intro.pdf - -setvars: -ifeq (${R_HOME},) -R_HOME= $(shell R RHOME) -endif -RPROG= $(R_HOME)/bin/R -RSCRIPT=$(R_HOME)/bin/Rscript - -RcppGSL-unitTests.pdf: - rm -fr unitTests-results/* - $(RSCRIPT) --vanilla unitTests/RcppGSL-unitTests.R - $(RPROG) CMD Sweave RcppGSL-unitTests.Rnw - $(RSCRIPT) --vanilla -e "tools::texi2dvi( 'RcppGSL-unitTests.tex', pdf = TRUE, clean = TRUE )" - rm -fr RcppGSL-unitTests.tex - -RcppGSL-intro.pdf: RcppGSL/RcppGSL-intro.Rnw - cp -f RcppGSL/RcppGSL-intro.Rnw . - $(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE); Sweave( 'RcppGSL-intro.Rnw', driver = driver ); " -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = FALSE )" -endif - bibtex RcppGSL-intro -ifneq (,$(findstring edd,$(whoami))) - pdflatex RcppGSL-intro - pdflatex RcppGSL-intro -else - $(RSCRIPT) -e "tools::texi2dvi( 'RcppGSL-intro.tex', pdf = TRUE, clean = TRUE )" -endif - rm -fr RcppGSL-intro.tex RcppGSL-intro.bbl RcppGSL-intro.blg RcppGSL-intro.aux RcppGSL-intro.out RcppGSL-intro.log - cp RcppGSL/RcppGSL-fake.Rnw RcppGSL-intro.Rnw From noreply at r-forge.r-project.org Fri Jun 21 23:30:01 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 21 Jun 2013 23:30:01 +0200 (CEST) Subject: [Rcpp-commits] r4361 - in pkg/RcppGSL: . src Message-ID: <20130621213001.CF94B185922@r-forge.r-project.org> Author: edd Date: 2013-06-21 23:30:00 +0200 (Fri, 21 Jun 2013) New Revision: 4361 Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/src/fastLm.cpp Log: minor improvement for computing std. error Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-21 11:50:21 UTC (rev 4360) +++ pkg/RcppGSL/ChangeLog 2013-06-21 21:30:00 UTC (rev 4361) @@ -5,6 +5,8 @@ * cleanup: Take some tasks that the vignette/Makefile had + * src/fastLm.cpp: Minor improvement in computing std.error of est. + 2013-06-19 Dirk Eddelbuettel * vignettes/RcppGSL/RcppGSL-intro.Rnw: Some fixes Modified: pkg/RcppGSL/src/fastLm.cpp =================================================================== --- pkg/RcppGSL/src/fastLm.cpp 2013-06-21 11:50:21 UTC (rev 4360) +++ pkg/RcppGSL/src/fastLm.cpp 2013-06-21 21:30:00 UTC (rev 4361) @@ -2,7 +2,7 @@ // // fastLm.cpp: Rcpp and GSL based implementation of lm // -// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of RcppGSL. // @@ -41,15 +41,12 @@ 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) ; - - // 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 ); + // assign diagonal to a vector, then take square roots to get std.error + Rcpp::NumericVector std_err; + std_err = gsl_matrix_diagonal(cov); // need two step decl. and assignment + std_err = sqrt(std_err); // sqrt() is an Rcpp sugar function + Rcpp::List res = Rcpp::List::create(Rcpp::Named("coefficients") = coef, Rcpp::Named("stderr") = std_err, Rcpp::Named("df.residual") = n - k); From noreply at r-forge.r-project.org Sat Jun 22 19:55:15 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 22 Jun 2013 19:55:15 +0200 (CEST) Subject: [Rcpp-commits] r4362 - in pkg/Rcpp: . inst Message-ID: <20130622175516.013321850A2@r-forge.r-project.org> Author: edd Date: 2013-06-22 19:55:15 +0200 (Sat, 22 Jun 2013) New Revision: 4362 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/DESCRIPTION pkg/Rcpp/inst/NEWS.Rd Log: minor edits in ChangeLog and NEWS rolled interim version number to 0.10.3.5 Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-21 21:30:00 UTC (rev 4361) +++ pkg/Rcpp/ChangeLog 2013-06-22 17:55:15 UTC (rev 4362) @@ -1,19 +1,24 @@ -2013-06-19 Romain Francois +2013-06-19 Romain Francois + * inst/NEWS.Rd: Document planned depreciation of old RCPP_FUNCION_* + macros which are redundant thanks to Rcpp Modules and Rcpp Attributes + * include/Rcpp/vector/string_proxy.h : added operator - string_proxy::operator==( const string_proxy& ) so that me may compare x[i] - and y[i] (x and y being CharacterVector) - * include/Rcpp/module/Module_generated_Pointer_CppMethod.h : remove const - and reference to OUT type in several places, that was causing problems e.g. - on making the Rcpp-modules vignette + string_proxy::operator==( const string_proxy& ) so that me may + compare x[i] and y[i] (x and y being CharacterVector) + + * include/Rcpp/module/Module_generated_Pointer_CppMethod.h : remove + const and reference to OUT type in several places, that was causing + problems e.g. on making the Rcpp-modules vignette + * include/Rcpp/module/Module_generated_CppMethod.h : idem - -2013-06-18 Romain Francois - * include/Rcpp/module/Module_generated_CppFunction.h : using BEGIN_RCPP / END_RCPP - as suggested by QRD in Rcpp-devel. This should reduce cross dll exceptions - issues on windows. +2013-06-18 Romain Francois + * include/Rcpp/module/Module_generated_CppFunction.h : using + BEGIN_RCPP / END_RCPP as suggested by Ben North on Rcpp-devel. This + should reduce cross dll exceptions issues on windows. + 2013-06-14 Romain Francois * include/Rcpp/stats/random/runif.h : removed unused max variable Modified: pkg/Rcpp/DESCRIPTION =================================================================== --- pkg/Rcpp/DESCRIPTION 2013-06-21 21:30:00 UTC (rev 4361) +++ pkg/Rcpp/DESCRIPTION 2013-06-22 17:55:15 UTC (rev 4362) @@ -1,6 +1,6 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 0.10.3.4 +Version: 0.10.3.5 Date: $Date$ Author: Dirk Eddelbuettel and Romain Francois, with contributions by Douglas Bates, John Chambers and JJ Allaire Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-21 21:30:00 UTC (rev 4361) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-22 17:55:15 UTC (rev 4362) @@ -29,7 +29,8 @@ it does not remove the element pointed by last (similar to what is done on stl types and what was intended initially). Reported on Rcpp-devel by Toni Giorgino. - \item Added equality operator between elements of \code{CharacterVector}s. + \item Added equality operator between elements of + \code{CharacterVector}s. } \item Changes in Rcpp sugar: \itemize{ @@ -41,8 +42,8 @@ } \item Changes in Rcpp build tools: \itemize{ - \item Fix (from Martyn Plummer) for solaris in handling - SingleLogicalResult. + \item Fix by Martyn Plummer for Solaris in handling of + \code{SingleLogicalResult}. \item The \code{src/Makevars} file can now optionally override the path for \code{/usr/bin/install_name_tool} which is used on OS X. \item Vignettes are trying harder not to be built in parallel. @@ -53,18 +54,17 @@ sourced by packages using Rcpp). \item Updated the \code{THANKS} file. } - \item Deprecation plans: + \item Planned Deprecation of \code{RCPP_FUNCTION_*}: \itemize{ \item The set of macros \code{RCPP_FUNCTION_} etc ... from the \code{preprocessor_generated.h} file will be deprecated in the next version - of \code{Rcpp}, i.e they will still be available but will generate some + of \pkg{Rcpp}, i.e they will still be available but will generate some warning in addition to their expected behavior. - - In the first release 12 months after now, the macros will be removed - from \code{Rcpp}. - - Users of these macros (if any) should start replacing them - with more up to date code, such as using attributes or modules. + \item In the first release that is at least 12 months after this announcement, the + macros will be removed from \pkg{Rcpp}. + \item Users of these macros (if there are any) should start replacing them + with more up to date code, such as using Rcpp attributes or Rcpp + modules. } } } From noreply at r-forge.r-project.org Sat Jun 22 22:23:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 22 Jun 2013 22:23:33 +0200 (CEST) Subject: [Rcpp-commits] r4363 - in pkg/RcppGSL: . inst inst/unitTests inst/unitTests/cpp Message-ID: <20130622202334.48A96185721@r-forge.r-project.org> Author: edd Date: 2013-06-22 22:23:33 +0200 (Sat, 22 Jun 2013) New Revision: 4363 Added: pkg/RcppGSL/inst/unitTests/cpp/ pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/inst/NEWS.Rd pkg/RcppGSL/inst/unitTests/runit.gsl.R Log: C++-based unit tests for RcppGSL now use sourceCpp Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-22 17:55:15 UTC (rev 4362) +++ pkg/RcppGSL/ChangeLog 2013-06-22 20:23:33 UTC (rev 4363) @@ -1,3 +1,9 @@ +2013-06-22 Dirk Eddelbuettel + + * inst/unitTests/runit.gsl.R: Rewritten to use sourceCpp() + + * inst/unitTests/cpp/gsl.cpp: New C++ file with unit tests + 2013-06-21 Dirk Eddelbuettel * vignettes/buildVignette.R: Added simple helper script to build Modified: pkg/RcppGSL/inst/NEWS.Rd =================================================================== --- pkg/RcppGSL/inst/NEWS.Rd 2013-06-22 17:55:15 UTC (rev 4362) +++ pkg/RcppGSL/inst/NEWS.Rd 2013-06-22 20:23:33 UTC (rev 4363) @@ -13,6 +13,8 @@ as R 3.0.0 supports different vignette engines, so the vignette build process has been simplified. A convenience helper script has also been added for command-line builds. + \item Unit tests now use \code{sourceCpp()} instead of + \code{cxxfunction()} from the \pkg{inline} package } } Added: pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp =================================================================== --- pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp (rev 0) +++ pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp 2013-06-22 20:23:33 UTC (rev 4363) @@ -0,0 +1,366 @@ +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- +// +// gsl.cpp: RcppGSL R integration of GSL via Rcpp -- unit tests +// +// Copyright (C) 2010 - 2013 Romain Francois and Dirk Eddelbuettel +// +// This file is part of RcppGSL. +// +// RcppGSL is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// RcppGSL is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RcppGSL. If not, see . + +#include +using namespace Rcpp; + +// [[Rcpp::export]] +List test_gsl_vector_wrapper() { + RcppGSL::vector x_double( 10 ); + RcppGSL::vector x_float( 10 ); + RcppGSL::vector x_int( 10 ); + //RcppGSL::vector x_long( 10 ); + RcppGSL::vector x_char( 10 ); + RcppGSL::vector x_long_double( 10 ); + RcppGSL::vector x_short( 10 ); + RcppGSL::vector x_uchar( 10 ); + RcppGSL::vector x_uint( 10 ); + RcppGSL::vector x_ushort( 10 ); + //RcppGSL::vector x_ulong( 10 ); + RcppGSL::vector x_complex( 10 ); + RcppGSL::vector x_complex_float( 10 ); + RcppGSL::vector x_complex_long_double( 10 ); + + List res = List::create(_["gsl_vector"] = x_double, + _["gsl_vector_float"] = x_float, + _["gsl_vector_int"] = x_int, + //_["gsl_vector_long"] = x_long, + _["gsl_vector_char"] = x_char, + _["gsl_vector_complex"] = x_complex, + _["gsl_vector_complex_float"] = x_complex_float, + _["gsl_vector_complex_long_double"] = x_complex_long_double, + _["gsl_vector_long_double"] = x_long_double, + _["gsl_vector_short"] = x_short, + _["gsl_vector_uchar"] = x_uchar, + _["gsl_vector_uint"] = x_uint, + _["gsl_vector_ushort"] = x_ushort + //,_["gsl_vector_ulong"] = x_ulong + ); + + x_double.free(); + x_float.free(); + x_int.free(); + //x_long.free(); + x_char.free(); + x_long_double.free(); + x_short.free(); + x_uchar.free(); + x_uint.free(); + x_ushort.free(); + //x_ulong.free(); + x_complex.free(); + x_complex_float.free(); + x_complex_long_double.free(); + + return res; +} + +// [[Rcpp::export]] +List test_gsl_vector() { + gsl_vector * x_double = gsl_vector_calloc (10); + gsl_vector_float * x_float = gsl_vector_float_calloc(10); + gsl_vector_int * x_int = gsl_vector_int_calloc(10); + //gsl_vector_long * x_long = gsl_vector_long_calloc(10); + gsl_vector_char * x_char = gsl_vector_char_calloc(10); + gsl_vector_complex * x_complex = gsl_vector_complex_calloc(10); + gsl_vector_complex_float * x_complex_float = gsl_vector_complex_float_calloc(10); + gsl_vector_complex_long_double * x_complex_long_double = gsl_vector_complex_long_double_calloc(10); + gsl_vector_long_double * x_long_double = gsl_vector_long_double_calloc(10); + gsl_vector_short * x_short = gsl_vector_short_calloc(10); + gsl_vector_uchar * x_uchar = gsl_vector_uchar_calloc(10); + gsl_vector_uint * x_uint = gsl_vector_uint_calloc(10); + gsl_vector_ushort * x_ushort = gsl_vector_ushort_calloc(10); + //gsl_vector_ulong * x_ulong = gsl_vector_ulong_calloc(10); + + /* create an R list containing copies of gsl data */ + List res = List::create(_["gsl_vector"] = *x_double, + _["gsl_vector_float"] = *x_float, + _["gsl_vector_int"] = *x_int, + //_["gsl_vector_long"] = *x_long, + _["gsl_vector_char"] = *x_char, + _["gsl_vector_complex"] = *x_complex, + _["gsl_vector_complex_float"] = *x_complex_float, + _["gsl_vector_complex_long_double"] = *x_complex_long_double, + _["gsl_vector_long_double"] = *x_long_double, + _["gsl_vector_short"] = *x_short, + _["gsl_vector_uchar"] = *x_uchar, + _["gsl_vector_uint"] = *x_uint, + _["gsl_vector_ushort"] = *x_ushort + //,_["gsl_vector_ulong"] = *x_ulong + ); + + /* cleanup gsl data */ + gsl_vector_free(x_double); + gsl_vector_float_free( x_float); + gsl_vector_int_free( x_int ); + //gsl_vector_long_free( x_long ); + gsl_vector_char_free( x_char ); + gsl_vector_complex_free( x_complex ); + gsl_vector_complex_float_free( x_complex_float ); + gsl_vector_complex_long_double_free( x_complex_long_double ); + gsl_vector_long_double_free( x_long_double ); + gsl_vector_short_free( x_short ); + gsl_vector_uchar_free( x_uchar ); + gsl_vector_uint_free( x_uint ); + gsl_vector_ushort_free( x_ushort ); + //gsl_vector_ulong_free( x_ulong ); + + return res; +} + +// [[Rcpp::export]] +List test_gsl_matrix() { + gsl_matrix * x_double = gsl_matrix_alloc(5, 2); + gsl_matrix_set_identity( x_double ); + gsl_matrix_float * x_float = gsl_matrix_float_alloc(5,2); + gsl_matrix_float_set_identity( x_float ); + gsl_matrix_int * x_int = gsl_matrix_int_alloc(5,2); + gsl_matrix_int_set_identity( x_int ); + //gsl_matrix_long * x_long = gsl_matrix_long_alloc(5,2); + //gsl_matrix_long_set_identity( x_long ); + gsl_matrix_char * x_char = gsl_matrix_char_alloc(5,2); + gsl_matrix_char_set_identity( x_char ); + gsl_matrix_complex * x_complex = gsl_matrix_complex_alloc(5,2); + gsl_matrix_complex_set_identity( x_complex ); + gsl_matrix_complex_float * x_complex_float = gsl_matrix_complex_float_alloc(5,2); + gsl_matrix_complex_float_set_identity( x_complex_float ); + gsl_matrix_complex_long_double * x_complex_long_double = gsl_matrix_complex_long_double_alloc(5,2); + gsl_matrix_complex_long_double_set_identity( x_complex_long_double ); + gsl_matrix_long_double * x_long_double = gsl_matrix_long_double_alloc(5,2); + gsl_matrix_long_double_set_identity( x_long_double ); + gsl_matrix_short * x_short = gsl_matrix_short_alloc(5,2); + gsl_matrix_short_set_identity( x_short ); + gsl_matrix_uchar * x_uchar = gsl_matrix_uchar_alloc(5,2); + gsl_matrix_uchar_set_identity( x_uchar ); + gsl_matrix_uint * x_uint = gsl_matrix_uint_alloc(5,2); + gsl_matrix_uint_set_identity( x_uint); + gsl_matrix_ushort * x_ushort = gsl_matrix_ushort_alloc(5,2); + gsl_matrix_ushort_set_identity( x_ushort ); + //gsl_matrix_ulong * x_ulong = gsl_matrix_ulong_alloc(5,2); + gsl_matrix_ulong_set_identity( x_ulong ); + + List res = List::create(_["gsl_matrix"] = *x_double , + _["gsl_matrix_float"] = *x_float, + _["gsl_matrix_int"] = *x_int, + //_["gsl_matrix_long"] = *x_long, + _["gsl_matrix_char"] = *x_char, + _["gsl_matrix_complex"] = *x_complex, + _["gsl_matrix_complex_float"] = *x_complex_float, + _["gsl_matrix_complex_long_double"] = *x_complex_long_double, + _["gsl_matrix_long_double"] = *x_long_double, + _["gsl_matrix_short"] = *x_short, + _["gsl_matrix_uchar"] = *x_uchar, + _["gsl_matrix_uint"] = *x_uint, + _["gsl_matrix_ushort"] = *x_ushort + //,_["gsl_matrix_ulong"] = *x_ulong + ); + + gsl_matrix_free( x_double ); + gsl_matrix_float_free( x_float); + gsl_matrix_int_free( x_int ); + //gsl_matrix_long_free( x_long ); + gsl_matrix_char_free( x_char ); + gsl_matrix_complex_free( x_complex ); + gsl_matrix_complex_float_free( x_complex_float ); + gsl_matrix_complex_long_double_free( x_complex_long_double ); + gsl_matrix_long_double_free( x_long_double ); + gsl_matrix_short_free( x_short ); + gsl_matrix_uchar_free( x_uchar ); + gsl_matrix_uint_free( x_uint ); + gsl_matrix_ushort_free( x_ushort ); + //gsl_matrix_ulong_free( x_ulong ); + + return res; +} + +// [[Rcpp::export]] +List test_gsl_vector_view() { + int n = 10; + gsl_vector *v = gsl_vector_calloc (n); + for( int i=0; i vec = as< RcppGSL::vector >(vec_); + int n = vec->size; + double res = 0.0; + for( int i=0; i mat = as< RcppGSL::matrix >( mat_); + int nr = mat->size1; + + double res = 0.0; + for( int i=0; i vec(10); + for( int i=0; i<10; i++){ + gsl_vector_int_set( vec, i, i ); + } + Rcpp::IntegerVector x; + x = vec; + return x; +} + +// [[Rcpp::export]] +NumericVector test_gsl_vector_indexing(NumericVector vec_) { + RcppGSL::vector vec = as< RcppGSL::vector >(vec_); + for( size_t i=0; i< vec.size(); i++){ + vec[i] = vec[i] + 1.0; + } + NumericVector res = Rcpp::wrap( vec ); + vec.free(); + return res; +} + +// [[Rcpp::export]] +double test_gsl_vector_iterating(NumericVector vec_) { + RcppGSL::vector vec = as< RcppGSL::vector >(vec_); + double res= std::accumulate( vec.begin(), vec.end(), 0.0 ); + vec.free(); + return wrap( res ); +} + +// [[Rcpp::export]] +List test_gsl_matrix_indexing(NumericMatrix mat_) { + RcppGSL::matrix mat= as< RcppGSL::matrix >( 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; + } + } + Rcpp::NumericMatrix res = Rcpp::wrap(mat); + mat.free(); + return res; +} + +// [[Rcpp::export]] +List test_gsl_vector_view_wrapper() { + int n = 10; + RcppGSL::vector vec( 10 ); + for( int i=0; i v_even = gsl_vector_subvector_with_stride(vec, 0, 2, n/2); + RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(vec, 1, 2, n/2); + + List res = List::create(_["even"] = v_even, + _["odd" ] = v_odd); + vec.free(); + + return res; +} + +// [[Rcpp::export]] +List test_gsl_matrix_view_wrapper() { + int nrow = 4; + int ncol = 6; + RcppGSL::matrix m(nrow, ncol); + int k =0; + for( int i=0; i x = gsl_matrix_submatrix(m, 2, 2, 2, 2 ); + + List res = List::create(_["full"] = m, + _["view"] = x); + m.free(); + + return res; +} + +// [[Rcpp::export]] +double test_gsl_vector_view_iterating(NumericVector vec_) { + RcppGSL::vector vec = as< RcppGSL::vector >(vec_); + int n = vec.size(); + RcppGSL::vector_view v_even = gsl_vector_subvector_with_stride(vec, 0, 2, n/2); + double res = std::accumulate( v_even.begin(), v_even.end(), 0.0 ); + return wrap( res ); +} + +// [[Rcpp::export]] +List test_gsl_matrix_view_indexing() { + int nr = 10; + int nc = 10; + RcppGSL::matrix mat( nr, nc ); + int k = 0; + for( size_t i=0; i< mat.nrow(); i++){ + for( size_t j=0; j< mat.ncol(); j++, k++){ + mat(i,j) = k; + } + } + RcppGSL::matrix_view x = gsl_matrix_submatrix(mat, 2, 2, 2, 2 ); + double res = 0.0; + for( size_t i=0; i. .setUp <- function(){ - require( inline ) - tests <- ".rcppgsl.tests" - if( ! exists( tests, globalenv() ) ){ - f <- list( - test_gsl_vector_wrapper = list( - signature(), - ' - RcppGSL::vector x_double( 10 ); - RcppGSL::vector x_float( 10 ); - RcppGSL::vector x_int( 10 ) ; - //RcppGSL::vector x_long( 10 ) ; - RcppGSL::vector x_char( 10 ) ; - RcppGSL::vector x_long_double( 10 ) ; - RcppGSL::vector x_short( 10 ) ; - RcppGSL::vector x_uchar( 10 ) ; - RcppGSL::vector x_uint( 10 ) ; - RcppGSL::vector x_ushort( 10 ) ; - //RcppGSL::vector x_ulong( 10 ) ; - RcppGSL::vector x_complex( 10 ) ; - RcppGSL::vector x_complex_float( 10 ) ; - RcppGSL::vector x_complex_long_double( 10 ) ; - - List res = List::create( - _["gsl_vector"] = x_double, - _["gsl_vector_float"] = x_float, - _["gsl_vector_int"] = x_int, - //_["gsl_vector_long"] = x_long, - _["gsl_vector_char"] = x_char, - _["gsl_vector_complex"] = x_complex, - _["gsl_vector_complex_float"] = x_complex_float, - _["gsl_vector_complex_long_double"] = x_complex_long_double, - _["gsl_vector_long_double"] = x_long_double, - _["gsl_vector_short"] = x_short, - _["gsl_vector_uchar"] = x_uchar, - _["gsl_vector_uint"] = x_uint, - _["gsl_vector_ushort"] = x_ushort - //,_["gsl_vector_ulong"] = x_ulong - ) ; - - x_double.free(); - x_float.free(); - x_int.free() ; - //x_long.free() ; - x_char.free() ; - x_long_double.free() ; - x_short.free() ; - x_uchar.free() ; - x_uint.free() ; - x_ushort.free() ; - //x_ulong.free() ; - x_complex.free() ; - x_complex_float.free() ; - x_complex_long_double.free() ; - - return res ; - - ' - ), - test_gsl_vector = list( - signature(), - ' - gsl_vector * x_double = gsl_vector_calloc (10); - gsl_vector_float * x_float = gsl_vector_float_calloc(10) ; - gsl_vector_int * x_int = gsl_vector_int_calloc(10) ; - //gsl_vector_long * x_long = gsl_vector_long_calloc(10) ; - gsl_vector_char * x_char = gsl_vector_char_calloc(10) ; - gsl_vector_complex * x_complex = gsl_vector_complex_calloc(10) ; - gsl_vector_complex_float * x_complex_float = gsl_vector_complex_float_calloc(10) ; - gsl_vector_complex_long_double * x_complex_long_double = gsl_vector_complex_long_double_calloc(10) ; - gsl_vector_long_double * x_long_double = gsl_vector_long_double_calloc(10) ; - gsl_vector_short * x_short = gsl_vector_short_calloc(10) ; - gsl_vector_uchar * x_uchar = gsl_vector_uchar_calloc(10) ; - gsl_vector_uint * x_uint = gsl_vector_uint_calloc(10) ; - gsl_vector_ushort * x_ushort = gsl_vector_ushort_calloc(10) ; - //gsl_vector_ulong * x_ulong = gsl_vector_ulong_calloc(10) ; - - /* create an R list containing copies of gsl data */ - List res = List::create( - _["gsl_vector"] = *x_double, - _["gsl_vector_float"] = *x_float, - _["gsl_vector_int"] = *x_int, - //_["gsl_vector_long"] = *x_long, - _["gsl_vector_char"] = *x_char, - _["gsl_vector_complex"] = *x_complex, - _["gsl_vector_complex_float"] = *x_complex_float, - _["gsl_vector_complex_long_double"] = *x_complex_long_double, - _["gsl_vector_long_double"] = *x_long_double, - _["gsl_vector_short"] = *x_short, - _["gsl_vector_uchar"] = *x_uchar, - _["gsl_vector_uint"] = *x_uint, - _["gsl_vector_ushort"] = *x_ushort - //,_["gsl_vector_ulong"] = *x_ulong - ) ; - - /* cleanup gsl data */ - gsl_vector_free(x_double); - gsl_vector_float_free( x_float); - gsl_vector_int_free( x_int ); - //gsl_vector_long_free( x_long ); - gsl_vector_char_free( x_char ); - gsl_vector_complex_free( x_complex ); - gsl_vector_complex_float_free( x_complex_float ); - gsl_vector_complex_long_double_free( x_complex_long_double ); - gsl_vector_long_double_free( x_long_double ); - gsl_vector_short_free( x_short ); - gsl_vector_uchar_free( x_uchar ); - gsl_vector_uint_free( x_uint ); - gsl_vector_ushort_free( x_ushort ); - //gsl_vector_ulong_free( x_ulong ); - - return res ; - - ' - ), - test_gsl_matrix = list( - signature(), - ' - gsl_matrix * x_double = gsl_matrix_alloc(5, 2); gsl_matrix_set_identity( x_double ) ; - gsl_matrix_float * x_float = gsl_matrix_float_alloc(5,2) ; gsl_matrix_float_set_identity( x_float ) ; - gsl_matrix_int * x_int = gsl_matrix_int_alloc(5,2) ; gsl_matrix_int_set_identity( x_int ) ; - //gsl_matrix_long * x_long = gsl_matrix_long_alloc(5,2) ; gsl_matrix_long_set_identity( x_long ) ; - gsl_matrix_char * x_char = gsl_matrix_char_alloc(5,2) ; gsl_matrix_char_set_identity( x_char ) ; - gsl_matrix_complex * x_complex = gsl_matrix_complex_alloc(5,2) ; gsl_matrix_complex_set_identity( x_complex ) ; - gsl_matrix_complex_float * x_complex_float = gsl_matrix_complex_float_alloc(5,2) ; gsl_matrix_complex_float_set_identity( x_complex_float ) ; - gsl_matrix_complex_long_double * x_complex_long_double = gsl_matrix_complex_long_double_alloc(5,2) ; gsl_matrix_complex_long_double_set_identity( x_complex_long_double ) ; - gsl_matrix_long_double * x_long_double = gsl_matrix_long_double_alloc(5,2) ; gsl_matrix_long_double_set_identity( x_long_double ) ; - gsl_matrix_short * x_short = gsl_matrix_short_alloc(5,2) ; gsl_matrix_short_set_identity( x_short ) ; - gsl_matrix_uchar * x_uchar = gsl_matrix_uchar_alloc(5,2) ; gsl_matrix_uchar_set_identity( x_uchar ) ; - gsl_matrix_uint * x_uint = gsl_matrix_uint_alloc(5,2) ; gsl_matrix_uint_set_identity( x_uint) ; - gsl_matrix_ushort * x_ushort = gsl_matrix_ushort_alloc(5,2) ; gsl_matrix_ushort_set_identity( x_ushort ) ; - //gsl_matrix_ulong * x_ulong = gsl_matrix_ulong_alloc(5,2) ; gsl_matrix_ulong_set_identity( x_ulong ) ; - - List res = List::create( - _["gsl_matrix"] = *x_double , - _["gsl_matrix_float"] = *x_float, - _["gsl_matrix_int"] = *x_int, - //_["gsl_matrix_long"] = *x_long, - _["gsl_matrix_char"] = *x_char, - _["gsl_matrix_complex"] = *x_complex, - _["gsl_matrix_complex_float"] = *x_complex_float, - _["gsl_matrix_complex_long_double"] = *x_complex_long_double, - _["gsl_matrix_long_double"] = *x_long_double, - _["gsl_matrix_short"] = *x_short, - _["gsl_matrix_uchar"] = *x_uchar, - _["gsl_matrix_uint"] = *x_uint, - _["gsl_matrix_ushort"] = *x_ushort - //,_["gsl_matrix_ulong"] = *x_ulong - ) ; - - gsl_matrix_free( x_double ); - gsl_matrix_float_free( x_float); - gsl_matrix_int_free( x_int ); - //gsl_matrix_long_free( x_long ); - gsl_matrix_char_free( x_char ); - gsl_matrix_complex_free( x_complex ); - gsl_matrix_complex_float_free( x_complex_float ); - gsl_matrix_complex_long_double_free( x_complex_long_double ); - gsl_matrix_long_double_free( x_long_double ); - gsl_matrix_short_free( x_short ); - gsl_matrix_uchar_free( x_uchar ); - gsl_matrix_uint_free( x_uint ); - gsl_matrix_ushort_free( x_ushort ); - //gsl_matrix_ulong_free( x_ulong ); - - return res ; - - ' - ), - test_gsl_vector_view = list( - signature(), - ' - int n = 10 ; - gsl_vector *v = gsl_vector_calloc (n); - for( int i=0 ; i vec = as< RcppGSL::vector >(vec_) ; - int n = vec->size ; - double res = 0.0 ; - for( int i=0; i mat = as< RcppGSL::matrix >( mat_) ; - int nr = mat->size1 ; - - double res = 0.0 ; - for( int i=0; i vec(10) ; - for( int i=0; i<10; i++){ - gsl_vector_int_set( vec, i, i ) ; - } - Rcpp::IntegerVector x ; - x = vec ; - return x ; - ' - ), - test_gsl_vector_indexing = list( - signature( vec_ = "numeric" ), - ' - RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; - for( size_t i=0; i< vec.size(); i++){ - vec[i] = vec[i] + 1.0 ; - } - NumericVector res = Rcpp::wrap( vec ) ; - vec.free() ; - return res ; - ' - ), - test_gsl_vector_iterating = list( - signature( vec_ = "numeric" ), - ' - RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; - double res= std::accumulate( vec.begin(), vec.end(), 0.0 ); - vec.free() ; - return wrap( res ) ; - - ' - ), - test_gsl_matrix_indexing = list( - signature( mat_ = "matrix" ), - ' - RcppGSL::matrix mat= as< RcppGSL::matrix >( 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 ; - } - } - Rcpp::NumericMatrix res = Rcpp::wrap(mat) ; - mat.free() ; - return res ; - ' - ), - test_gsl_vector_view_wrapper = list( - signature(), - ' - int n = 10 ; - RcppGSL::vector vec( 10 ) ; - for( int i=0 ; i v_even = gsl_vector_subvector_with_stride(vec, 0, 2, n/2); - RcppGSL::vector_view v_odd = gsl_vector_subvector_with_stride(vec, 1, 2, n/2); - - List res = List::create( - _["even"] = v_even, - _["odd" ] = v_odd - ) ; - vec.free() ; - - return res ; - - ' - ), - test_gsl_matrix_view_wrapper = list( - signature(), - ' - int nrow = 4 ; - int ncol = 6 ; - RcppGSL::matrix m(nrow, ncol); - int k =0 ; - for( int i=0 ; i x = gsl_matrix_submatrix(m, 2, 2, 2, 2 ) ; - - List res = List::create( - _["full"] = m, - _["view"] = x - ) ; - m.free() ; - - return res ; - - ' - ), - test_gsl_vector_view_iterating = list( - signature( vec_ = "numeric" ), - ' - RcppGSL::vector vec = as< RcppGSL::vector >(vec_) ; - int n = vec.size() ; - RcppGSL::vector_view v_even = gsl_vector_subvector_with_stride(vec, 0, 2, n/2); - double res = std::accumulate( v_even.begin(), v_even.end(), 0.0 ); - return wrap( res ) ; - - ' - ), - test_gsl_matrix_view_indexing = list( - signature(), - ' - int nr = 10 ; - int nc = 10 ; - RcppGSL::matrix mat( nr, nc ) ; - int k = 0; - for( size_t i=0; i< mat.nrow(); i++){ - for( size_t j=0; j< mat.ncol(); j++, k++){ - mat(i,j) = k ; - } - } - RcppGSL::matrix_view x = gsl_matrix_submatrix(mat, 2, 2, 2, 2 ) ; - double res = 0.0 ; - for( size_t i=0; i Author: edd Date: 2013-06-22 22:49:12 +0200 (Sat, 22 Jun 2013) New Revision: 4364 Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw pkg/RcppGSL/vignettes/buildVignette.R Log: some minor tweaks for the vignette process Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-22 20:23:33 UTC (rev 4363) +++ pkg/RcppGSL/ChangeLog 2013-06-22 20:49:12 UTC (rev 4364) @@ -1,9 +1,13 @@ 2013-06-22 Dirk Eddelbuettel - * inst/unitTests/runit.gsl.R: Rewritten to use sourceCpp() + * inst/unitTests/runit.gsl.R: Rewritten to use sourceCpp() * inst/unitTests/cpp/gsl.cpp: New C++ file with unit tests + * vignettes/RcppGSL-unitTests.Rnw: Minor tweaking + + * vignettes/buildVignette.R: Default to all .Rnw files in directory + 2013-06-21 Dirk Eddelbuettel * vignettes/buildVignette.R: Added simple helper script to build Modified: pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-22 20:23:33 UTC (rev 4363) +++ pkg/RcppGSL/vignettes/RcppGSL-unitTests.Rnw 2013-06-22 20:49:12 UTC (rev 4364) @@ -13,6 +13,7 @@ require(RcppGSL) prettyVersion <- packageDescription("RcppGSL")$Version prettyDate <- format(Sys.Date(), "%B %e, %Y") +library(RUnit) @ \usepackage[colorlinks]{hyperref} @@ -23,35 +24,30 @@ \begin{document} \maketitle +\section*{Test Execution} <>= -library(inline) -library(RUnit) - pkg <- "RcppGSL" -cppfunction <- function(...) cxxfunction(..., plugin=pkg) - if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) dir.create("unitTests-results") - path <- system.file("unitTests", package=pkg) - testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) -tests <- runTestSuite(testSuite, verbose=FALSE) +tests <- runTestSuite(testSuite) err <- getErrors(tests) - if (err$nFail > 0) stop(sprintf("unit test problems: %d failures", err$nFail)) if (err$nErr > 0) stop( sprintf("unit test problems: %d errors", err$nErr)) - printHTMLProtocol(tests, fileName= sprintf("unitTests-results/%s-unitTests.html", pkg)) printTextProtocol(tests, fileName= sprintf("unitTests-results/%s-unitTests.txt" , pkg)) if (file.exists("/tmp")) { - invisible(file.copy(sprintf("unitTests-results/%s-unitTests.txt", pkg), "/tmp", overwrite=TRUE)) - invisible(file.copy(sprintf("unitTests-results/%s-unitTests.html", pkg), "/tmp", overwrite=TRUE)) + invisible(sapply(c("txt", "html"), function(ext) { + fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) + file.copy(fname, "/tmp", overwrite=TRUE) + })) } @ +\section*{Test Results} \begin{verbatim} <>= Modified: pkg/RcppGSL/vignettes/buildVignette.R =================================================================== --- pkg/RcppGSL/vignettes/buildVignette.R 2013-06-22 20:23:33 UTC (rev 4363) +++ pkg/RcppGSL/vignettes/buildVignette.R 2013-06-22 20:49:12 UTC (rev 4364) @@ -1,15 +1,10 @@ #!/usr/bin/Rscript -args <- commandArgs(TRUE) -if (length(args) == 0) { - cat("No argument given, using 'RcppGSL-intro.Rnw'\n") - srcfile <- "RcppGSL-intro.Rnw" -} else { - srcfile <- args[1] -} +## use given argument(s) as target files, or else default to .Rnw files in directory +files <- if (length(commandArgs(TRUE)) == 0) dir(pattern="*.Rnw") else commandArgs(TRUE) -texfile <- gsub(".Rnw", ".tex", srcfile) - -Sweave(srcfile, driver=highlight::HighlightWeaveLatex()) -tools::texi2pdf(texfile) - +## convert all files from Rnw to pdf using the highlight driver +invisible(sapply(files, function(srcfile) { + Sweave(srcfile, driver=highlight::HighlightWeaveLatex()) + tools::texi2pdf(gsub(".Rnw", ".tex", srcfile)) +})) From noreply at r-forge.r-project.org Sat Jun 22 23:25:41 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 22 Jun 2013 23:25:41 +0200 (CEST) Subject: [Rcpp-commits] r4365 - in pkg/RcppGSL: . vignettes Message-ID: <20130622212541.E25EE1847A9@r-forge.r-project.org> Author: edd Date: 2013-06-22 23:25:41 +0200 (Sat, 22 Jun 2013) New Revision: 4365 Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw pkg/RcppGSL/vignettes/buildVignette.R Log: added section on attributes to intro vignette Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-22 20:49:12 UTC (rev 4364) +++ pkg/RcppGSL/ChangeLog 2013-06-22 21:25:41 UTC (rev 4365) @@ -6,8 +6,11 @@ * vignettes/RcppGSL-unitTests.Rnw: Minor tweaking - * vignettes/buildVignette.R: Default to all .Rnw files in directory + * vignettes/RcppGSL-intro.Rnw: Added section on attributes + * vignettes/buildVignette.R: Default to all .Rnw files in directory, + also set boxes option to TRUE + 2013-06-21 Dirk Eddelbuettel * vignettes/buildVignette.R: Added simple helper script to build Modified: pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw =================================================================== --- pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-22 20:49:12 UTC (rev 4364) +++ pkg/RcppGSL/vignettes/RcppGSL-intro.Rnw 2013-06-22 21:25:41 UTC (rev 4365) @@ -58,9 +58,8 @@ The \pkg{RcppGSL} package provides an easy-to-use interface between \pkg{GSL} data structures and \proglang{R} using concepts from \pkg{Rcpp} - \citep{JSS:Rcpp,CRAN:Rcpp} which is itself a package that eases the interfaces - between \proglang{R} and C++. -} + \citep{JSS:Rcpp,CRAN:Rcpp,Eddelbuettel:2013:Rcpp} which is itself a package + that eases the interfaces between \proglang{R} and C++. } \section{Introduction} @@ -749,6 +748,63 @@ package.skeleton( "mypackage", foo ) @ +\section{Using \pkg{RcppGSL} with Rcpp Attributes} + +\textsl{Rcpp Attributes} \citep{CRAN:Rcpp:Attributes} builds on the features +of the \pkg{inline} package described in previous section, and streamline the +compilation, loading and linking process even further. It leverages the +existing plugins for \pkg{inline}. This section illustrates how the example +from the previous section can be written using \textsl{Rcpp Attributes}. + + +<>= + +#include +#include + +#include + +// declare a dependency on the RcppGSL package; also activates plugin +// +// [[Rcpp::depends(RcppGSL)]] + +// declare the function to be 'exported' to R +// +// [[Rcpp::export]] +Rcpp::NumericVector foo(Rcpp::NumericMatrix sM) { + RcppGSL::matrix M = Rcpp::as >(sM); + int k = M.ncol(); + Rcpp::NumericVector n(k); // to store results + + for (int j = 0; j < k; j++) { + RcppGSL::vector_view colview = gsl_matrix_column (M, j); + n[j] = gsl_blas_dnrm2(colview); + } + M.free() ; + return n; // return vector +} + +/*** R +## see Section 8.4.13 of the GSL manual: +## create M as a sum of two outer products +M <- outer(sin(0:9), rep(1,10), "*") + + outer(rep(1, 10), cos(0:9), "*") +foo(M) +*/ +@ + +With the code above stored in a file, say, ``gslNorm.cpp'' one can simply +call \texttt{sourceCpp()} to have the wrapper code added, and all of the +compilation, linking and loading done --- including the execution of the +short \proglang{R} segment at the end: + +<>= +sourceCpp("gslNorm.cpp") +@ + +See the vignette ``Rcpp-attributes'' \citep{CRAN:Rcpp:Attributes} of the +\pkg{Rcpp} package \citep{CRAN:Rcpp} for details. + \section{Summary} The GNU Scientific Library (GSL) by \citet{GSL} offers a very comprehensive Modified: pkg/RcppGSL/vignettes/buildVignette.R =================================================================== --- pkg/RcppGSL/vignettes/buildVignette.R 2013-06-22 20:49:12 UTC (rev 4364) +++ pkg/RcppGSL/vignettes/buildVignette.R 2013-06-22 21:25:41 UTC (rev 4365) @@ -5,6 +5,6 @@ ## convert all files from Rnw to pdf using the highlight driver invisible(sapply(files, function(srcfile) { - Sweave(srcfile, driver=highlight::HighlightWeaveLatex()) + Sweave(srcfile, driver=highlight::HighlightWeaveLatex(boxes=TRUE)) tools::texi2pdf(gsub(".Rnw", ".tex", srcfile)) })) From noreply at r-forge.r-project.org Sun Jun 23 00:15:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 23 Jun 2013 00:15:28 +0200 (CEST) Subject: [Rcpp-commits] r4366 - pkg/Rcpp/inst/doc Message-ID: <20130622221528.822EE185984@r-forge.r-project.org> Author: edd Date: 2013-06-23 00:15:27 +0200 (Sun, 23 Jun 2013) New Revision: 4366 Modified: pkg/Rcpp/inst/doc/Rcpp.bib Log: added Stroustrup (2013, 4th ed) Modified: pkg/Rcpp/inst/doc/Rcpp.bib =================================================================== --- pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-22 21:25:41 UTC (rev 4365) +++ pkg/Rcpp/inst/doc/Rcpp.bib 2013-06-22 22:15:27 UTC (rev 4366) @@ -543,6 +543,16 @@ edition = {3rd} } + at Book{Stroustrup:2013:Cpp, + author = {Bjarne Stroustrup}, + title = {The C++ Programming Language}, + publisher = {Addison-Wesley}, + address = {Boston}, + year = 1997, + page = 1368, + edition = {4th} +} + @Article{TempleLang:2009:ModestProposal, author = {Duncan {Temple Lang}}, title = {A modest proposal: an approach to making the From noreply at r-forge.r-project.org Sun Jun 23 17:14:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 23 Jun 2013 17:14:48 +0200 (CEST) Subject: [Rcpp-commits] r4367 - in pkg/Rcpp: . debian inst inst/include/Rcpp Message-ID: <20130623151448.A36E818508E@r-forge.r-project.org> Author: edd Date: 2013-06-23 17:14:47 +0200 (Sun, 23 Jun 2013) New Revision: 4367 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/DESCRIPTION pkg/Rcpp/debian/changelog pkg/Rcpp/debian/control pkg/Rcpp/debian/r-cran-rcpp.lintian-overrides pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/include/Rcpp/config.h Log: Rcpp release 0.10.4 Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/ChangeLog 2013-06-23 15:14:47 UTC (rev 4367) @@ -1,3 +1,10 @@ +2013-06-23 Dirk Eddelbuettel + + * DESCRIPTION: Release 0.10.4 + * inst/NEWS.Rd: Release 0.10.4 + * inst/include/Rcpp/config.h: Release 0.10.4 + * debian/*: Similarly updated for new release to Debian + 2013-06-19 Romain Francois * inst/NEWS.Rd: Document planned depreciation of old RCPP_FUNCION_* Modified: pkg/Rcpp/DESCRIPTION =================================================================== --- pkg/Rcpp/DESCRIPTION 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/DESCRIPTION 2013-06-23 15:14:47 UTC (rev 4367) @@ -1,6 +1,6 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 0.10.3.5 +Version: 0.10.4 Date: $Date$ Author: Dirk Eddelbuettel and Romain Francois, with contributions by Douglas Bates, John Chambers and JJ Allaire @@ -37,7 +37,7 @@ package development. Attributes are built on top of Rcpp modules and their implementation is based on previous work in the inline package. . - Many examples are included, and over 870 unit tests in over 400 unit + Many examples are included, and around 881 unit tests in 412 unit test functions provide additional usage examples. . An earlier version of Rcpp, containing what we now call the 'classic Rcpp Modified: pkg/Rcpp/debian/changelog =================================================================== --- pkg/Rcpp/debian/changelog 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/debian/changelog 2013-06-23 15:14:47 UTC (rev 4367) @@ -1,3 +1,11 @@ +rcpp (0.10.4-1) unstable; urgency=low + + * New release + + * debian/control: Set Build-Depends: to current R version + + -- Dirk Eddelbuettel Sun, 23 Jun 2013 09:02:24 -0500 + rcpp (0.10.3-2) unstable; urgency=low * debian/control: Set Build-Depends: to current R version Modified: pkg/Rcpp/debian/control =================================================================== --- pkg/Rcpp/debian/control 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/debian/control 2013-06-23 15:14:47 UTC (rev 4367) @@ -2,7 +2,7 @@ Section: gnu-r Priority: optional Maintainer: Dirk Eddelbuettel -Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.0.0~20130327), cdbs +Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.0.1), cdbs Standards-Version: 3.9.4 Homepage: http://dirk.eddelbuettel.com/code/rcpp.html @@ -43,7 +43,7 @@ package development. Attributes are built on top of Rcpp modules and their implementation is based on previous work in the inline package. . - Many examples are included, and over 870 unit tests in over 390 unit + Many examples are included, and around 881 unit tests in 412 unit test functions provide additional usage examples. . An earlier version of Rcpp, containing what we now call the 'classic Rcpp Modified: pkg/Rcpp/debian/r-cran-rcpp.lintian-overrides =================================================================== --- pkg/Rcpp/debian/r-cran-rcpp.lintian-overrides 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/debian/r-cran-rcpp.lintian-overrides 2013-06-23 15:14:47 UTC (rev 4367) @@ -72,3 +72,4 @@ r-cran-rcpp: script-not-executable usr/lib/R/site-library/Rcpp/unitTests/runit.rmath.R r-cran-rcpp: script-not-executable usr/lib/R/site-library/Rcpp/unitTests/runit.String.R r-cran-rcpp: script-not-executable usr/lib/R/site-library/Rcpp/unitTests/runit.wstring.R +r-cran-rcpp: script-not-executable usr/lib/R/site-library/Rcpp/unitTests/runit.Reference.R Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-23 15:14:47 UTC (rev 4367) @@ -2,9 +2,9 @@ \title{News for Package 'Rcpp'} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} - \section{Changes in Rcpp version 0.10.4 (future)}{ + \section{Changes in Rcpp version 0.10.4 (2013-06-23)}{ \itemize{ - \item Changes in R code: + \item Changes in R code: None beyond those detailed for Rcpp Attributes \item Changes in Rcpp attributes: \itemize{ \item Fixed problem whereby the interaction between the gc and the Modified: pkg/Rcpp/inst/include/Rcpp/config.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/config.h 2013-06-22 22:15:27 UTC (rev 4366) +++ pkg/Rcpp/inst/include/Rcpp/config.h 2013-06-23 15:14:47 UTC (rev 4367) @@ -25,7 +25,7 @@ #define Rcpp_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s)) // All three digits have to be integers for g++-4.7 or later -#define RCPP_VERSION Rcpp_Version(0,10,3) +#define RCPP_VERSION Rcpp_Version(0,10,4) // Rcpp 0.10.3 has initial support for new preserve/release semantics // This switch enables a rollback to the standard R preserve/release semantics From noreply at r-forge.r-project.org Sun Jun 23 17:25:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 23 Jun 2013 17:25:00 +0200 (CEST) Subject: [Rcpp-commits] r4368 - in pkg/Rcpp: . debian Message-ID: <20130623152500.5E0EB18090B@r-forge.r-project.org> Author: edd Date: 2013-06-23 17:24:59 +0200 (Sun, 23 Jun 2013) New Revision: 4368 Modified: pkg/Rcpp/DESCRIPTION pkg/Rcpp/debian/control Log: one typo in Description: fixed (thanks, win-builder spell check) one paragraph DESCRIPTION added to debian/control copy of it Modified: pkg/Rcpp/DESCRIPTION =================================================================== --- pkg/Rcpp/DESCRIPTION 2013-06-23 15:14:47 UTC (rev 4367) +++ pkg/Rcpp/DESCRIPTION 2013-06-23 15:24:59 UTC (rev 4368) @@ -46,7 +46,7 @@ available for code relying on the older interface. New development should always use this Rcpp package instead. . - Addditional documentation is available via the paper by Eddelbuettel and + Additional documentation is available via the paper by Eddelbuettel and Francois (2011, JSS) paper and the book by Eddelbuettel (2013, Springer); see 'citation("Rcpp")' for details. Depends: R (>= 2.15.1) Modified: pkg/Rcpp/debian/control =================================================================== --- pkg/Rcpp/debian/control 2013-06-23 15:14:47 UTC (rev 4367) +++ pkg/Rcpp/debian/control 2013-06-23 15:24:59 UTC (rev 4368) @@ -51,4 +51,8 @@ been factored out of Rcpp into the package RcppClassic and it is still available for code relying on this interface. New development should use this package instead. + . + Additional documentation is available via the paper by Eddelbuettel and + Francois (2011, JSS) paper and the book by Eddelbuettel (2013, Springer); + see 'citation("Rcpp")' for details. From noreply at r-forge.r-project.org Sun Jun 23 22:44:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 23 Jun 2013 22:44:26 +0200 (CEST) Subject: [Rcpp-commits] r4369 - in pkg/RcppGSL: . inst/unitTests inst/unitTests/cpp Message-ID: <20130623204426.D2BDC185734@r-forge.r-project.org> Author: edd Date: 2013-06-23 22:44:25 +0200 (Sun, 23 Jun 2013) New Revision: 4369 Modified: pkg/RcppGSL/ChangeLog pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp pkg/RcppGSL/inst/unitTests/runit.gsl.R Log: brown paper bag corrections Modified: pkg/RcppGSL/ChangeLog =================================================================== --- pkg/RcppGSL/ChangeLog 2013-06-23 15:24:59 UTC (rev 4368) +++ pkg/RcppGSL/ChangeLog 2013-06-23 20:44:25 UTC (rev 4369) @@ -1,3 +1,8 @@ +2013-06-23 Dirk Eddelbuettel + + * inst/unitTests/runit.gsl.R: Corrections to new unitTest scheme + * inst/unitTests/cpp/gsl.cpp: Idem + 2013-06-22 Dirk Eddelbuettel * inst/unitTests/runit.gsl.R: Rewritten to use sourceCpp() Modified: pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp =================================================================== --- pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp 2013-06-23 15:24:59 UTC (rev 4368) +++ pkg/RcppGSL/inst/unitTests/cpp/gsl.cpp 2013-06-23 20:44:25 UTC (rev 4369) @@ -19,9 +19,12 @@ // You should have received a copy of the GNU General Public License // along with RcppGSL. If not, see . -#include +#include + using namespace Rcpp; +// [[Rcpp::depends(RcppGSL)]] + // [[Rcpp::export]] List test_gsl_vector_wrapper() { RcppGSL::vector x_double( 10 ); @@ -155,7 +158,7 @@ gsl_matrix_ushort * x_ushort = gsl_matrix_ushort_alloc(5,2); gsl_matrix_ushort_set_identity( x_ushort ); //gsl_matrix_ulong * x_ulong = gsl_matrix_ulong_alloc(5,2); - gsl_matrix_ulong_set_identity( x_ulong ); + //gsl_matrix_ulong_set_identity( x_ulong ); List res = List::create(_["gsl_matrix"] = *x_double , _["gsl_matrix_float"] = *x_float, @@ -237,7 +240,7 @@ res += gsl_vector_get( vec, i ); } vec.free(); - return wrap( res ); + return res; } // [[Rcpp::export]] @@ -250,7 +253,7 @@ res += mat( i, 0 ); } mat.free(); - return wrap(res); + return res; } // [[Rcpp::export]] @@ -280,11 +283,20 @@ RcppGSL::vector vec = as< RcppGSL::vector >(vec_); double res= std::accumulate( vec.begin(), vec.end(), 0.0 ); vec.free(); - return wrap( res ); + return res; } // [[Rcpp::export]] -List test_gsl_matrix_indexing(NumericMatrix mat_) { +NumericVector test_gsl_vector_iterator_transform(NumericVector vec_) { + RcppGSL::vector vec = as< RcppGSL::vector >(vec_); + NumericVector res(vec.size()); + std::transform(vec.begin(), vec.end(), res.begin(), ::sqrt); + vec.free(); + return res; +} + +// [[Rcpp::export]] +NumericMatrix test_gsl_matrix_indexing(NumericMatrix mat_) { RcppGSL::matrix mat= as< RcppGSL::matrix >( mat_ ); for( size_t i=0; i< mat.nrow(); i++){ for( size_t j=0; j< mat.ncol(); j++){ @@ -339,11 +351,11 @@ int n = vec.size(); RcppGSL::vector_view v_even = gsl_vector_subvector_with_stride(vec, 0, 2, n/2); double res = std::accumulate( v_even.begin(), v_even.end(), 0.0 ); - return wrap( res ); + return res; } // [[Rcpp::export]] -List test_gsl_matrix_view_indexing() { +double test_gsl_matrix_view_indexing() { int nr = 10; int nc = 10; RcppGSL::matrix mat( nr, nc ); @@ -361,6 +373,5 @@ } } mat.free(); - return wrap( res ); + return res; } - Modified: pkg/RcppGSL/inst/unitTests/runit.gsl.R =================================================================== --- pkg/RcppGSL/inst/unitTests/runit.gsl.R 2013-06-23 15:24:59 UTC (rev 4368) +++ pkg/RcppGSL/inst/unitTests/runit.gsl.R 2013-06-23 20:44:25 UTC (rev 4369) @@ -1,7 +1,7 @@ #!/usr/bin/r -t # Emacs make this -*- mode: R; tab-width: 4 -*- # -# Copyright (C) 2010 Romain Francois and Dirk Eddelbuettel +# Copyright (C) 2010 - 2013 Romain Francois and Dirk Eddelbuettel # # This file is part of RcppGSL. # @@ -18,8 +18,9 @@ # You should have received a copy of the GNU General Public License # along with RcppGSL. If not, see . -.setUp <- function(){ - if (!exists("pathRcppTests")) pathRcppTests <- getwd() +.setUp <- function() { + if (!exists("pathRcppTests")) + pathRcppTests <- system.file("unitTests", package="RcppGSL") sourceCpp(file.path(pathRcppTests, "cpp/gsl.cpp")) } @@ -117,7 +118,7 @@ res <- fx() checkEquals( res$full[3:4, 3:4], res$view, msg = "wrap(gsl.matrix.view)" ) - fx <- .rcppgsl.tests$test_gsl_matrix_view_wrapper + fx <- test_gsl_matrix_view_wrapper res <- fx() checkEquals( res$full[3:4, 3:4], res$view, msg = "wrap(gsl.matrix.view.wrapper)" ) } @@ -155,6 +156,13 @@ checkEquals( res, sum(x) ) } +test.gsl.RcppGSL.vector.iterator.transform <- function() { + x <- seq(0.5, 10.5) + fx <- test_gsl_vector_iterator_transform + res <- fx(x) + checkEquals(res, sqrt(x)) +} + test.gsl.RcppGSL.matrix.indexing <- function(){ m <- matrix( 1:16+.5, nr = 4 ) fx <- test_gsl_matrix_indexing From noreply at r-forge.r-project.org Mon Jun 24 02:13:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 24 Jun 2013 02:13:52 +0200 (CEST) Subject: [Rcpp-commits] r4370 - pkg/Rcpp/man Message-ID: <20130624001353.38E70181291@r-forge.r-project.org> Author: edd Date: 2013-06-24 02:13:52 +0200 (Mon, 24 Jun 2013) New Revision: 4370 Modified: pkg/Rcpp/man/setRcppClass.Rd Log: set 90-column limit requested by CRAN Modified: pkg/Rcpp/man/setRcppClass.Rd =================================================================== --- pkg/Rcpp/man/setRcppClass.Rd 2013-06-23 20:44:25 UTC (rev 4369) +++ pkg/Rcpp/man/setRcppClass.Rd 2013-06-24 00:13:52 UTC (rev 4370) @@ -11,7 +11,8 @@ C++ class. } \usage{ -setRcppClass(Class, CppClass, module, fields = list(), contains = , methods = , saveAs = Class, where = , ...) +setRcppClass(Class, CppClass, module, fields = list(), contains = , + methods = , saveAs = Class, where = , ...) } %- maybe also 'usage' for other objects documented here. \arguments{ @@ -36,7 +37,8 @@ \item{saveAs}{ Save a generator object for the class in the package's namespace under this name. By default, the generator object has the name of the -class. To avoid saving any generator object, supply this argument as \code{NULL}. +class. To avoid saving any generator object, supply this argument as +\code{NULL}. } \item{where}{ The environment in which to save the class definition. By default, From noreply at r-forge.r-project.org Mon Jun 24 21:04:23 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 24 Jun 2013 21:04:23 +0200 (CEST) Subject: [Rcpp-commits] r4371 - in pkg/Rcpp: . inst/include/Rcpp/platform Message-ID: <20130624190423.BAFF31858A1@r-forge.r-project.org> Author: edd Date: 2013-06-24 21:04:22 +0200 (Mon, 24 Jun 2013) New Revision: 4371 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/include/Rcpp/platform/compiler.h Log: Note the useful wiki page http://sourceforge.net/p/predef/wiki/Home with #defines for OSs, compilers, libraries and more Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-24 00:13:52 UTC (rev 4370) +++ pkg/Rcpp/ChangeLog 2013-06-24 19:04:22 UTC (rev 4371) @@ -1,3 +1,9 @@ +2013-06-24 Dirk Eddelbuettel + + * inst/include/Rcpp/platform/compiler.h: Note the useful wiki page + http://sourceforge.net/p/predef/wiki/Home with #defines for OSs, + compilers, libraries and more + 2013-06-23 Dirk Eddelbuettel * DESCRIPTION: Release 0.10.4 Modified: pkg/Rcpp/inst/include/Rcpp/platform/compiler.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/platform/compiler.h 2013-06-24 00:13:52 UTC (rev 4370) +++ pkg/Rcpp/inst/include/Rcpp/platform/compiler.h 2013-06-24 19:04:22 UTC (rev 4371) @@ -2,7 +2,7 @@ // // compiler.h: Rcpp R/C++ interface class library -- check compiler // -// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -22,6 +22,9 @@ #ifndef Rcpp__platform__compiler_h #define Rcpp__platform__compiler_h +// NB: A vast list valid identifiers is at these wiki pages: +// http://sourceforge.net/p/predef/wiki/Home/ + #undef GOOD_COMPILER_FOR_RCPP #ifdef __GNUC__ #define GOOD_COMPILER_FOR_RCPP From noreply at r-forge.r-project.org Tue Jun 25 10:04:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Jun 2013 10:04:36 +0200 (CEST) Subject: [Rcpp-commits] r4372 - scripts Message-ID: <20130625080436.D7808185296@r-forge.r-project.org> Author: romain Date: 2013-06-25 10:04:35 +0200 (Tue, 25 Jun 2013) New Revision: 4372 Modified: scripts/preprocessor.R Log: added deprecated message Modified: scripts/preprocessor.R =================================================================== --- scripts/preprocessor.R 2013-06-24 19:04:22 UTC (rev 4371) +++ scripts/preprocessor.R 2013-06-25 08:04:35 UTC (rev 4372) @@ -22,6 +22,7 @@ extern "C" SEXP __NAME__(%s){ \\ SEXP res = R_NilValue ; \\ BEGIN_RCPP \\ +REprintf(" RCPP_FUNCTION_%d is deprecated, it will be removed permanently in july 2014\\n" ) ; \\ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(%s) ) ; \\ return res ; \\ END_RCPP \\ @@ -33,6 +34,7 @@ if( i == 0 ) "" else paste( sprintf( "#___%d", 0:(i-1)), collapse=", "), if( i == 0 ) "" else paste( sprintf( "___%d", 0:(i-1)), collapse=", "), if( i == 0 ) "" else paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ), + i, if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1) ), collapse = ", " ), if( i == 0 ) "" else paste( sprintf( "___%d", 0:(i-1)), collapse=", ") ) @@ -56,6 +58,7 @@ } \\ extern "C" SEXP __NAME__(%s){ \\ BEGIN_RCPP \\ +REprintf(" RCPP_FUNCTION_VOID_%d is deprecated, it will be removed permanently in july 2014\\n" ) ; \\ RCPP_DECORATE(__NAME__)(%s) ; \\ END_RCPP \\ } \\ @@ -66,50 +69,12 @@ i, if( i == 0 ) "" else paste( sprintf( "#___%d", 0:(i-1)), collapse=", "), if( i == 0 ) "" else paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ), + i, if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1) ), collapse = ", " ), if( i == 0 ) "" else paste( sprintf( "___%d", 0:(i-1)), collapse=", ") ) }) -# -# rcpp_function_nodecl <- sapply( 0:65, function(i){ -# txt <- sprintf( ' -# #define RCPP_FUNCTION_NODECL_%d(__OUT__,__NAME__%s) \\ -# extern "C" SEXP __NAME__(%s){ \\ -# SEXP res = R_NilValue ; \\ -# BEGIN_RCPP \\ -# res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(%s) ) ; \\ -# END_RCPP \\ -# return res ; \\ -# } \\ -# __OUT__ RCPP_DECORATE(__NAME__)(%s)', -# i, -# if( i == 0 ) "" else paste( ",", paste( sprintf( "___%d", 0:(i-1)), collapse=", ") ), -# if( i == 0 ) "" else paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ), -# if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1) ), collapse = ", " ), -# if( i == 0 ) "" else paste( sprintf( "___%d", 0:(i-1)), collapse=", ") -# ) -# }) - - -# rcpp_wrapper <- sapply( 0:65, function(i){ -# txt <- sprintf( ' -# #define RCPP_WRAPPER_%d(__OUT__,__NAME__) \\ -# extern "C" SEXP __OUT__(%s){ \\ -# SEXP res = R_NilValue ; \\ -# BEGIN_RCPP \\ -# res = ::Rcpp::wrap( __NAME__(%s) ) ; \\ -# END_RCPP \\ -# return res ; \\ -# } -# ', -# i, -# if( i == 0 ) "" else paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ), -# if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1) ), collapse = ", " ) -# ) -# }) - - rcpp_xp_method <- sapply( 0:65, function(i){ txt <- sprintf( ' #define RCPP_XP_METHOD_%d(__NAME__,__CLASS__,__METHOD__ ) \\ @@ -125,6 +90,7 @@ } \\ extern "C" SEXP __NAME__( SEXP xp %s ){ \\ BEGIN_RCPP \\ + REprintf(" RCPP_XP_METHOD_%d is deprecated, it will be removed permanently in july 2014\\n" ) ; \\ ::Rcpp::XPtr< __CLASS__ > ptr(xp) ; \\ return ::Rcpp::wrap( ptr->__METHOD__( %s ) ) ; \\ END_RCPP \\ @@ -133,6 +99,7 @@ i, i, if( i == 0 ) "" else paste( ", ", paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ) ), + i, if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1)), collapse=", ") ) @@ -154,6 +121,7 @@ } \\ extern "C" SEXP __NAME__( SEXP xp %s ){ \\ BEGIN_RCPP \\ + REprintf(" RCPP_XP_METHOD_CAST_%d is deprecated, it will be removed permanently in july 2014\\n" ) ; \\ ::Rcpp::XPtr< __CLASS__ > ptr(xp) ; \\ return ::Rcpp::wrap( __CAST__( ptr->__METHOD__( %s ) ) ) ;\\ END_RCPP \\ @@ -162,6 +130,7 @@ i, i, if( i == 0 ) "" else paste( ", ", paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ) ), + i, if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1)), collapse=", ") ) @@ -184,6 +153,7 @@ } \\ extern "C" SEXP __NAME__( SEXP xp %s ){ \\ BEGIN_RCPP \\ +REprintf(" RCPP_XP_METHOD_VOID_%d is deprecated, it will be removed permanently in july 2014\\n" ) ; \\ ::Rcpp::XPtr< __CLASS__ > ptr(xp) ; \\ ptr->__METHOD__( %s ) ; \\ END_RCPP \\ @@ -192,6 +162,7 @@ i, i, if( i == 0 ) "" else paste( ", ", paste( sprintf( "SEXP x%d", 0:(i-1) ), collapse = ", " ) ), + i, if( i == 0 ) "" else paste( sprintf( "::Rcpp::internal::converter( x%d )", 0:(i-1)), collapse=", ") ) @@ -203,7 +174,7 @@ // :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: // preprocessor_generated.h: Rcpp R/C++ interface class library -- pre processor help // -// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -246,5 +217,5 @@ #endif " ) -writeLines( res, "Rcpp/inst/include/Rcpp/preprocessor_generated.h" ) +writeLines( res, "Rcpp/inst/include/Rcpp/macros/preprocessor_generated.h" ) From noreply at r-forge.r-project.org Tue Jun 25 11:49:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Jun 2013 11:49:56 +0200 (CEST) Subject: [Rcpp-commits] r4373 - in pkg/Rcpp: . inst inst/include/Rcpp/macros inst/unitTests src Message-ID: <20130625094956.439B4183B43@r-forge.r-project.org> Author: romain Date: 2013-06-25 11:49:54 +0200 (Tue, 25 Jun 2013) New Revision: 4373 Removed: pkg/Rcpp/inst/unitTests/runit.macros.R Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/DESCRIPTION pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/inst/include/Rcpp/macros/preprocessor_generated.h pkg/Rcpp/src/Module.cpp Log: deprecating RCPP_FUNCTION ... macros Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-25 08:04:35 UTC (rev 4372) +++ pkg/Rcpp/ChangeLog 2013-06-25 09:49:54 UTC (rev 4373) @@ -1,3 +1,10 @@ +2013-06-25 Romain Francois + + * DESCRIPTION : devel version 0.10.4.1 + * src/Module.cpp : bring a simplified version of RCPP_FUNCTION 1 .. 4 + * unitTests/runit.macros.R : removed, as RCPP_FUNCTION ... are deprecated + * include/Rcpp/macros/preprocessor_generated.h : deprecating RCPP_FUNCTION_... macros + 2013-06-24 Dirk Eddelbuettel * inst/include/Rcpp/platform/compiler.h: Note the useful wiki page Modified: pkg/Rcpp/DESCRIPTION =================================================================== --- pkg/Rcpp/DESCRIPTION 2013-06-25 08:04:35 UTC (rev 4372) +++ pkg/Rcpp/DESCRIPTION 2013-06-25 09:49:54 UTC (rev 4373) @@ -1,6 +1,6 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 0.10.4 +Version: 0.10.4.1 Date: $Date$ Author: Dirk Eddelbuettel and Romain Francois, with contributions by Douglas Bates, John Chambers and JJ Allaire Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-25 08:04:35 UTC (rev 4372) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-25 09:49:54 UTC (rev 4373) @@ -2,6 +2,20 @@ \title{News for Package 'Rcpp'} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} + \section{Changes in Rcpp version 0.10.5 (future)}{ + \item Deprecation of \code{RCPP_FUNCTION_*}: + \itemize{ + \item The macros from the \code{preprocessor_generated.h} + file have been deprecated. They are still available, but they print a message + in addition to their expected behavior. + \item The macros will be permanently removed in the first \pkg{Rcpp} + release after july 2014. + \item Users of these macros (if there are any) should start replacing them + with more up to date code, such as using Rcpp attributes or Rcpp + modules. + } + } + \section{Changes in Rcpp version 0.10.4 (2013-06-23)}{ \itemize{ \item Changes in R code: None beyond those detailed for Rcpp Attributes Modified: pkg/Rcpp/inst/include/Rcpp/macros/preprocessor_generated.h =================================================================== --- pkg/Rcpp/inst/include/Rcpp/macros/preprocessor_generated.h 2013-06-25 08:04:35 UTC (rev 4372) +++ pkg/Rcpp/inst/include/Rcpp/macros/preprocessor_generated.h 2013-06-25 09:49:54 UTC (rev 4373) @@ -2,7 +2,7 @@ // :tabSize=4:indentSize=4:noTabs=true:folding=explicit:collapseFolds=1: // preprocessor_generated.h: Rcpp R/C++ interface class library -- pre processor help // -// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois // // This file is part of Rcpp. // @@ -41,6 +41,7 @@ extern "C" SEXP __NAME__(){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_0 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)() ) ; \ return res ; \ END_RCPP \ @@ -63,6 +64,7 @@ extern "C" SEXP __NAME__(SEXP x0){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_1 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 )) ) ; \ return res ; \ END_RCPP \ @@ -85,6 +87,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_2 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 )) ) ; \ return res ; \ END_RCPP \ @@ -107,6 +110,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_3 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 )) ) ; \ return res ; \ END_RCPP \ @@ -129,6 +133,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_4 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 )) ) ; \ return res ; \ END_RCPP \ @@ -151,6 +156,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_5 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 )) ) ; \ return res ; \ END_RCPP \ @@ -173,6 +179,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_6 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 )) ) ; \ return res ; \ END_RCPP \ @@ -195,6 +202,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_7 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 )) ) ; \ return res ; \ END_RCPP \ @@ -217,6 +225,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_8 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 )) ) ; \ return res ; \ END_RCPP \ @@ -239,6 +248,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_9 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 )) ) ; \ return res ; \ END_RCPP \ @@ -261,6 +271,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_10 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 )) ) ; \ return res ; \ END_RCPP \ @@ -283,6 +294,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_11 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 )) ) ; \ return res ; \ END_RCPP \ @@ -305,6 +317,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_12 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 )) ) ; \ return res ; \ END_RCPP \ @@ -327,6 +340,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_13 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 )) ) ; \ return res ; \ END_RCPP \ @@ -349,6 +363,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_14 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 )) ) ; \ return res ; \ END_RCPP \ @@ -371,6 +386,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_15 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 )) ) ; \ return res ; \ END_RCPP \ @@ -393,6 +409,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_16 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 )) ) ; \ return res ; \ END_RCPP \ @@ -415,6 +432,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_17 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 )) ) ; \ return res ; \ END_RCPP \ @@ -437,6 +455,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_18 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 )) ) ; \ return res ; \ END_RCPP \ @@ -459,6 +478,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_19 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 )) ) ; \ return res ; \ END_RCPP \ @@ -481,6 +501,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_20 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 )) ) ; \ return res ; \ END_RCPP \ @@ -503,6 +524,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_21 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 )) ) ; \ return res ; \ END_RCPP \ @@ -525,6 +547,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_22 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 )) ) ; \ return res ; \ END_RCPP \ @@ -547,6 +570,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_23 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 ), ::Rcpp::internal::converter( x22 )) ) ; \ return res ; \ END_RCPP \ @@ -569,6 +593,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22, SEXP x23){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_24 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 ), ::Rcpp::internal::converter( x22 ), ::Rcpp::internal::converter( x23 )) ) ; \ return res ; \ END_RCPP \ @@ -591,6 +616,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22, SEXP x23, SEXP x24){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_25 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 ), ::Rcpp::internal::converter( x22 ), ::Rcpp::internal::converter( x23 ), ::Rcpp::internal::converter( x24 )) ) ; \ return res ; \ END_RCPP \ @@ -613,6 +639,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22, SEXP x23, SEXP x24, SEXP x25){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_26 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 ), ::Rcpp::internal::converter( x22 ), ::Rcpp::internal::converter( x23 ), ::Rcpp::internal::converter( x24 ), ::Rcpp::internal::converter( x25 )) ) ; \ return res ; \ END_RCPP \ @@ -635,6 +662,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22, SEXP x23, SEXP x24, SEXP x25, SEXP x26){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_27 is deprecated, it will be removed permanently in july 2014\n" ) ; \ res = ::Rcpp::wrap( RCPP_DECORATE(__NAME__)(::Rcpp::internal::converter( x0 ), ::Rcpp::internal::converter( x1 ), ::Rcpp::internal::converter( x2 ), ::Rcpp::internal::converter( x3 ), ::Rcpp::internal::converter( x4 ), ::Rcpp::internal::converter( x5 ), ::Rcpp::internal::converter( x6 ), ::Rcpp::internal::converter( x7 ), ::Rcpp::internal::converter( x8 ), ::Rcpp::internal::converter( x9 ), ::Rcpp::internal::converter( x10 ), ::Rcpp::internal::converter( x11 ), ::Rcpp::internal::converter( x12 ), ::Rcpp::internal::converter( x13 ), ::Rcpp::internal::converter( x14 ), ::Rcpp::internal::converter( x15 ), ::Rcpp::internal::converter( x16 ), ::Rcpp::internal::converter( x17 ), ::Rcpp::internal::converter( x18 ), ::Rcpp::internal::converter( x19 ), ::Rcpp::internal::converter( x20 ), ::Rcpp::internal::converter( x21 ), ::Rcpp::internal::converter( x22 ), ::Rcpp::internal::converter( x23 ), ::Rcpp::internal::converter( x24 ), ::Rcpp::internal::converter( x25 ), ::Rcpp::internal::converter( x26 )) ) ; \ return res ; \ END_RCPP \ @@ -657,6 +685,7 @@ extern "C" SEXP __NAME__(SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, SEXP x6, SEXP x7, SEXP x8, SEXP x9, SEXP x10, SEXP x11, SEXP x12, SEXP x13, SEXP x14, SEXP x15, SEXP x16, SEXP x17, SEXP x18, SEXP x19, SEXP x20, SEXP x21, SEXP x22, SEXP x23, SEXP x24, SEXP x25, SEXP x26, SEXP x27){ \ SEXP res = R_NilValue ; \ BEGIN_RCPP \ +REprintf(" RCPP_FUNCTION_28 is deprecated, it will be removed permanently in july 2014\n" ) ; \ [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rcpp -r 4373 From noreply at r-forge.r-project.org Tue Jun 25 15:47:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 25 Jun 2013 15:47:07 +0200 (CEST) Subject: [Rcpp-commits] r4374 - in pkg/Rcpp: . inst src Message-ID: <20130625134707.206491855AC@r-forge.r-project.org> Author: edd Date: 2013-06-25 15:47:06 +0200 (Tue, 25 Jun 2013) New Revision: 4374 Modified: pkg/Rcpp/ChangeLog pkg/Rcpp/inst/NEWS.Rd pkg/Rcpp/src/api.cpp Log: added test for #define(__sun) around use of backtrace() Modified: pkg/Rcpp/ChangeLog =================================================================== --- pkg/Rcpp/ChangeLog 2013-06-25 09:49:54 UTC (rev 4373) +++ pkg/Rcpp/ChangeLog 2013-06-25 13:47:06 UTC (rev 4374) @@ -1,5 +1,10 @@ -2013-06-25 Romain Francois +2013-06-25 Dirk Eddelbuettel + * src/api.cpp: Also test for #defined(__sun) when checking for system + lacking a valid backtrace() function for stack traces + +2013-06-25 Romain Francois + * DESCRIPTION : devel version 0.10.4.1 * src/Module.cpp : bring a simplified version of RCPP_FUNCTION 1 .. 4 * unitTests/runit.macros.R : removed, as RCPP_FUNCTION ... are deprecated Modified: pkg/Rcpp/inst/NEWS.Rd =================================================================== --- pkg/Rcpp/inst/NEWS.Rd 2013-06-25 09:49:54 UTC (rev 4373) +++ pkg/Rcpp/inst/NEWS.Rd 2013-06-25 13:47:06 UTC (rev 4374) @@ -3,8 +3,17 @@ \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} \section{Changes in Rcpp version 0.10.5 (future)}{ - \item Deprecation of \code{RCPP_FUNCTION_*}: + \itemize{ + + \item Changes in Rcpp API: \itemize{ + \item Add \code{#defined(__sun)} to lists of operating systems to + test for when checking for lack of \code{backtrace()} needed for + stack traces. + } + + \item Deprecation of \code{RCPP_FUNCTION_*}: + \itemize{ \item The macros from the \code{preprocessor_generated.h} file have been deprecated. They are still available, but they print a message in addition to their expected behavior. Modified: pkg/Rcpp/src/api.cpp =================================================================== --- pkg/Rcpp/src/api.cpp 2013-06-25 09:49:54 UTC (rev 4373) +++ pkg/Rcpp/src/api.cpp 2013-06-25 13:47:06 UTC (rev 4374) @@ -1533,7 +1533,7 @@ } #if defined(__GNUC__) -#if defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) +#if defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__sun) // Simpler version for Windows and *BSD SEXP stack_trace( const char* file, int line ){ Rcpp::List trace = Rcpp::List::create( @@ -1543,7 +1543,7 @@ trace.attr("class") = "Rcpp_stack_trace" ; return trace ; } -#else // ! (defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) +#else // ! (defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__sun) #include #include From noreply at r-forge.r-project.org Thu Jun 27 04:33:21 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 27 Jun 2013 04:33:21 +0200 (CEST) Subject: [Rcpp-commits] r4375 - in pkg/RcppXts: . inst src tests Message-ID: <20130627023321.83617185307@r-forge.r-project.org> Author: edd Date: 2013-06-27 04:33:20 +0200 (Thu, 27 Jun 2013) New Revision: 4375 Modified: pkg/RcppXts/ChangeLog pkg/RcppXts/inst/NEWS.Rd pkg/RcppXts/src/xtsMod.cpp pkg/RcppXts/tests/checks.R Log: * src/xtsMod.cpp: Added a more functions now that xts 0.9-5 is on CRAN * tests/check.R: Added some illustrations / tests as well Modified: pkg/RcppXts/ChangeLog =================================================================== --- pkg/RcppXts/ChangeLog 2013-06-25 13:47:06 UTC (rev 4374) +++ pkg/RcppXts/ChangeLog 2013-06-27 02:33:20 UTC (rev 4375) @@ -1,3 +1,8 @@ +2013-06-26 Dirk Eddelbuettel + + * src/xtsMod.cpp: Added a more functions now that xts 0.9-5 is on CRAN + * tests/check.R: Added some illustrations / tests as well + 2013-01-18 Dirk Eddelbuettel * DESCRIPTION (Version): 0.0.4 Modified: pkg/RcppXts/inst/NEWS.Rd =================================================================== --- pkg/RcppXts/inst/NEWS.Rd 2013-06-25 13:47:06 UTC (rev 4374) +++ pkg/RcppXts/inst/NEWS.Rd 2013-06-27 02:33:20 UTC (rev 4375) @@ -2,9 +2,16 @@ \title{News for Package \pkg{RcppXts}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} +\section{Changes in version 0.0.5 (2013-xx-yy)}{ + \itemize{ + \item Depends on \cpkg{xts} 0.9-5 now on CRAN + \item Exports a number of additional functions + } +} + \section{Changes in version 0.0.4 (2013-01-18)}{ \itemize{ - \item Depends on (unreleased) \cpkg{xts} 0.9-2 now on CRAN + \item Depends on \cpkg{xts} 0.9-2 now on CRAN } } Modified: pkg/RcppXts/src/xtsMod.cpp =================================================================== --- pkg/RcppXts/src/xtsMod.cpp 2013-06-25 13:47:06 UTC (rev 4374) +++ pkg/RcppXts/src/xtsMod.cpp 2013-06-27 02:33:20 UTC (rev 4375) @@ -70,4 +70,37 @@ List::create(Named("x"), Named("k"), Named("pad")), "Extract the coredata from xts object"); + function("xtsMakeIndexUnique", + &xtsMakeIndexUnique, + List::create(Named("x"), Named("eps")), + "Make the POSIXt index unique by separating by 'eps'"); + + function("xtsMakeUnique", + &xtsMakeIndexUnique, + List::create(Named("x"), Named("eps")), + "Make the POSIXt index unique by separating by 'eps'"); + + function("xtsEndpoints", + &xtsEndpoints, + List::create(Named("x"), Named("on"), Named("k"), Named("addlast")), + "Create a series of end points given a time index"); + + function("xtsMerge", + &xtsMerge, + List::create(Named("x"), Named("y"), Named("all"), Named("fill"), Named("retclass"), + Named("colnames"), Named("suffixes"), Named("retside"), + Named("env"), Named("coerce")), + "Merge two series"); + + function("xtsNaOmit", + &xtsNaOmit, + List::create(Named("x")), + "Omit NA values"); + + // -- this requires xts 0.9-6 or later (fixed in SVN) + // function("xtsNaLocf", + // &xtsNaLocf, + // List::create(Named("x"), Named("fromLast"), Named("maxgap"), Named("limit")), + // "Fill NA values by carrying last observation forward"); + } Modified: pkg/RcppXts/tests/checks.R =================================================================== --- pkg/RcppXts/tests/checks.R 2013-06-25 13:47:06 UTC (rev 4374) +++ pkg/RcppXts/tests/checks.R 2013-06-27 02:33:20 UTC (rev 4375) @@ -1,6 +1,8 @@ library(RcppXts) +options("digits.secs"=6) + X <- xts(1:4, order.by=Sys.time()+0:3) X2 <- xts(1:4, order.by=Sys.time()+4:7) @@ -13,4 +15,30 @@ xtsRbind(X, X2, FALSE) xtsRbind(X, X, TRUE) xtsNaCheck(X) -xtsLag(X, 2L, TRUE) +Y <- X +xtsLag(Y, 2L, TRUE) + +Y <- X +index(Y)[2] <- index(Y)[3] +Y +xtsMakeIndexUnique(Y, 0.001) + +Y <- X +index(Y)[2] <- index(Y)[3] +xtsMakeUnique(Y, 0.5) + +X <- xts(1:20, order.by=Sys.time()+(0:19)*60) +xtsEndpoints(index(X), 60L, 4, TRUE) # every fourth minute, incl last +xtsEndpoints(index(X), 60L, 4, FALSE) # every fourth minute + +xtsMerge(X, X2, c(TRUE,TRUE), TRUE, TRUE, "a", "b", TRUE, new.env(), 0) + +Y2 <- Y +Y2[2] <- NA +xtsNaOmit(Y2) + +## -- requires xts 0.9-6 (fixed in SVN) +## Y2 <- X2 +## Y2[3] <- NA +## Y2 +## xtsNaLocf(Y2, FALSE, 1, Inf) From noreply at r-forge.r-project.org Sun Jun 30 22:12:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 30 Jun 2013 22:12:33 +0200 (CEST) Subject: [Rcpp-commits] r4376 - in pkg/Rcpp/inst/unitTests: . cpp Message-ID: <20130630201233.7F9741859DE@r-forge.r-project.org> Author: romain Date: 2013-06-30 22:12:33 +0200 (Sun, 30 Jun 2013) New Revision: 4376 Added: pkg/Rcpp/inst/unitTests/cpp/as.cpp Modified: pkg/Rcpp/inst/unitTests/runit.as.R Log: using sourceCpp Added: pkg/Rcpp/inst/unitTests/cpp/as.cpp =================================================================== --- pkg/Rcpp/inst/unitTests/cpp/as.cpp (rev 0) +++ pkg/Rcpp/inst/unitTests/cpp/as.cpp 2013-06-30 20:12:33 UTC (rev 4376) @@ -0,0 +1,60 @@ +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- +// +// as.cpp: Rcpp R/C++ interface class library -- as<> unit tests +// +// Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois +// +// This file is part of Rcpp. +// +// Rcpp is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Rcpp is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Rcpp. If not, see . + +#include +using namespace Rcpp ; + +// [[Rcpp::export]] +int as_int( SEXP x){ return as( x ); } + +// [[Rcpp::export]] +double as_double( SEXP x){ return as( x ); } + +// [[Rcpp::export]] +Rbyte as_Rbyte( SEXP x){ return as( x ); } + +// [[Rcpp::export]] +bool as_bool( SEXP x){ return as( x ); } + +// [[Rcpp::export]] +std::string as_string( SEXP x){ return as( x ); } + +// [[Rcpp::export]] +std::vector as_vector_int( SEXP x){ return as< std::vector >(x) ; } + +// [[Rcpp::export]] +std::vector as_vector_double( SEXP x){ return as< std::vector >(x) ; } + +// [[Rcpp::export]] +std::vector as_vector_raw( SEXP x){ return as< std::vector >(x) ; } + +// [[Rcpp::export]] +std::vector as_vector_bool( SEXP x){ return as< std::vector >(x) ; } + +// [[Rcpp::export]] +std::vector as_vector_string( SEXP x){ return as< std::vector >(x) ; } + +// [[Rcpp::export]] +std::deque as_deque_int( SEXP x){ return as< std::deque >(x) ; } + +// [[Rcpp::export]] +std::list as_list_int( SEXP x){ return as< std::list >(x) ; } + Modified: pkg/Rcpp/inst/unitTests/runit.as.R =================================================================== --- pkg/Rcpp/inst/unitTests/runit.as.R 2013-06-27 02:33:20 UTC (rev 4375) +++ pkg/Rcpp/inst/unitTests/runit.as.R 2013-06-30 20:12:33 UTC (rev 4376) @@ -1,6 +1,6 @@ #!/usr/bin/r -t # -# Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois +# Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois # # This file is part of Rcpp. # @@ -21,160 +21,82 @@ if (.runThisTest) { -definitions <- function() { - list("as_int"=list( - signature(x="numeric"), - 'int y = as(x); - return wrap(y) ;') - - ,"as_double"=list( - signature(x="numeric"), - 'double y = as(x) ; - return wrap(y) ;') - - ,"as_raw"=list( - signature(x="numeric"), - 'Rbyte y = as(x) ; - return wrap(y) ;') - - ,"as_bool"=list( - signature(x="numeric"), - 'bool y = as(x) ; - return wrap(y) ;') - - ,"as_string"=list( - signature(x="character"), - 'std::string y = as(x) ; - return wrap(y) ;') - - ,"as_vector_int"=list( - signature(x="numeric"), - 'vector y = as< vector >(x) ; - return wrap(y) ;') - - ,"as_vector_double"=list( - signature(x="numeric"), - 'vector y = as< vector >(x) ; - return wrap(y) ;') - - ,"as_vector_raw"=list( - signature(x="numeric"), - 'vector y = as< vector >(x) ; - return wrap(y) ;') - - ,"as_vector_bool"=list( - signature(x="numeric"), - 'vector y = as< vector >(x) ; - return wrap(y) ;') - - ,"as_vector_string"=list( - signature(x="character"), - 'vector y = as< vector >(x) ; - return wrap(y) ;') - - ,"as_deque_int"=list( - signature(x="integer"), - 'deque y = as< deque >(x) ; - return wrap( accumulate( y.begin(), y.end(), 0.0 ) ) ;') - - ,"as_list_int"=list( - signature(x="integer"), - 'list y = as< list >(x) ; - return wrap( accumulate( y.begin(), y.end(), 0.0 ) ) ;') - ) -} .setUp <- function() { - tests <- ".rcpp.as" - if( ! exists( tests, globalenv() )) { - fun <- Rcpp:::compile_unit_tests(definitions()) - assign( tests, fun, globalenv() ) - } + sourceCpp(file.path(pathRcppTests, "cpp/as.cpp")) } test.as.int <- function(){ - fun <- .rcpp.as$as_int - checkEquals( fun(10), 10L, msg = "as( REALSXP ) " ) - checkEquals( fun(10L), 10L, msg = "as( INTSXP ) " ) - checkEquals( fun(as.raw(10L)), 10L, msg = "as( RAWSXP ) " ) - checkEquals( fun(TRUE), 1L, msg = "as( LGLSXP ) " ) + checkEquals( as_int(10), 10L, msg = "as( REALSXP ) " ) + checkEquals( as_int(10L), 10L, msg = "as( INTSXP ) " ) + checkEquals( as_int(as.raw(10L)), 10L, msg = "as( RAWSXP ) " ) + checkEquals( as_int(TRUE), 1L, msg = "as( LGLSXP ) " ) } test.as.double <- function(){ - fun <- .rcpp.as$as_double - checkEquals( fun(10), 10.0, msg = "as( REALSXP ) " ) - checkEquals( fun(10L), 10.0, msg = "as( INTSXP ) " ) - checkEquals( fun(as.raw(10L)), 10.0, msg = "as( RAWSXP ) " ) - checkEquals( fun(TRUE), 1.0, msg = "as( LGLSXP ) " ) + checkEquals( as_double(10), 10.0, msg = "as( REALSXP ) " ) + checkEquals( as_double(10L), 10.0, msg = "as( INTSXP ) " ) + checkEquals( as_double(as.raw(10L)), 10.0, msg = "as( RAWSXP ) " ) + checkEquals( as_double(TRUE), 1.0, msg = "as( LGLSXP ) " ) } test.as.raw <- function(){ - fun <- .rcpp.as$as_raw - checkEquals( fun(10), as.raw(10), msg = "as( REALSXP ) " ) - checkEquals( fun(10L), as.raw(10), msg = "as( INTSXP ) " ) - checkEquals( fun(as.raw(10L)), as.raw(10), msg = "as( RAWSXP ) " ) - checkEquals( fun(TRUE), as.raw(1), msg = "as( LGLSXP ) " ) + checkEquals( as_raw(10), as.raw(10), msg = "as( REALSXP ) " ) + checkEquals( as_raw(10L), as.raw(10), msg = "as( INTSXP ) " ) + checkEquals( as_raw(as.raw(10L)), as.raw(10), msg = "as( RAWSXP ) " ) + checkEquals( as_raw(TRUE), as.raw(1), msg = "as( LGLSXP ) " ) } test.as.bool <- function(){ - fun <- .rcpp.as$as_bool - checkEquals( fun(10), as.logical(10), msg = "as( REALSXP ) " ) - checkEquals( fun(10L), as.logical(10), msg = "as( INTSXP ) " ) - checkEquals( fun(as.raw(10L)), as.logical(10), msg = "as( RAWSXP ) " ) - checkEquals( fun(TRUE), as.logical(1), msg = "as( LGLSXP ) " ) + checkEquals( as_bool(10), as.logical(10), msg = "as( REALSXP ) " ) + checkEquals( as_bool(10L), as.logical(10), msg = "as( INTSXP ) " ) + checkEquals( as_bool(as.raw(10L)), as.logical(10), msg = "as( RAWSXP ) " ) + checkEquals( as_bool(TRUE), as.logical(1), msg = "as( LGLSXP ) " ) } test.as.string <- function(){ - fun <- .rcpp.as$as_string - checkEquals( fun("foo"), "foo", msg = "as( STRSXP ) " ) + checkEquals( as_string("foo"), "foo", msg = "as( STRSXP ) " ) } test.as.vector.int <- function(){ - fun <- .rcpp.as$as_vector_int - checkEquals( fun(1:10), 1:10 , msg = "as>( INTSXP ) " ) - checkEquals( fun(as.numeric(1:10)), 1:10 , msg = "as>( REALSXP ) " ) - checkEquals( fun(as.raw(1:10)), 1:10 , msg = "as>( RAWSXP ) " ) - checkEquals( fun(c(TRUE,FALSE)), 1:0 , msg = "as>( LGLSXP ) " ) + checkEquals( as_vector_int(1:10), 1:10 , msg = "as>( INTSXP ) " ) + checkEquals( as_vector_int(as.numeric(1:10)), 1:10 , msg = "as>( REALSXP ) " ) + checkEquals( as_vector_int(as.raw(1:10)), 1:10 , msg = "as>( RAWSXP ) " ) + checkEquals( as_vector_int(c(TRUE,FALSE)), 1:0 , msg = "as>( LGLSXP ) " ) } test.as.vector.double <- function(){ - fun <- .rcpp.as$as_vector_double - checkEquals( fun(1:10), as.numeric(1:10) , msg = "as>( INTSXP ) " ) - checkEquals( fun(as.numeric(1:10)), as.numeric(1:10) , msg = "as>( REALSXP ) " ) - checkEquals( fun(as.raw(1:10)), as.numeric(1:10), msg = "as>( RAWSXP ) " ) - checkEquals( fun(c(TRUE,FALSE)), c(1.0, 0.0) , msg = "as>( LGLSXP ) " ) + checkEquals( as_vector_double(1:10), as.numeric(1:10) , msg = "as>( INTSXP ) " ) + checkEquals( as_vector_double(as.numeric(1:10)), as.numeric(1:10) , msg = "as>( REALSXP ) " ) + checkEquals( as_vector_double(as.raw(1:10)), as.numeric(1:10), msg = "as>( RAWSXP ) " ) + checkEquals( as_vector_double(c(TRUE,FALSE)), c(1.0, 0.0) , msg = "as>( LGLSXP ) " ) } test.as.vector.raw <- function(){ - fun <- .rcpp.as$as_vector_raw - checkEquals( fun(1:10), as.raw(1:10) , msg = "as>( INTSXP ) " ) - checkEquals( fun(as.numeric(1:10)), as.raw(1:10) , msg = "as>( REALSXP ) " ) - checkEquals( fun(as.raw(1:10)), as.raw(1:10) , msg = "as>( RAWSXP ) " ) - checkEquals( fun(c(TRUE,FALSE)), as.raw(1:0) , msg = "as>( LGLSXP ) " ) + checkEquals( as_vector_raw(1:10), as.raw(1:10) , msg = "as>( INTSXP ) " ) + checkEquals( as_vector_raw(as.numeric(1:10)), as.raw(1:10) , msg = "as>( REALSXP ) " ) + checkEquals( as_vector_raw(as.raw(1:10)), as.raw(1:10) , msg = "as>( RAWSXP ) " ) + checkEquals( as_vector_raw(c(TRUE,FALSE)), as.raw(1:0) , msg = "as>( LGLSXP ) " ) } test.as.vector.bool <- function(){ - fun <- .rcpp.as$as_vector_bool - checkEquals( fun(0:10), as.logical(0:10) , msg = "as>( INTSXP ) " ) - checkEquals( fun(as.numeric(0:10)), as.logical(0:10) , msg = "as>( REALSXP ) " ) - checkEquals( fun(as.raw(0:10)), as.logical(0:10) , msg = "as>( RAWSXP ) " ) - checkEquals( fun(c(TRUE,FALSE)), as.logical(1:0) , msg = "as>( LGLSXP ) " ) + checkEquals( as_vector_bool(0:10), as.logical(0:10) , msg = "as>( INTSXP ) " ) + checkEquals( as_vector_bool(as.numeric(0:10)), as.logical(0:10) , msg = "as>( REALSXP ) " ) + checkEquals( as_vector_bool(as.raw(0:10)), as.logical(0:10) , msg = "as>( RAWSXP ) " ) + checkEquals( as_vector_bool(c(TRUE,FALSE)), as.logical(1:0) , msg = "as>( LGLSXP ) " ) } test.as.vector.string <- function(){ - fun <- .rcpp.as$as_vector_string - checkEquals( fun(letters), letters , msg = "as>( STRSXP ) " ) + checkEquals( as_vector_string(letters), letters , msg = "as>( STRSXP ) " ) } test.as.deque.int <- function(){ - fun <- .rcpp.as$as_deque_int - checkEquals( fun(1:10), sum(1:10) , msg = "as>( INTSXP ) " ) + checkEquals( as_deque_int(1:10), 1:10 , msg = "as>( INTSXP ) " ) } test.as.list.int <- function(){ - fun <- .rcpp.as$as_list_int - checkEquals( fun(1:10), sum(1:10) , msg = "as>( INTSXP ) " ) + checkEquals( as_list_int(1:10), 1:10 , msg = "as>( INTSXP ) " ) } }