[Rcpp-commits] r1627 - pkg/Rcpp/inst/doc/Rcpp-sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 19 14:16:24 CEST 2010


Author: romain
Date: 2010-06-19 14:16:23 +0200 (Sat, 19 Jun 2010)
New Revision: 1627

Modified:
   pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
Log:
copy and paste is bad, maybe we should come up with something

Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-19 12:09:10 UTC (rev 1626)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-19 12:16:23 UTC (rev 1627)
@@ -54,6 +54,7 @@
   of the \pkg{Rcpp} API. 
   
   \sugar{} is based on the technique of expression templates.
+  % TODO: reference to armadillo, blitz, etc ...
 }
 
 \section{Motivation}
@@ -129,21 +130,81 @@
 NumericVector x ;
 NumericVector y ;
 
-// adding them
+// two vectors
 NumericVector res = x + y ;
 
-// adding a single value
+// one vector, one single value
 NumericVector res = x + 2.0 ;
 NumericVector res = 2.0 + x;
 
-// adding expressions
+// two expressions
 NumericVector res = x * y + y / 2.0 ;
 @
 
 \subsubsection{operator-}
+
+The \texttt{operator-} is used to substract two \sugar{} expressions of the same 
+size or one \sugar{} expression with a single value of the appropriate type.
+
+<<lang=cpp>>=
+// two numeric vectors of the same size
+NumericVector x ;
+NumericVector y ;
+
+// two vectors
+NumericVector res = x - y ;
+
+// one vector, one single value
+NumericVector res = x - 2.0 ;
+NumericVector res = 2.0 - x;
+
+// two expressions
+NumericVector res = x * y - y / 2.0 ;
+@
+
 \subsubsection{operator*}
+
+The \texttt{operator*} is used to multiply two \sugar{} expressions of the same 
+size or one \sugar{} expression with a single value of the appropriate type.
+
+<<lang=cpp>>=
+// two numeric vectors of the same size
+NumericVector x ;
+NumericVector y ;
+
+// two vectors
+NumericVector res = x * y ;
+
+// one vector, one single value
+NumericVector res = x * 2.0 ;
+NumericVector res = 2.0 * x;
+
+// two expressions
+NumericVector res = x * ( y - 2.0 ) ;
+@
+
 \subsubsection{operator/}
 
+The \texttt{operator*} is used to divide two \sugar{} expressions of the same 
+size or one \sugar{} expression with a single value of the appropriate type.
+
+<<lang=cpp>>=
+// two numeric vectors of the same size
+NumericVector x ;
+NumericVector y ;
+
+// two vectors
+NumericVector res = x / y ;
+
+// one vector, one single value
+NumericVector res = x / 2.0 ;
+NumericVector res = 2.0 / x;
+
+// two expressions
+NumericVector res = x / ( y * y ) ;
+@
+
+
 \subsection{Unary operators}
 
 \subsubsection{operator-}
@@ -162,6 +223,7 @@
 \subsection{sapply}
 \subsection{lapply}
 
+\section{Performance}
 
 \section{Implementation}
 



More information about the Rcpp-commits mailing list