[Rcpp-commits] r4382 - in pkg/Rcpp/inst/unitTests: . cpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 2 12:56:35 CEST 2013


Author: romain
Date: 2013-07-02 12:56:34 +0200 (Tue, 02 Jul 2013)
New Revision: 4382

Modified:
   pkg/Rcpp/inst/unitTests/cpp/Matrix.cpp
   pkg/Rcpp/inst/unitTests/runit.Matrix.R
Log:
using sourceCpp

Modified: pkg/Rcpp/inst/unitTests/cpp/Matrix.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/Matrix.cpp	2013-07-02 10:49:12 UTC (rev 4381)
+++ pkg/Rcpp/inst/unitTests/cpp/Matrix.cpp	2013-07-02 10:56:34 UTC (rev 4382)
@@ -37,7 +37,7 @@
     for( size_t i=0 ; i<4; i++){
         	trace += m(i,i) ;
     }
-    return wrap( trace ) ;
+    return trace;
 }
 
 // [[Rcpp::export]]
@@ -66,7 +66,7 @@
 
 // [[Rcpp::export]]
 NumericMatrix matrix_numeric_ctor2(){
-    return NumericMatrix m(3,3);
+    return NumericMatrix(3,3);
 }
 
 // [[Rcpp::export]]
@@ -89,7 +89,7 @@
 // [[Rcpp::export]]
 double runit_NumericMatrix_row( NumericMatrix m){
     NumericMatrix::Row first_row = m.row(0) ;
-    return wrap( std::accumulate( first_row.begin(), first_row.end(), 0.0 ) ) ;
+    return std::accumulate( first_row.begin(), first_row.end(), 0.0 ) ;
 }
 
 // [[Rcpp::export]]
@@ -115,7 +115,7 @@
 // [[Rcpp::export]]
 double runit_NumericMatrix_column( NumericMatrix m ){
     NumericMatrix::Column col = m.column(0) ;
-    return wrap( std::accumulate( col.begin(), col.end(), 0.0 ) ) ;
+    return std::accumulate( col.begin(), col.end(), 0.0 ) ;
 }
 
 // [[Rcpp::export]]
@@ -135,9 +135,9 @@
 std::string runit_CharacterMatrix_column( CharacterMatrix m){
     CharacterMatrix::Column col = m.column(0) ;
     std::string res(
-    	std::accumulate(
-    		col.begin(), col.end(), std::string() ) ) ;
-    return wrap(res) ;
+        std::accumulate( col.begin(), col.end(), std::string() )
+    ) ;
+    return res ;
 }
 
 // [[Rcpp::export]]

Modified: pkg/Rcpp/inst/unitTests/runit.Matrix.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Matrix.R	2013-07-02 10:49:12 UTC (rev 4381)
+++ pkg/Rcpp/inst/unitTests/runit.Matrix.R	2013-07-02 10:56:34 UTC (rev 4382)
@@ -23,11 +23,9 @@
 
 .setUp <- Rcpp:::unit_test_setup("Matrix.cpp")
 
