[Rcpp-commits] r4490 - in pkg/RcppArmadillo: . inst/include inst/unitTests inst/unitTests/cpp vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 15 23:17:02 CEST 2013


Author: edd
Date: 2013-09-15 23:17:02 +0200 (Sun, 15 Sep 2013)
New Revision: 4490

Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
   pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
   pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
   pkg/RcppArmadillo/vignettes/RcppArmadillo-unitTests.Rnw
Log:
also add const case following Romain's commits for const ref and ref
added unit tests for all three for both matrices and vectors


Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/ChangeLog	2013-09-15 21:17:02 UTC (rev 4490)
@@ -1,5 +1,12 @@
-2013-09-15 Romain Francois <romain at r-enthusiasts.com>
-        
+2013-09-15  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/include/RcppArmadilloAs.h: Also define ConstInputParameter
+	* inst/include/RcppArmadilloForward.h: Ditto for declaration
+	* inst/unitTests/runit.RcppArmadillo.R: New unit tests for these
+	* inst/unitTests/cpp/armadillo.cpp: C++ code for new unit tests
+
+2013-09-15  Romain Francois <romain at r-enthusiasts.com>
+
         * include/RcppArmadilloForward.h : declaration of specializations of
 	ConstReferenceInputParameter and ReferenceInputParameter
         * include/RcppArmadilloAs.h : definitions of the above

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-15 21:17:02 UTC (rev 4490)
@@ -131,6 +131,18 @@
         Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > m ;
         arma::Mat<T> mat ;
     } ;
+
+    template <typename T>
+    class ConstInputParameter< arma::Mat<T> > {
+    public:
+        typedef const typename arma::Mat<T> const_nonref;
+        ConstInputParameter(SEXP x_) : m(x_), mat(m.begin(), m.nrow(), m.ncol(), false){}
+        inline operator const_nonref() { return mat ; }
+    private:
+        Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > m ;
+        arma::Mat<T> mat ;
+    };
+
     
     template <typename T, typename VEC, typename REF>
     class ArmaVec_InputParameter {
@@ -155,8 +167,10 @@
     
     MAKE_INPUT_PARAMETER(ConstReferenceInputParameter, arma::Col<T>, const arma::Col<T>& )
     MAKE_INPUT_PARAMETER(ReferenceInputParameter     , arma::Col<T>, arma::Col<T>&       )
+    MAKE_INPUT_PARAMETER(ConstInputParameter         , arma::Col<T>, const arma::Col<T>  )
     MAKE_INPUT_PARAMETER(ConstReferenceInputParameter, arma::Row<T>, const arma::Row<T>& )
     MAKE_INPUT_PARAMETER(ReferenceInputParameter     , arma::Row<T>, arma::Row<T>&       )
+    MAKE_INPUT_PARAMETER(ConstInputParameter         , arma::Row<T>, const arma::Row<T>  )
 #undef MAKE_INPUT_PARAMETER
 }
 

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloForward.h	2013-09-15 21:17:02 UTC (rev 4490)
@@ -98,12 +98,15 @@
 
     template <typename T> class ConstReferenceInputParameter< arma::Mat<T> > ;
     template <typename T> class ReferenceInputParameter< arma::Mat<T> > ;
+    template <typename T> class ConstInputParameter< arma::Mat<T> > ;
     
     template <typename T> class ConstReferenceInputParameter< arma::Col<T> > ;
     template <typename T> class ReferenceInputParameter< arma::Col<T> > ;
+    template <typename T> class ConstInputParameter< arma::Col<T> > ;
     
     template <typename T> class ConstReferenceInputParameter< arma::Row<T> > ;
     template <typename T> class ReferenceInputParameter< arma::Row<T> > ;
+    template <typename T> class ConstInputParameter< arma::Row<T> > ;
     
 }
 

Modified: pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp	2013-09-15 21:17:02 UTC (rev 4490)
@@ -210,3 +210,45 @@
 //     checkException(fun(), msg="RTTI check on matrix constructor exception")
 
 // }
+
+
+// [[Rcpp::export]]
+int mat_plain(arma::mat x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int mat_const(const arma::mat x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int mat_ref(arma::mat & x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int mat_const_ref(const arma::mat & x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int vec_plain(arma::vec x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int vec_const(const arma::vec x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int vec_ref(arma::vec & x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int vec_const_ref(const arma::vec & x) { 
+    return x.n_elem;
+}
+

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-09-15 21:17:02 UTC (rev 4490)
@@ -160,3 +160,52 @@
 ##     checkException(fun(), msg="RTTI check on matrix constructor exception")
 
 ## }
+
+test.armadillo.mat.plain <- function() {
+    fx <- mat_plain
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Plain Matrix function signature" )
+}
+
+test.armadillo.mat.const <- function() {
+    fx <- mat_const
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Const Matrix function signature" )
+}
+
+test.armadillo.mat.ref <- function() {
+    fx <- mat_ref
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Reference Matrix function signature" )
+}
+
+test.armadillo.mat.const.ref <- function() {
+    fx <- mat_const_ref
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Const Reference Matrix function signature" )
+}
+
+test.armadillo.vec.plain <- function() {
+    fx <- vec_plain
+    m <- 1:9
+    checkEquals(fx(m), 9, msg = "Plain Vector function signature" )
+}
+
+test.armadillo.vec.const <- function() {
+    fx <- vec_const
+    m <- 1:9
+    checkEquals(fx(m), 9, msg = "Const Vector function signature" )
+}
+
+test.armadillo.vec.ref <- function() {
+    fx <- vec_ref
+    m <- 1:9
+    checkEquals(fx(m), 9, msg = "Reference Vector function signature" )
+}
+
+test.armadillo.vec.const.ref <- function() {
+    fx <- vec_const_ref
+    m <- 1:9
+    checkEquals(fx(m), 9, msg = "Const Reference Vector function signature" )
+}
+

Modified: pkg/RcppArmadillo/vignettes/RcppArmadillo-unitTests.Rnw
===================================================================
--- pkg/RcppArmadillo/vignettes/RcppArmadillo-unitTests.Rnw	2013-09-15 20:18:34 UTC (rev 4489)
+++ pkg/RcppArmadillo/vignettes/RcppArmadillo-unitTests.Rnw	2013-09-15 21:17:02 UTC (rev 4490)
@@ -18,8 +18,8 @@
 
 \usepackage[colorlinks]{hyperref}
 \author{Dirk Eddelbuettel, Romain Fran\c{c}ois and Douglas Bates}
-\title{RcppArmadillo : Unit testing results}
-\date{\texttt{RcppArmadillo} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
+\title{\textbf{RcppArmadillo}: Unit testing results}
+\date{\textbf{RcppArmadillo} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
 
 \begin{document}
 \maketitle



More information about the Rcpp-commits mailing list