[Rinside-commits] r239 - in pkg: . inst/examples inst/examples/armadillo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 11 01:41:30 CEST 2012
Author: edd
Date: 2012-08-11 01:41:30 +0200 (Sat, 11 Aug 2012)
New Revision: 239
Added:
pkg/inst/examples/armadillo/
pkg/inst/examples/armadillo/Makefile
pkg/inst/examples/armadillo/rinside_arma0.cpp
pkg/inst/examples/armadillo/rinside_arma1.cpp
Modified:
pkg/ChangeLog
Log:
new examples using Armadillo
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2012-05-02 23:57:55 UTC (rev 238)
+++ pkg/ChangeLog 2012-08-10 23:41:30 UTC (rev 239)
@@ -1,3 +1,9 @@
+2012-08-10 Dirk Eddelbuettel <edd at dexter>
+
+ * inst/examples/armadillo/: New example directory for Armadillo
+ * inst/examples/armadillo/rinside_arma0.cpp: simple first example
+ * inst/examples/armadillo/rinside_arma1.cpp: second example
+
2012-04-08 Dirk Eddelbuettel <edd at debian.org>
* inst/examples/standard/rinside_sample12.cpp: New example
Added: pkg/inst/examples/armadillo/Makefile
===================================================================
--- pkg/inst/examples/armadillo/Makefile (rev 0)
+++ pkg/inst/examples/armadillo/Makefile 2012-08-10 23:41:30 UTC (rev 239)
@@ -0,0 +1,51 @@
+## -*- mode: make; tab-width: 8; -*-
+##
+## Simple Makefile
+
+## comment this out if you need a different version of R,
+## and set set R_HOME accordingly as an environment variable
+R_HOME := $(shell R RHOME)
+
+sources := $(wildcard *.cpp)
+programs := $(sources:.cpp=)
+
+
+## include headers and libraries for R
+RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
+RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
+RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
+RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
+
+## if you need to set an rpath to R itself, also uncomment
+#RRPATH := -Wl,-rpath,$(R_HOME)/lib
+
+## include headers and libraries for Rcpp interface classes
+RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+
+## include headers and libraries for RInside embedding classes
+RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+## RcppArmadillo header
+RCPPARMAINCL := $(shell echo 'RcppArmadillo:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+## compiler etc settings used in default make rules
+CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
+CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
+CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RCPPARMAINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
+LDLIBS := $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
+
+all: $(programs)
+ @test -x /usr/bin/strip && strip $^
+
+run: $(programs)
+ @for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done
+
+clean:
+ rm -vf $(programs)
+ rm -vrf *.dSYM
+
+runAll:
+ for p in $(programs); do echo "Running $$p"; ./$$p; done
Added: pkg/inst/examples/armadillo/rinside_arma0.cpp
===================================================================
--- pkg/inst/examples/armadillo/rinside_arma0.cpp (rev 0)
+++ pkg/inst/examples/armadillo/rinside_arma0.cpp 2012-08-10 23:41:30 UTC (rev 239)
@@ -0,0 +1,21 @@
+// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Simple example using Armadillo classes
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h> // for the embedded R via RInside
+#include <RcppArmadillo.h>
+
+int main(int argc, char *argv[]) {
+
+ RInside R(argc, argv); // create an embedded R instance
+
+ std::string cmd = "diag(3)"; // create a Matrix in r
+
+ arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
+
+ std::cout << m << std::endl; // and use Armadillo i/o
+
+ exit(0);
+}
Added: pkg/inst/examples/armadillo/rinside_arma1.cpp
===================================================================
--- pkg/inst/examples/armadillo/rinside_arma1.cpp (rev 0)
+++ pkg/inst/examples/armadillo/rinside_arma1.cpp 2012-08-10 23:41:30 UTC (rev 239)
@@ -0,0 +1,28 @@
+// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Simple example using Armadillo on matrix data generated in R
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h> // for the embedded R via RInside
+#include <RcppArmadillo.h>
+
+int main(int argc, char *argv[]) {
+
+ RInside R(argc, argv); // create an embedded R instance
+
+ std::string cmd = "set.seed(42); matrix(rnorm(9),3,3)"; // create a random Matrix in r
+
+ arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
+ arma::mat n = m.t() * m;
+ double nacc = arma::accu(n);
+ double nrnk = arma::rank(n);
+
+ m.print("Initial Matrix n"); // initial random matrix
+ n.print("Product n' * n"); // product of m' * m
+ std::cout << "accu(n) " << nacc << " "
+ << "rank(n) " << nrnk << std::endl; // accu() and rank()
+
+ exit(0);
+}
+
More information about the Rinside-commits
mailing list