[Rcpp-commits] r912 - pkg/RcppArmadillo/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 17 15:32:06 CET 2010


Author: romain
Date: 2010-03-17 15:32:06 +0100 (Wed, 17 Mar 2010)
New Revision: 912

Modified:
   pkg/RcppArmadillo/src/RcppArmadillo.cpp
   pkg/RcppArmadillo/src/fastLm.cpp
Log:
use the arma:: prefix everywhere

Modified: pkg/RcppArmadillo/src/RcppArmadillo.cpp
===================================================================
--- pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-03-17 12:49:17 UTC (rev 911)
+++ pkg/RcppArmadillo/src/RcppArmadillo.cpp	2010-03-17 14:32:06 UTC (rev 912)
@@ -22,49 +22,50 @@
 #include <RcppArmadillo.h>
 
 using namespace Rcpp ;
-using namespace arma ;
-	
+
 extern "C" SEXP RcppArmadillo_wrap(){
 	
-    // using the _ notation
-    List matrices = make_list( 
-    	_["Mat<int>"]          = eye<imat>( 3,3 ), 
-    	_["Mat<double>"]       = eye<mat>( 3,3 ),
-    	_["Mat<float>"]        = eye<fmat>( 3, 3 ), 
-    	_["Mat<unsigned int>"] = eye<umat>( 3, 3 )
-    	) ;
-    
     // using the Named(.) = . notation
     List cols = make_list( 
-    	Named( "Col<double>" ) = zeros<mat>(5,1), 
-    	Named( "Col<float>" )  = zeros<fmat>(5,1)
+    	Named( "Col<double>" ) = arma::zeros<arma::mat>(5,1), 
+    	Named( "Col<float>" )  = arma::zeros<arma::fmat>(5,1)
     	) ; 
     
     // using the Named( . , . ) notation
     List rows = make_list( 
-    	Named( "Row<double>", zeros<mat>(1,5) ),
-    	Named( "Row<float>" , zeros<fmat>(1,5) )
+    	Named( "Row<double>", arma::zeros<arma::mat>(1,5) ),
+    	Named( "Row<float>" , arma::zeros<arma::fmat>(1,5) )
     	) ;
 	
+    // using the _[.] = . notation
+    List matrices = make_list( 
+    	_["Mat<int>"]          = arma::eye<arma::imat>( 3,3 ), 
+    	_["Mat<double>"]       = arma::eye<arma::mat>( 3,3 ),
+    	_["Mat<float>"]        = arma::eye<arma::fmat>( 3, 3 ), 
+    	_["Mat<unsigned int>"] = arma::eye<arma::umat>( 3, 3 )
+    	) ;
+    
     // creating an empty list and grow it on demand
     List fields ;
-    field<int> f1( 2, 2 ) ;
+    arma::field<int> f1( 2, 2 ) ;
     f1( 0, 0 ) = 0 ; 
     f1( 1, 0 ) = 1 ; 
     f1( 0, 1 ) = 2 ; 
     f1( 1, 1 ) = 3 ; 
     fields["field<int>"] = f1 ;
-    field<std::string> f2(2,2) ;
+    
+    arma::field<std::string> f2(2,2) ;
     f2( 0, 0 ) = "a" ; 
     f2( 1, 0 ) = "b" ; 
     f2( 0, 1 ) = "c" ; 
     f2( 1, 1 ) = "d" ; 
     fields["field<std::string>"] = f2 ;
-    field<colvec> f3(2,2) ;
-    f3(0,0) = zeros<mat>(5,1) ;
-    f3(1,0) = zeros<mat>(4,1) ;
-    f3(0,1) = zeros<mat>(3,1) ;
-    f3(1,1) = zeros<mat>(2,1) ;
+    
+    arma::field<arma::colvec> f3(2,2) ;
+    f3(0,0) = arma::zeros<arma::mat>(5,1) ;
+    f3(1,0) = arma::zeros<arma::mat>(4,1) ;
+    f3(0,1) = arma::zeros<arma::mat>(3,1) ;
+    f3(1,1) = arma::zeros<arma::mat>(2,1) ;
     fields["field<colvec>"] = f3 ;
 	
     List output = make_list( 
@@ -80,64 +81,64 @@
 extern "C" SEXP RcppArmadillo_as_Mat(SEXP input_){
 
     List input(input_) ;
-    imat m1 = input[0] ; /* implicit as */
-    mat  m2 = input[1] ; /* implicit as */
-    umat m3 = input[0] ; /* implicit as */
-    fmat m4 = input[1] ; /* implicit as */
+    arma::imat m1 = input[0] ; /* implicit as */
+    arma::mat  m2 = input[1] ; /* implicit as */
+    arma::umat m3 = input[0] ; /* implicit as */
+    arma::fmat m4 = input[1] ; /* implicit as */
 	
     List res = make_list( 
-    	accu( m1 ),
-    	accu( m2 ),
-    	accu( m3 ),
-    	accu( m4 ) ) ;
+    	arma::accu( m1 ),
+    	arma::accu( m2 ),
+    	arma::accu( m3 ),
+    	arma::accu( m4 ) ) ;
     
     return res ;
 }
 
 extern "C" SEXP RcppArmadillo_as_Col( SEXP input_){
     List input(input_) ;
-    icolvec m1 = input[0] ; /* implicit as */
-    colvec  m2 = input[1] ; /* implicit as */
-    ucolvec m3 = input[0] ; /* implicit as */
-    fcolvec m4 = input[1] ; /* implicit as */
+    arma::icolvec m1 = input[0] ; /* implicit as */
+    arma::colvec  m2 = input[1] ; /* implicit as */
+    arma::ucolvec m3 = input[0] ; /* implicit as */
+    arma::fcolvec m4 = input[1] ; /* implicit as */
 	
     List res = make_list( 
-    	accu( m1 ),
-    	accu( m2 ),
-    	accu( m3 ),
-    	accu( m4 ) ) ;
+    	arma::accu( m1 ),
+    	arma::accu( m2 ),
+    	arma::accu( m3 ),
+    	arma::accu( m4 ) ) ;
     
     return res ;
 }
 
 extern "C" SEXP RcppArmadillo_as_Row(SEXP input_){
     List input(input_) ;
-    irowvec m1 = input[0] ; /* implicit as */
-    rowvec  m2 = input[1] ; /* implicit as */
-    urowvec m3 = input[0] ; /* implicit as */
-    frowvec m4 = input[1] ; /* implicit as */
+    arma::irowvec m1 = input[0] ; /* implicit as */
+    arma::rowvec  m2 = input[1] ; /* implicit as */
+    arma::urowvec m3 = input[0] ; /* implicit as */
+    arma::frowvec m4 = input[1] ; /* implicit as */
 	
     List res = make_list( 
-    	accu( m1 ),
-    	accu( m2 ),
-    	accu( m3 ),
-    	accu( m4 ) ) ;
+    	arma::accu( m1 ),
+    	arma::accu( m2 ),
+    	arma::accu( m3 ),
+    	arma::accu( m4 ) ) ;
     return res ;
 }
 
 extern "C" SEXP RcppArmadillo_wrap_Glue(){
 	
-    mat m1 = eye<mat>( 3, 3 ) ;
-    mat m2 = eye<mat>( 3, 3 ) ;
-	
-    List res ;
+    arma::mat m1 = arma::eye<arma::mat>( 3, 3 ) ;
+    arma::mat m2 = arma::eye<arma::mat>( 3, 3 ) ;
+	                     
+    List res ;                                  
     res["mat+mat"] = m1 + m2 ;
     return res ;
 }
 
 extern "C" SEXP RcppArmadillo_wrap_Op(){
 
-    mat m1 = eye<mat>( 3, 3 ) ;
+	arma::mat m1 = arma::eye<arma::mat>( 3, 3 ) ;
 	
     List res ;
     res["- mat"] = - m1 ;
@@ -150,9 +151,9 @@
     if( single ){
 	return Rcpp::wrap( 10000*av.major + 100*av.minor + av.patch ) ;
     }
-    Rcpp::IntegerVector version(3); 
+    IntegerVector version(3); 
     version = av.major, av.minor, av.patch ;
-    Rcpp::CharacterVector names(3); 
+    CharacterVector names(3); 
     names = "major", "minor", "patch" ;
     version.names() = names ;
     version.attr("class" ) = "armadillo_version" ;

Modified: pkg/RcppArmadillo/src/fastLm.cpp
===================================================================
--- pkg/RcppArmadillo/src/fastLm.cpp	2010-03-17 12:49:17 UTC (rev 911)
+++ pkg/RcppArmadillo/src/fastLm.cpp	2010-03-17 14:32:06 UTC (rev 912)
@@ -21,8 +21,6 @@
 
 #include <RcppArmadillo.h>
 
-// [romain]: what about "using namespace arma; " in the function
-
 extern "C" SEXP fastLm(SEXP ys, SEXP Xs) {
 
     Rcpp::NumericVector yr(ys);			// creates Rcpp vector from SEXP
@@ -41,7 +39,7 @@
 	arma::colvec resid = y - X*coef; 		// residuals
 
 #if ARMA_VERSION_GE_090
-    double sig2 = arma::as_scalar( trans(resid)*resid/(n-k) );
+	double sig2 = arma::as_scalar( arma::trans(resid)*resid/(n-k) );
 #else
 	double sig2 = ( arma::trans(resid)*resid/(n-k) );
 #endif



More information about the Rcpp-commits mailing list