[Rcpp-commits] r2569 - in pkg/RcppGSL: . inst inst/examples inst/examples/RcppGSLExample inst/examples/RcppGSLExample/R inst/examples/RcppGSLExample/man inst/examples/RcppGSLExample/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Nov 28 22:12:19 CET 2010
Author: edd
Date: 2010-11-28 22:12:19 +0100 (Sun, 28 Nov 2010)
New Revision: 2569
Added:
pkg/RcppGSL/inst/examples/
pkg/RcppGSL/inst/examples/RcppGSLExample/
pkg/RcppGSL/inst/examples/RcppGSLExample/DESCRIPTION
pkg/RcppGSL/inst/examples/RcppGSLExample/NAMESPACE
pkg/RcppGSL/inst/examples/RcppGSLExample/R/
pkg/RcppGSL/inst/examples/RcppGSLExample/R/colNorm.R
pkg/RcppGSL/inst/examples/RcppGSLExample/man/
pkg/RcppGSL/inst/examples/RcppGSLExample/man/colNorm.Rd
pkg/RcppGSL/inst/examples/RcppGSLExample/src/
pkg/RcppGSL/inst/examples/RcppGSLExample/src/Makevars
pkg/RcppGSL/inst/examples/RcppGSLExample/src/colNorm.cpp
Modified:
pkg/RcppGSL/ChangeLog
Log:
adding a simple example package
Modified: pkg/RcppGSL/ChangeLog
===================================================================
--- pkg/RcppGSL/ChangeLog 2010-11-28 20:10:24 UTC (rev 2568)
+++ pkg/RcppGSL/ChangeLog 2010-11-28 21:12:19 UTC (rev 2569)
@@ -1,3 +1,10 @@
+2010-11-28 Dirk Eddelbuettel <edd at debian.org>
+
+ * inst/examples/RcppGSLExample/: Started as a simple example of using
+ RcppGSL in a user package
+
+ * NEWS: Added with initial notes towards a release
+
2010-11-27 Romain Francois <romain at r-enthusiasts.com>
* include/include/*h: Updated to satisfy some grumblings from g++
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/DESCRIPTION
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/DESCRIPTION (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/DESCRIPTION 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,11 @@
+Package: RcppGSLExample
+Title: A really simple example of using RcppGSL in a package
+Version: 0.0.1
+Date: $Date$
+Author: Dirk Eddelbuettel and Romain Francois
+Maintainer: Dirk Eddelbuettel and Romain Francois <RomainAndDirk at r-enthusiasts.com>
+Description: Examples for Seamless R, C++ and GSL integration
+Depends: R (>= 2.11.0), Rcpp (>= 0.8.4)
+LinkingTo: Rcpp, RcppGSL
+URL: http://dirk.eddelbuettel.com/code/rcpp.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp
+License: GPL (>= 2)
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/NAMESPACE
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/NAMESPACE (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/NAMESPACE 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,3 @@
+useDynLib(RcppGSLExample)
+
+export(colNorm)
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/R/colNorm.R
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/R/colNorm.R (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/R/colNorm.R 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,24 @@
+## colNorm.R: R wrapper to Rcpp/GSL colNorm implementation
+##
+## Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+##
+## 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 <http://www.gnu.org/licenses/>.
+
+colNorm <- function(M) {
+ stopifnot(is.matrix(M))
+ res <- .Call("colNorm", M, package="RcppGSLExample")
+}
+
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/man/colNorm.Rd
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/man/colNorm.Rd (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/man/colNorm.Rd 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,36 @@
+\name{colNorm}
+\alias{colNorm}
+\title{Column norm of a matrix}
+\description{
+ \code{colNorm} provides a column norm of a matrix to provide an
+ example of using \pkg{RcppGSL} with \code{GNU GSL} library.
+}
+\usage{
+colNorm(M)
+}
+\arguments{
+ \item{M}{a numeric matrix.}
+}
+\details{
+ The column norm of \code{M} is returned.
+
+ This example reprises an example in section 8.4.13 of the GSL
+ reference manual.
+}
+
+\value{
+ \code{colNorm} returns a vector each element of which corresponds to
+ the vector norm of the corresponding column of \code{M}.
+}
+\references{GNU GSL project: \url{http://www.gnu.org/software/gsl}}
+\author{
+ The GNU GSL library is being written by team of authors with the
+ overall development, design and implementation lead by Brian Gough and
+ Gerard Jungman. RcppGSL is written by Romain Francois and Dirk Eddelbuettel.
+}
+\examples{
+ ## see Section 8.4.13 of the GSL manual
+ M <- matrix(sin(0:9), nrow=10, ncol=1) %*% matrix(1, ncol=10) + matrix(1, nrow=10) %*% matrix(cos(0:9), ncol=10)
+ print(colNorm(M))
+}
+
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/src/Makevars
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/src/Makevars (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/src/Makevars 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,8 @@
+## Emacs please make this a -*- mode: Makefile; -*-
+##
+##
+PKG_CXXFLAGS = `gsl-config --cflags`
+##
+## Use the R_HOME indirection to support installations of multiple R version
+PKG_LIBS = `gsl-config --libs-without-cblas` `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" `
+
Added: pkg/RcppGSL/inst/examples/RcppGSLExample/src/colNorm.cpp
===================================================================
--- pkg/RcppGSL/inst/examples/RcppGSLExample/src/colNorm.cpp (rev 0)
+++ pkg/RcppGSL/inst/examples/RcppGSLExample/src/colNorm.cpp 2010-11-28 21:12:19 UTC (rev 2569)
@@ -0,0 +1,54 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// colNorm.cpp: Rcpp and GSL based example of column norm
+// adapted from `Section 8.4.13 Example programs for matrices'
+// of the GSL manual
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+
+#include <RcppGSL.h>
+#include <gsl/gsl_matrix.h>
+#include <gsl/gsl_blas.h>
+
+extern "C" SEXP colNorm(SEXP sM) {
+
+ try {
+
+ RcppGSL::matrix<double> 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<double> colview = gsl_matrix_column (M, j);
+ RcppGSL::vector<double> col2( Rcpp::wrap(colview) ); // ugly !!
+ n[j] = gsl_blas_dnrm2(col2);
+ col2.free(); // even uglier !!
+ }
+ gsl_matrix_free (M);
+ return n; // return vector
+
+ } catch( std::exception &ex ) {
+ forward_exception_to_r( ex );
+
+ } catch(...) {
+ ::Rf_error( "c++ exception (unknown reason)" );
+ }
+ return R_NilValue; // -Wall
+}
+
More information about the Rcpp-commits
mailing list