[Rcpp-commits] r827 - in pkg/RcppArmadillo: R inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 3 11:22:16 CET 2010


Author: romain
Date: 2010-03-03 11:22:16 +0100 (Wed, 03 Mar 2010)
New Revision: 827

Added:
   pkg/RcppArmadillo/R/armadillo_version.R
Modified:
   pkg/RcppArmadillo/inst/include/RcppArmadillo.h
   pkg/RcppArmadillo/src/RcppArmadillo.cpp
Log:
add a simple armadillo_version function so that we can test > 0.9.0 features in unit test

Added: pkg/RcppArmadillo/R/armadillo_version.R
===================================================================
--- pkg/RcppArmadillo/R/armadillo_version.R	                        (rev 0)
+++ pkg/RcppArmadillo/R/armadillo_version.R	2010-03-03 10:22:16 UTC (rev 827)
@@ -0,0 +1,21 @@
+## Copyright (C)       2010 Dirk Eddelbuettel and Romain Francois
+##
+## This file is part of RcppArmadillo.
+##
+## RcppArmadillo is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 2 of the License, or
+## (at your option) any later version.
+##
+## RcppArmadillo is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
+
+armadillo_version <- function(single = FALSE){
+	.Call( "armadillo_version", isTRUE(single), PACKAGE = "RcppArmadillo" )
+}
+

Modified: pkg/RcppArmadillo/inst/include/RcppArmadillo.h
===================================================================
--- pkg/RcppArmadillo/inst/include/RcppArmadillo.h	2010-03-03 09:43:55 UTC (rev 826)
+++ pkg/RcppArmadillo/inst/include/RcppArmadillo.h	2010-03-03 10:22:16 UTC (rev 827)
@@ -28,7 +28,6 @@
 
 /* forward declarations */
 namespace Rcpp {
-	
     /* support for wrap */
     template <typename T> SEXP wrap ( const arma::Mat<T>& ) ;
     template <typename T> SEXP wrap ( const arma::Row<T>& ) ;
@@ -50,6 +49,19 @@
     
     template <typename T1, typename op_type>
     SEXP wrap(const arma::eOp<T1, op_type>& X ) ;
+    
+    /* TODO: maybe we can move those out of if( 0.9.0 ) */
+    template <typename T1, typename op_type>
+    SEXP wrap(const arma::OpCube<T1,op_type>& X ) ;
+    
+    template <typename T1, typename T2, typename glue_type>
+    SEXP wrap(const arma::GlueCube<T1,T2,glue_type>& X ) ;
+    
+    template <typename T1, typename op_type>
+    SEXP wrap(const arma::eOpCube<T1,op_type>& X ) ;
+    
+    template <typename T1, typename T2, typename glue_type>
+    SEXP wrap(const arma::eGlueCube<T1,T2,glue_type>& X ) ;
     #endif 
     
     namespace traits {
@@ -144,6 +156,17 @@
     
     /* TODO: will do better when I can use 0.9.0 */
     #if ARMA_VERSION_GE_090
+    
+    template <typename T1, typename op_type>
+    SEXP wrap(const arma::OpCube<T1,op_type>& X ){
+    	return wrap( arma::Cube<typename T1::elem_type>(X) ) ;
+    }
+    
+    template <typename T1, typename T2, typename glue_type>
+    SEXP wrap(const arma::GlueCube<T1,T2,glue_type>& X ){
+    	return wrap( arma::Cube<typename T1::elem_type>(X) ) ;
+    }
+    
     namespace RcppArmadillo{
     	
     	/* we can intercept and directly build the resulting matrix using 
@@ -191,6 +214,16 @@
     SEXP wrap(const arma::eOp<T1, op_type>& X ){
     	    return RcppArmadillo::wrap_eop( X, typename traits::r_sexptype_needscast<typename T1::elem_type>::type() ) ;
     }
+    
+    template <typename T1, typename op_type>
+    SEXP wrap(const arma::eOpCube<T1,op_type>& X ){
+    	return wrap( arma::Cube<typename T1::elem_type>(X) ) ;
+    }
+    
+    template <typename T1, typename T2, typename glue_type>
+    SEXP wrap(const arma::eGlueCube<T1,T2,glue_type>& X ){
+    	return wrap( arma::Cube<typename T1::elem_type>(X) ) ;
+    }
     #endif
 
     /* support for Rcpp::as */

Modified: pkg/RcppArmadillo/src/RcppArmadillo.cpp
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-03-03 09:43:55 UTC (rev 826)
+++ pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-03-03 10:22:16 UTC (rev 827)
@@ -206,3 +206,19 @@
                        Rcpp::Named( "stderr", stderrest));
     return res;
 }
+
+extern "C" SEXP armadillo_version(SEXP single_){
+	struct arma::arma_version av;
+	bool single = Rcpp::as<bool>( single_) ;
+	if( single ){
+		return Rcpp::wrap( 10000*av.major + 100*av.minor + av.patch ) ;
+	}
+	Rcpp::IntegerVector version(3); 
+	version = av.major, av.minor, av.patch ;
+	Rcpp::CharacterVector names(3); 
+	names = "major", "minor", "patch" ;
+	version.names() = names ;
+	version.attr("class" ) = "armadillo_version" ;
+	return version ;
+}
+



More information about the Rcpp-commits mailing list