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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 27 17:11:21 CEST 2013


Author: romain
Date: 2013-09-27 17:11:20 +0200 (Fri, 27 Sep 2013)
New Revision: 4537

Modified:
   pkg/RcppArmadillo/ChangeLog
   pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
   pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
Log:
handle InputParameter for complex type (cx_mat) ...

Modified: pkg/RcppArmadillo/ChangeLog
===================================================================
--- pkg/RcppArmadillo/ChangeLog	2013-09-27 14:07:41 UTC (rev 4536)
+++ pkg/RcppArmadillo/ChangeLog	2013-09-27 15:11:20 UTC (rev 4537)
@@ -1,3 +1,10 @@
+2013-09-27 Romain Francois <romain at r-enthusiasts.com>
+
+        * include/RcppArmadilloAs.h : handle cx_mat, using that Rcomplex is
+        layout compatible with std::complex<double>
+        * unitTests/cpp/armadillo.cpp : more testing
+        * unitTests/runit.RcppArmadillo.R : more testing
+        
 2013-09-23  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/*: Upgraded to Armadillo pre-release of 3.920.0

Modified: pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-27 14:07:41 UTC (rev 4536)
+++ pkg/RcppArmadillo/inst/include/RcppArmadilloAs.h	2013-09-27 15:11:20 UTC (rev 4537)
@@ -105,7 +105,7 @@
     public:
         typedef const typename arma::Mat<T>& const_reference ;
                         
-        ConstReferenceInputParameter( SEXP x_ ) : m(x_), mat( m.begin(), m.nrow(), m.ncol(), false ){}
+        ConstReferenceInputParameter( SEXP x_ ) : m(x_), mat( reinterpret_cast<T*>( m.begin() ), m.nrow(), m.ncol(), false ){}
                         
         inline operator const_reference(){
         		return mat ;        
@@ -121,7 +121,7 @@
     public:
         typedef typename arma::Mat<T>& reference ;
                         
-        ReferenceInputParameter( SEXP x_ ) : m(x_), mat( m.begin(), m.nrow(), m.ncol(), false ){}
+        ReferenceInputParameter( SEXP x_ ) : m(x_), mat( reinterpret_cast<T*>( m.begin() ), m.nrow(), m.ncol(), false ){}
                         
         inline operator reference(){
             return mat ;        
@@ -136,7 +136,7 @@
     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){}
+        ConstInputParameter(SEXP x_) : m(x_), mat( reinterpret_cast<T*>( m.begin() ), m.nrow(), m.ncol(), false){}
         inline operator const_nonref() { return mat ; }
     private:
         Rcpp::Matrix< Rcpp::traits::r_sexptype_traits<T>::rtype > m ;
@@ -147,7 +147,7 @@
     template <typename T, typename VEC, typename REF>
     class ArmaVec_InputParameter {
     public:
-        ArmaVec_InputParameter( SEXP x_ ) : v(x_), vec( v.begin(), v.size(), false ){}
+        ArmaVec_InputParameter( SEXP x_ ) : v(x_), vec( reinterpret_cast<T*>( v.begin() ), v.size(), false ){}
                         
         inline operator REF(){
             return vec ;        

Modified: pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp	2013-09-27 14:07:41 UTC (rev 4536)
+++ pkg/RcppArmadillo/inst/unitTests/cpp/armadillo.cpp	2013-09-27 15:11:20 UTC (rev 4537)
@@ -252,3 +252,23 @@
     return x.n_elem;
 }
 
+// [[Rcpp::export]]
+int cx_mat_plain(arma::cx_mat x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int cx_mat_const(const arma::cx_mat x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int cx_mat_ref(arma::cx_mat & x) { 
+    return x.n_elem;
+}
+
+// [[Rcpp::export]]
+int cx_mat_const_ref(const arma::cx_mat & x) { 
+    return x.n_elem;
+}
+

Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-09-27 14:07:41 UTC (rev 4536)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2013-09-27 15:11:20 UTC (rev 4537)
@@ -209,3 +209,26 @@
     checkEquals(fx(m), 9, msg = "Const Reference Vector function signature" )
 }
 
+test.armadillo.mat.plain <- function() {
+    fx <- cx_mat_plain
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Plain Matrix function signature" )
+}
+
+test.armadillo.mat.const <- function() {
+    fx <- cx_mat_const
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Const Matrix function signature" )
+}
+
+test.armadillo.mat.ref <- function() {
+    fx <- cx_mat_ref
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Reference Matrix function signature" )
+}
+
+test.armadillo.mat.const.ref <- function() {
+    fx <- cx_mat_const_ref
+    m <- matrix(1:9, 3, 3)
+    checkEquals(fx(m), 9, msg = "Const Reference Matrix function signature" )
+}



More information about the Rcpp-commits mailing list