[Rcpp-commits] r2428 - pkg/RcppArmadillo/inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 11 17:31:10 CET 2010


Author: edd
Date: 2010-11-11 17:31:10 +0100 (Thu, 11 Nov 2010)
New Revision: 2428

Modified:
   pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
   pkg/RcppArmadillo/inst/unitTests/runit.fastLm.R
Log:
two changes without which the unit tests failed for me -- odd
needed to force loading of inline and RcppArmadillo, respectively


Modified: pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-11-11 15:47:37 UTC (rev 2427)
+++ pkg/RcppArmadillo/inst/unitTests/runit.RcppArmadillo.R	2010-11-11 16:31:10 UTC (rev 2428)
@@ -17,62 +17,66 @@
 # You should have received a copy of the GNU General Public License
 # along with RcppArmadillo.  If not, see <http://www.gnu.org/licenses/>.
 
+.setUp <- function(){
+    suppressMessages(require(inline))
+}
+
 test.wrap.R <- function(){
-	
-	fx <- cxxfunction( , '
-	   
-	// using the Named(.) = . notation
-    List cols = List::create( 
-    	Named( "Col<double>" ) = arma::zeros<arma::mat>(5,1), 
-    	Named( "Col<float>" )  = arma::zeros<arma::fmat>(5,1)
-    	) ;
-    
+
+    fx <- cxxfunction( , '
+
+    // using the Named(.) = . notation
+    List cols = List::create(
+    Named( "Col<double>" ) = arma::zeros<arma::mat>(5,1),
+    Named( "Col<float>" )  = arma::zeros<arma::fmat>(5,1)
+    ) ;
+
     // using the Named(., .)  notation
-    List rows = List::create( 
-    	Named( "Row<double>",  arma::zeros<arma::mat>(1,5)  ),
-    	Named( "Row<float>" ,  arma::zeros<arma::fmat>(1,5) )
-    	) ;
-	
+    List rows = List::create(
+    Named( "Row<double>",  arma::zeros<arma::mat>(1,5)  ),
+    Named( "Row<float>" ,  arma::zeros<arma::fmat>(1,5) )
+    ) ;
+
     // using the _[.] = . notation
-    List matrices = List::create( 
-    	_["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 )
-    	) ;
-    
+    List matrices = List::create(
+        _["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 ;
     arma::field<int> f1( 2, 2 ) ;
-    f1( 0, 0 ) = 0 ; 
-    f1( 1, 0 ) = 1 ; 
-    f1( 0, 1 ) = 2 ; 
-    f1( 1, 1 ) = 3 ; 
+    f1( 0, 0 ) = 0 ;
+    f1( 1, 0 ) = 1 ;
+    f1( 0, 1 ) = 2 ;
+    f1( 1, 1 ) = 3 ;
     fields["field<int>"] = f1 ;
-    
+
     arma::field<std::string> f2(2,2) ;
-    f2( 0, 0 ) = "a" ; 
-    f2( 1, 0 ) = "b" ; 
-    f2( 0, 1 ) = "c" ; 
-    f2( 1, 1 ) = "d" ; 
+    f2( 0, 0 ) = "a" ;
+    f2( 1, 0 ) = "b" ;
+    f2( 0, 1 ) = "c" ;
+    f2( 1, 1 ) = "d" ;
     fields["field<std::string>"] = f2 ;
-    
+
     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 = List::create( 
-    	_["matrices : Mat<T>"]  = matrices, 
+
+    List output = List::create(
+    	_["matrices : Mat<T>"]  = matrices,
     	_["rows : Row<T>"]      = rows,
-    	_["columns : Col<T>"]   = cols, 
+    	_["columns : Col<T>"]   = cols,
     	_["fields  : field<T>"] = fields ) ;
-    
+
     return output ;
 	' , plugin = "RcppArmadillo" )
-	
+
     res <- fx()
 
     checkEquals( res[[1]][[1]], matrix(as.integer((diag(3))),nr=3), msg = "eye<imat>(3,3)" )
@@ -91,55 +95,55 @@
 }
 
 test.wrap.Glue <- function(){
-    
-	fx <- cxxfunction( , '
-	
+
+    fx <- cxxfunction( , '
+
     arma::mat m1 = arma::eye<arma::mat>( 3, 3 ) ;
     arma::mat m2 = arma::eye<arma::mat>( 3, 3 ) ;
-	                     
-    List res ;                                  
+
+    List res ;
     res["mat+mat"] = m1 + m2 ;
     return res ;
-	
-	', plugin = "RcppArmadillo" )
-	
+
+    ', plugin = "RcppArmadillo" )
+
 	res <- fx()
     checkEquals( res[[1]], 2*diag(3), msg = "wrap(Glue)" )
 }
 
 test.wrap.Op <- function(){
-	
-	fx <- cxxfunction( , '
-	
-	arma::mat m1 = arma::eye<arma::mat>( 3, 3 ) ;
-	
+
+    fx <- cxxfunction( , '
+
+    arma::mat m1 = arma::eye<arma::mat>( 3, 3 ) ;
+
     List res ;
     res["- mat"] = - m1 ;
     return res ;
-	
-	', plugin = "RcppArmadillo" )
+
+    ', plugin = "RcppArmadillo" )
     res <- fx()
     checkEquals( res[[1]], -1*diag(3), msg = "wrap(Op)" )
 }
 
 test.as.Mat <- function(){
-	
-	fx <- cxxfunction( signature(input_ = "list" ) , '
-	    List input(input_) ;
-    	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 = List::create( 
-    		arma::accu( m1 ),
-    		arma::accu( m2 ),
-    		arma::accu( m3 ),
-    		arma::accu( m4 ) ) ;
-    	
-    	return res ;
+
+    fx <- cxxfunction( signature(input_ = "list" ) , '
+    List input(input_) ;
+    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 = List::create(
+    	arma::accu( m1 ),
+    	arma::accu( m2 ),
+    	arma::accu( m3 ),
+    	arma::accu( m4 ) ) ;
+
+    return res ;
     ', plugin = "RcppArmadillo" )
-	
+
     integer_mat <- matrix( as.integer(diag(4)), ncol = 4, nrow = 4 )
     numeric_mat <- diag(5)
     res <- fx( list( integer_mat, numeric_mat ) )
@@ -147,44 +151,44 @@
 }
 
 test.as.Col <- function(){
-	fx <- cxxfunction( signature(input_ = "list" ) , '
-		
+    fx <- cxxfunction( signature(input_ = "list" ) , '
+
     List input(input_) ;
     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 = List::create( 
+
+    List res = List::create(
     	arma::accu( m1 ),
     	arma::accu( m2 ),
     	arma::accu( m3 ),
     	arma::accu( m4 ) ) ;
-    
+
     return res ;
-	
-	', plugin = "RcppArmadillo" )
-	
+
+    ', plugin = "RcppArmadillo" )
+
     res <- fx( list( 1:10, as.numeric(1:10) ) )
     checkEquals( unlist( res ), rep(55.0, 4 ), msg = "as<Col>" )
 }
 
 test.as.Row <- function(){
-	fx <- cxxfunction( signature(input_ = "list" ) , '
+    fx <- cxxfunction( signature(input_ = "list" ) , '
 
     List input(input_) ;
     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 = List::create( 
+
+    List res = List::create(
     	arma::accu( m1 ),
     	arma::accu( m2 ),
     	arma::accu( m3 ),
     	arma::accu( m4 ) ) ;
     return res ;
-	
+
 	', plugin = "RcppArmadillo" )
 
     res <- fx( list( 1:10, as.numeric(1:10) ) )
@@ -192,136 +196,136 @@
 }
 
 test.cxmat <- function(){
-	
-	fx <- cxxfunction( signature() , '
 
+    fx <- cxxfunction( signature() , '
+
     arma::cx_mat m1  = arma::eye<arma::cx_mat> ( 3, 3 ) ;
     arma::cx_fmat m2 = arma::eye<arma::cx_fmat>( 3, 3 ) ;
     return List::create( _["double"] = m1, _["float"] = m2 ) ;
-    
-	', plugin = "RcppArmadillo" )
-	checkEquals( fx(), 
-		list( double = (1+0i)*diag(3), float = (1+0i)*diag(3) ), 
+
+    ', plugin = "RcppArmadillo" )
+    checkEquals( fx(),
+		list( double = (1+0i)*diag(3), float = (1+0i)*diag(3) ),
 		msg = "support for complex matrices" )
-	
+
 }
 
 test.mtOp <- function(){
 
-	fx <- cxxfunction( signature() , '
+    fx <- cxxfunction( signature() , '
 
-	std::complex<double> x( 1.0, 2.0 ) ;
+    std::complex<double> x( 1.0, 2.0 ) ;
     arma::mat m1  = arma::eye<arma::mat> ( 3, 3 ) ;
 
     return wrap( x * m1 ) ;
-    
-	', plugin = "RcppArmadillo" )
-	checkEquals( fx(), 
-		(1+2i)*diag(3), 
+
+    ', plugin = "RcppArmadillo" )
+    checkEquals( fx(),
+		(1+2i)*diag(3),
 		msg = "support for mtOp" )
-	
+
 }
 
 test.mtGlue <- function(){
 
-	fx <- cxxfunction( signature() , '
+    fx <- cxxfunction( signature() , '
 
-	arma::imat m2 = arma::eye<arma::imat> ( 3, 3 ) ;
-	arma::mat m1  = arma::eye<arma::mat> ( 3, 3 ) ;
+    arma::imat m2 = arma::eye<arma::imat> ( 3, 3 ) ;
+    arma::mat m1  = arma::eye<arma::mat> ( 3, 3 ) ;
 
     return wrap( m1 + m2 ) ;
-    
-	', plugin = "RcppArmadillo" )
-	checkEquals( fx(), 
-		2.0 * diag(3) , 
+
+    ', plugin = "RcppArmadillo" )
+    checkEquals( fx(),
+		2.0 * diag(3) ,
 		msg = "support for mtOp" )
-	
+
 }
 
 
 test.sugar <- function(){
 
-	fx <- cxxfunction( signature(x= "numeric") , '
-	NumericVector xx(x) ;
-	arma::mat m = forward( xx + xx ) ; 
+    fx <- cxxfunction( signature(x= "numeric") , '
+    NumericVector xx(x) ;
+    arma::mat m = forward( xx + xx ) ;
     return wrap( m ) ;
-    
-	', plugin = "RcppArmadillo" )
-	checkEquals( fx(1:10), 
-		matrix( 2*(1:10), nrow = 10 ) , 
+
+    ', plugin = "RcppArmadillo" )
+    checkEquals( fx(1:10),
+		matrix( 2*(1:10), nrow = 10 ) ,
 		msg = "RcppArmadillo and sugar" )
-	
+
 }
 
 test.sugar.cplx <- function(){
 
-	fx <- cxxfunction( signature(x= "complex") , '
-	ComplexVector xx(x) ;
-	arma::cx_mat m = forward( exp( xx ) ) ; 
-	
+    fx <- cxxfunction( signature(x= "complex") , '
+    ComplexVector xx(x) ;
+    arma::cx_mat m = forward( exp( xx ) ) ;
+
     return wrap( m ) ;
-    
-	', plugin = "RcppArmadillo" )
-	x <- 1:10*(1+1i) 
-	checkEquals( fx(x), 
-		matrix( exp(x), nrow = 10 ) , 
+
+    ', plugin = "RcppArmadillo" )
+    x <- 1:10*(1+1i)
+    checkEquals( fx(x),
+		matrix( exp(x), nrow = 10 ) ,
 		msg = "RcppArmadillo and sugar (complex)" )
-	
+
 }
 
 test.armadillo.sugar.ctor <- function(){
 
-	fx <- cxxfunction( signature(x= "numeric") , '
-	NumericVector xx(x) ;
-	arma::mat m = xx + xx ;
-	arma::colvec co = xx ;
-	arma::rowvec ro = xx ;
-    return List::create( 
-    	_["mat"] = m + m, 
-    	_["rowvec"] = ro, 
-    	_["colvec"] = co 
-    ); 
+    fx <- cxxfunction( signature(x= "numeric") , '
+    NumericVector xx(x) ;
+    arma::mat m = xx + xx ;
+    arma::colvec co = xx ;
+    arma::rowvec ro = xx ;
+    return List::create(
+    	_["mat"] = m + m,
+    	_["rowvec"] = ro,
+    	_["colvec"] = co
+    );
     ', plugin = "RcppArmadillo" )
-	checkEquals( fx(1:10), 
-		list( 
-			mat = matrix( 4*(1:10), nrow = 10 ), 
-			rowvec = matrix( 1:10, nrow = 1 ), 
-			colvec = matrix( 1:10, ncol = 1 )
-			)
-		, 
+    checkEquals( fx(1:10),
+		list(
+                     mat = matrix( 4*(1:10), nrow = 10 ),
+                     rowvec = matrix( 1:10, nrow = 1 ),
+                     colvec = matrix( 1:10, ncol = 1 )
+                     )
+		,
 		msg = "Mat( sugar expression )" )
-	
+
 }
 
 
 test.armadillo.sugar.matrix.ctor <- function(){
 
-	inc <- '
-	double norm( double x, double y){
+    inc <- '
+    double norm( double x, double y){
 		return ::sqrt( x*x + y*y );
-	}
-	'
-	fx <- cxxfunction( signature(x= "numeric") , '
-	NumericVector xx(x) ;
-	NumericVector yy = NumericVector::create( 1 ) ;
-	arma::mat m = diag( xx ) ; 
-	arma::colvec co = outer( xx, yy, ::norm ) ;
-	arma::rowvec ro = outer( yy, xx, ::norm ) ;
-    return List::create( 
-    	_["mat"] = m + m , 
-    	_["rowvec"] = ro, 
-    	_["colvec"] = co 
-    ); 
+    }
+    '
+    fx <- cxxfunction( signature(x= "numeric") , '
+    NumericVector xx(x) ;
+    NumericVector yy = NumericVector::create( 1 ) ;
+    arma::mat m = diag( xx ) ;
+    arma::colvec co = outer( xx, yy, ::norm ) ;
+    arma::rowvec ro = outer( yy, xx, ::norm ) ;
+    return List::create(
+    	_["mat"] = m + m ,
+    	_["rowvec"] = ro,
+    	_["colvec"] = co
+    );
     ', plugin = "RcppArmadillo", includes = inc )
-	res <- fx(1:10)    
-	norm <- function(x, y) sqrt( x*x + y*y )
-	checkEquals( res, 
-		list( 
-			mat = diag(2*(1:10)), 
-			rowvec = outer( 1, 1:10, norm ), 
-			colvec = outer( 1:10, 1, norm )
-		), 
+    res <- fx(1:10)
+    norm <- function(x, y) sqrt( x*x + y*y )
+    checkEquals( res,
+		list(
+                     mat = diag(2*(1:10)),
+                     rowvec = outer( 1, 1:10, norm ),
+                     colvec = outer( 1:10, 1, norm )
+                     ),
 		msg = "Mat( sugar expression )" )
-	
+
 }
 

Modified: pkg/RcppArmadillo/inst/unitTests/runit.fastLm.R
===================================================================
--- pkg/RcppArmadillo/inst/unitTests/runit.fastLm.R	2010-11-11 15:47:37 UTC (rev 2427)
+++ pkg/RcppArmadillo/inst/unitTests/runit.fastLm.R	2010-11-11 16:31:10 UTC (rev 2428)
@@ -19,6 +19,7 @@
 
 .setUp <- function(){
     suppressMessages(require(datasets))
+    suppressMessages(require(RcppArmadillo))
 }
 
 test.fastLm <- function() {
@@ -26,7 +27,7 @@
     flm <- .Call("fastLm",
                  log(trees$Volume),
                  cbind(1, log(trees$Girth)),
-                 PACKAGE="RcppArmadillo")
+                 package="RcppArmadillo")
     fit <- lm(log(Volume) ~ log(Girth), data=trees)
 
     checkEquals(as.numeric(flm$coefficients), as.numeric(coef(fit)),



More information about the Rcpp-commits mailing list