-
 test.List.column <- function(){
-	funx <- .rcpp.Matrix$runit_Row_Column_sugar
 	x <- matrix( 1:16+.5, nc = 4 )
-	res <- funx( x )
+	res <- runit_Row_Column_sugar( x )
 	target <- list(
 	    x[1,],
 	    x[,1],
@@ -40,129 +38,107 @@
 }
 
 test.NumericMatrix <- function(){
-	funx <- .rcpp.Matrix$matrix_numeric
 	x <- matrix( 1:16 + .5, ncol = 4 )
-	checkEquals( funx(x), sum(diag(x)), msg = "matrix indexing" )
+	checkEquals( matrix_numeric(x), sum(diag(x)), msg = "matrix indexing" )
 
 	y <- as.vector( x )
-	checkException( funx(y) , msg = "not a matrix" )
+	checkException( matrix_numeric(y) , msg = "not a matrix" )
 
 }
 
 test.CharacterMatrix <- function(){
-	funx <- .rcpp.Matrix$matrix_character
 	x <- matrix( letters[1:16], ncol = 4 )
-	checkEquals( funx(x), paste( diag(x), collapse = "" ) )
+	checkEquals( matrix_character(x), paste( diag(x), collapse = "" ) )
 }
 
 test.GenericMatrix <- function( ){
-	funx <- .rcpp.Matrix$matrix_generic
 	g <- function(y){
 		sapply( y, function(x) seq(from=x, to = 16) )
 	}
 	x <- matrix( g(1:16), ncol = 4 )
-	checkEquals( funx(x), g(diag(matrix(1:16,ncol=4))), msg = "GenericMatrix" )
+	checkEquals( matrix_generic(x), g(diag(matrix(1:16,ncol=4))), msg = "GenericMatrix" )
 }
 
 test.IntegerMatrix.diag <- function(){
-	funx <- .rcpp.Matrix$matrix_integer_diag
 	expected <- matrix( 0L, nrow = 5, ncol = 5 )
 	diag( expected ) <- 1L
-	checkEquals( funx(), expected, msg = "IntegerMatrix::diag" )
+	checkEquals( matrix_integer_diag(), expected, msg = "IntegerMatrix::diag" )
 }
 
 test.CharacterMatrix.diag <- function(){
-	funx <- .rcpp.Matrix$matrix_character_diag
 	expected <- matrix( "", nrow = 5, ncol = 5 )
 	diag( expected ) <- "foo"
-	checkEquals( funx(), expected, msg = "CharacterMatrix::diag" )
+	checkEquals( matrix_character_diag(), expected, msg = "CharacterMatrix::diag" )
 }
 
 test.NumericMatrix.Ctors <- function(){
-	funx <- .rcpp.Matrix$matrix_numeric_ctor1
 	x <- matrix(0, 3, 3)
-	checkEquals( funx(), x, msg = "matrix from single int" )
+	checkEquals( matrix_numeric_ctor1(), x, msg = "matrix from single int" )
 
-	funx <- .rcpp.Matrix$matrix_numeric_ctor2
 	x <- matrix(0, 3, 3)
-	checkEquals( funx(), x, msg = "matrix from two int" )
+	checkEquals( matrix_numeric_ctor2(), x, msg = "matrix from two int" )
 }
 
 test.IntegerVector.matrix.indexing <- function(){
-    fun <- .rcpp.Matrix$integer_matrix_indexing
     x <- matrix( 1:16, ncol = 4 )
-    checkEquals( fun(x), sum(diag(x)), msg = "matrix indexing" )
+    checkEquals( integer_matrix_indexing(x), sum(diag(x)), msg = "matrix indexing" )
 
-    fun <- .rcpp.Matrix$integer_matrix_indexing_lhs
-    checkEquals( diag(fun(x)), 2*0:3, msg = "matrix indexing lhs" )
+    checkEquals( diag(integer_matrix_indexing_lhs(x)), 2*0:3, msg = "matrix indexing lhs" )
 
     y <- as.vector( x )
-    checkException( fun(y) , msg = "not a matrix" )
+    checkException( integer_matrix_indexing_lhs(y) , msg = "not a matrix" )
 }
 
-
-
 test.NumericMatrix.row <- function(){
-	funx <- .rcpp.Matrix$runit_NumericMatrix_row
 	x <- matrix( 1:16 + .5, ncol = 4 )
-	checkEquals( funx( x ), sum( x[1,] ), msg = "iterating over a row" )
+	checkEquals( runit_NumericMatrix_row( x ), sum( x[1,] ), msg = "iterating over a row" )
 }
 
 test.CharacterMatrix.row <- function(){
-	funx <- .rcpp.Matrix$runit_CharacterMatrix_row
 	m <- matrix( letters, ncol = 2 )
-	checkEquals( funx(m), paste( m[1,], collapse = "" ), msg = "CharacterVector::Row" )
+	checkEquals( runit_CharacterMatrix_row(m), paste( m[1,], collapse = "" ), msg = "CharacterVector::Row" )
 }
 
 test.List.row <- function(){
-	funx <- .rcpp.Matrix$runit_GenericMatrix_row
 	m <- lapply( 1:16, function(i) seq(from=1, to = i ) )
 	dim( m ) <- c( 4, 4 )
-	checkEquals( funx( m ), 1 + 0:3*4, msg = "List::Row" )
-
+	checkEquals( runit_GenericMatrix_row( m ), 1 + 0:3*4, msg = "List::Row" )
 }
 
 test.NumericMatrix.column <- function(){
-	funx <- .rcpp.Matrix$runit_NumericMatrix_column
 	x <- matrix( 1:16 + .5, ncol = 4 )
-	checkEquals( funx( x ), sum( x[,1] ) , msg = "iterating over a column" )
+	checkEquals( runit_NumericMatrix_column( x ), sum( x[,1] ) , msg = "iterating over a column" )
 }
 
 test.NumericMatrix.cumsum <- function(){
-	funx <- .rcpp.Matrix$runit_NumericMatrix_cumsum
 	x <- matrix( 1:8 + .5, ncol = 2 )
-	checkEquals( funx( x ), t(apply(x, 1, cumsum)) , msg = "cumsum" )
+	checkEquals( runit_NumericMatrix_cumsum( x ), t(apply(x, 1, cumsum)) , msg = "cumsum" )
 }
 
 test.CharacterMatrix.column <- function(){
-	funx <- .rcpp.Matrix$runit_CharacterMatrix_column
 	m <- matrix( letters, ncol = 2 )
-	checkEquals( funx(m), paste( m[,1], collapse = "" ), msg = "CharacterVector::Column" )
+	checkEquals( runit_CharacterMatrix_column(m), paste( m[,1], collapse = "" ), msg = "CharacterVector::Column" )
 }
 
 test.List.column <- function(){
-	funx <- .rcpp.Matrix$runit_GenericMatrix_column
 	m <- lapply( 1:16, function(i) seq(from=1, to = i ) )
 	dim( m ) <- c( 4, 4 )
-	checkEquals( funx( m ), 1:4, msg = "List::Column" )
+	checkEquals( runit_GenericMatrix_column( m ), 1:4, msg = "List::Column" )
 }
 
 test.NumericMatrix.colsum <- function( ){
-    funx <- .rcpp.Matrix$runit_NumericMatrix_colsum
     probs <- matrix(1:12,nrow=3)
-    checkEquals( funx( probs ), t(apply(probs,1,cumsum)) )
+    checkEquals( runit_NumericMatrix_colsum( probs ), t(apply(probs,1,cumsum)) )
 }
 
 test.NumericMatrix.rowsum <- function( ){
-    funx <- .rcpp.Matrix$runit_NumericMatrix_rowsum
     probs <- matrix(1:12,nrow=3)
-    checkEquals( funx( probs ), apply(probs,2,cumsum) )
+    checkEquals( runit_NumericMatrix_rowsum( probs ), apply(probs,2,cumsum) )
 }
 
 test.NumericMatrix.SubMatrix <- function( ){
-    funx <- .rcpp.Matrix$runit_SubMatrix
     target <- rbind( c(3,4,5,5), c(3,4,5,5), 0 )
-    checkEquals( funx(), target, msg = "SubMatrix" )
+    checkEquals( runit_SubMatrix(), target, msg = "SubMatrix" )
 }
 
 



More information about the Rcpp-commits mailing list