[Rcpp-commits] r2907 - in pkg/Rcpp: . inst/doc/Rcpp-FAQ

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 20 17:23:57 CET 2011


Author: edd
Date: 2011-02-20 17:23:57 +0100 (Sun, 20 Feb 2011)
New Revision: 2907

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw
Log:
added RcppArmadillo example


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-02-19 21:44:48 UTC (rev 2906)
+++ pkg/Rcpp/ChangeLog	2011-02-20 16:23:57 UTC (rev 2907)
@@ -1,3 +1,7 @@
+2011-02-20  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Added RcppArmadillo example
+
 2011-02-19  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw: Added three more setup-related

Modified: pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw	2011-02-19 21:44:48 UTC (rev 2906)
+++ pkg/Rcpp/inst/doc/Rcpp-FAQ/Rcpp-FAQ.Rnw	2011-02-20 16:23:57 UTC (rev 2907)
@@ -472,6 +472,31 @@
 @
 
 
+\subsection{Can I easily multiply matrices ? }
+
+\begin{quote}
+  \emph{Can I multiply matrices easily?}
+\end{quote}
+
+Yes, via the \pkg{RcppArmadillo} package which builds upon \pkg{Rcpp} and the
+wonderful Armadillo library at \url{http://arma.sf.net}:
+
+<<eval=FALSE>>=
+txt <- 'arma::mat Am = Rcpp::as< arma::mat >(A);
+        arma::mat Bm = Rcpp::as< arma::mat >(B);
+        return Rcpp::wrap( Am * Bm );'
+mmult <- cxxfunction(signature(A="numeric", B="numeric"),
+                     body=txt, plugin="RcppArmadillo")
+A <- matrix(1:9, 3, 3)
+B <- matrix(9:1, 3, 3)
+C <- mmult(A, B)
+@
+% < < echo=FALSE,print=FALSE > > =
+% A <- matrix(1:9, 3, 3)
+% B <- matrix(9:1, 3, 3)
+% A %*% B
+% @
+
 \section{Support}
 
 \subsection{Is the API documented ? }



More information about the Rcpp-commits mailing list