[Rinside-commits] r242 - in pkg: . inst inst/examples inst/examples/armadillo inst/examples/eigen

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 12 21:59:05 CEST 2012


Author: edd
Date: 2012-08-12 21:59:05 +0200 (Sun, 12 Aug 2012)
New Revision: 242

Added:
   pkg/inst/examples/eigen/
   pkg/inst/examples/eigen/Makefile
   pkg/inst/examples/eigen/rinside_eigen0.cpp
   pkg/inst/examples/eigen/rinside_eigen1.cpp
Modified:
   pkg/ChangeLog
   pkg/inst/NEWS.Rd
   pkg/inst/examples/armadillo/Makefile
   pkg/inst/examples/armadillo/rinside_arma1.cpp
Log:
added Eigen examples which match the Armadillo examples added yesterday


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2012-08-11 00:36:49 UTC (rev 241)
+++ pkg/ChangeLog	2012-08-12 19:59:05 UTC (rev 242)
@@ -1,3 +1,9 @@
+2012-08-12  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/examples/eigen/: New example directory for Eigen
+	* inst/examples/eigen/rinside_eigen0.cpp: simple first example
+	* inst/examples/eigen/rinside_eigen1.cpp: second example
+
 2012-08-10  Dirk Eddelbuettel  <edd at dexter>
 
 	* inst/examples/armadillo/: New example directory for Armadillo

Modified: pkg/inst/NEWS.Rd
===================================================================
--- pkg/inst/NEWS.Rd	2012-08-11 00:36:49 UTC (rev 241)
+++ pkg/inst/NEWS.Rd	2012-08-12 19:59:05 UTC (rev 242)
@@ -6,6 +6,8 @@
   \itemize{
     \item New fifth examples subdirectory 'armadillo' with two new
     examples showing how to combine \cpkg{RInside} with \cpkg{RcppArmadillo}
+    \item New sixth examples subdirectory 'eigen with two new examples
+    showing how to combine \cpkg{RInside} with \cpkg{RcppEigen} 
     \item Prettified the Wt example 'web application' with CSS use, also added
     and XML file with simple headers and description text
     \item New example rinside_sample12 motivated by StackOverflow

Modified: pkg/inst/examples/armadillo/Makefile
===================================================================
--- pkg/inst/examples/armadillo/Makefile	2012-08-11 00:36:49 UTC (rev 241)
+++ pkg/inst/examples/armadillo/Makefile	2012-08-12 19:59:05 UTC (rev 242)
@@ -28,7 +28,7 @@
 RINSIDEINCL := 		$(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
 RINSIDELIBS := 		$(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)
 
-## RcppArmadillo header
+## RcppArmadillo headers
 RCPPARMAINCL :=		$(shell echo 'RcppArmadillo:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)	
 
 ## compiler etc settings used in default make rules

Modified: pkg/inst/examples/armadillo/rinside_arma1.cpp
===================================================================
--- pkg/inst/examples/armadillo/rinside_arma1.cpp	2012-08-11 00:36:49 UTC (rev 241)
+++ pkg/inst/examples/armadillo/rinside_arma1.cpp	2012-08-12 19:59:05 UTC (rev 242)
@@ -18,8 +18,8 @@
     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
+    m.print("Initial Matrix m"); 			// initial random matrix
+    n.print("Product n = m' * m");		 	// product of m' * m
     std::cout << "accu(n) " << nacc << " " 
 	      << "rank(n) " << nrnk << std::endl; 	// accu() and rank()
 

Added: pkg/inst/examples/eigen/Makefile
===================================================================
--- pkg/inst/examples/eigen/Makefile	                        (rev 0)
+++ pkg/inst/examples/eigen/Makefile	2012-08-12 19:59:05 UTC (rev 242)
@@ -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)
+
+## RcppEigen headers
+RCPPEIGENINCL :=	$(shell echo 'cat(paste("-I", system.file("include", package = "RcppEigen"), sep = ""))' | $(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) $(RCPPEIGENINCL) $(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/eigen/rinside_eigen0.cpp
===================================================================
--- pkg/inst/examples/eigen/rinside_eigen0.cpp	                        (rev 0)
+++ pkg/inst/examples/eigen/rinside_eigen0.cpp	2012-08-12 19:59:05 UTC (rev 242)
@@ -0,0 +1,22 @@
+// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Simple example using Eigen classes
+//
+// Copyright (C) 2012  Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h>                    // for the embedded R via RInside
+#include <RcppEigen.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 
+
+    const Eigen::Map<Eigen::MatrixXd>  m = // parse, eval + return result
+      Rcpp::as<Eigen::Map<Eigen::MatrixXd> >(R.parseEval(cmd));
+
+    std::cout << m << std::endl; 	// and use Eigen i/o  
+
+    exit(0);
+}

Added: pkg/inst/examples/eigen/rinside_eigen1.cpp
===================================================================
--- pkg/inst/examples/eigen/rinside_eigen1.cpp	                        (rev 0)
+++ pkg/inst/examples/eigen/rinside_eigen1.cpp	2012-08-12 19:59:05 UTC (rev 242)
@@ -0,0 +1,27 @@
+// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Simple example using Eigen classes on matrix data generated in R
+//
+// Copyright (C) 2012  Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h>                    // for the embedded R via RInside
+#include <RcppEigen.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 
+
+    const Eigen::Map<Eigen::MatrixXd>  m = 		// parse, eval + return result
+      Rcpp::as<Eigen::Map<Eigen::MatrixXd> >(R.parseEval(cmd));
+    Eigen::MatrixXd n = m.transpose() * m;
+    Eigen::ColPivHouseholderQR<Eigen::MatrixXd> nqr(n);
+
+    std::cout << "Initial Matrix m\n" << m << std::endl;
+    std::cout << "Product n = m' * m\n" << n << std::endl;
+    std::cout << "n.sum() " << n.sum() << std::endl;
+    std::cout << "nrq.rank() " << nqr.rank() << std::endl; 	
+
+    exit(0);
+}



More information about the Rinside-commits mailing list