[Rcpp-commits] r1809 - pkg/Rcpp/inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 7 15:11:03 CEST 2010


Author: romain
Date: 2010-07-07 15:11:02 +0200 (Wed, 07 Jul 2010)
New Revision: 1809

Removed:
   pkg/Rcpp/inst/unitTests/runit.ComplexVector.R
Modified:
   pkg/Rcpp/inst/unitTests/runit.Vector.R
Log:
merge runit.ComplexVector into runit.Vector

Deleted: pkg/Rcpp/inst/unitTests/runit.ComplexVector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.ComplexVector.R	2010-07-07 13:06:05 UTC (rev 1808)
+++ pkg/Rcpp/inst/unitTests/runit.ComplexVector.R	2010-07-07 13:11:02 UTC (rev 1809)
@@ -1,54 +0,0 @@
-#!/usr/bin/r -t
-#
-# Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
-#
-# This file is part of Rcpp.
-#
-# Rcpp 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.
-#
-# Rcpp 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 Rcpp.  If not, see <http://www.gnu.org/licenses/>.
-
-test.ComplexVector <- function(){
-	funx <- cppfunction(signature(), '
-	ComplexVector x(10) ;
-	Rcomplex rc ;
-	for( int i=0; i<10; i++) {
-		rc.r = rc.i = i + 0.0 ;
-		x[i] = rc ;
-	}
-	return x ;'  )
-	checkEquals( funx(), 0:9*(1+1i), msg = "ComplexVector" )
-}
-
-test.ComplexVector.INTSXP <- function(){
-	funx <- cppfunction(signature(vec = "complex" ), '
-	ComplexVector x(vec) ;
-	for( int i=0; i<x.size(); i++) { 
-		x[i].r = x[i].r*2 ;
-		x[i].i = x[i].i*2 ;
-	}
-	return x ;'  )
-	checkEquals( funx(0:9*(1+1i)), 2*0:9*(1+1i), msg = "ComplexVector( CPLXSXP) " )
-}
-
-test.ComplexVector.initializer.list <- function(){
-	if( Rcpp:::capabilities()[["initializer lists"]] ){
-		funx <- cppfunction(signature(), '
-		Rcomplex c1 ; c1.r = c1.i = 0.0 ;
-		Rcomplex c2 ; c2.r = c2.i = 1.0 ;
-		ComplexVector x = { c1, c2 } ;
-		return x ;', cxxargs = "-std=c++0x" )
-		checkEquals( funx(), c( 0:1*(1+1i)), msg = "ComplexVector( initializer list) " )
-	}
-}
-
-

Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R	2010-07-07 13:06:05 UTC (rev 1808)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R	2010-07-07 13:11:02 UTC (rev 1809)
@@ -85,12 +85,35 @@
 				ExpressionVector code( "sort(x)" ) ;
 				return code.eval(env) ;
 				' 
+        	), 
+        	"complex_" = list( 
+        		signature(), 
+        		'
+				ComplexVector x(10) ;
+				Rcomplex rc ;
+				for( int i=0; i<10; i++) {
+					rc.r = rc.i = i + 0.0 ;
+					x[i] = rc ;
+				}
+				return x ;
+				'
+        	), 
+        	"complex_INTSXP" = list( 
+        		signature(vec = "complex" ), 
+        		'
+				ComplexVector x(vec) ;
+				for( int i=0; i<x.size(); i++) { 
+					x[i].r = x[i].r*2 ;
+					x[i].i = x[i].i*2 ;
+				}
+				return x ;
+				'
         	)
         	
         )
 
         if (Rcpp:::capabilities()[["initializer lists"]]) {
-        	g <- list(
+        	g <- list( 
         		"raw_initializer_list"=list(
         			signature(), 
         			'
@@ -98,6 +121,15 @@
 					for( int i=0; i<x.size(); i++) x[i] = x[i]*2 ;
 					return x ;
 					'
+        		), 
+        		"complex_initializer_list" = list( 
+        			signature(), 
+        			'
+					Rcomplex c1 ; c1.r = c1.i = 0.0 ;
+					Rcomplex c2 ; c2.r = c2.i = 1.0 ;
+					ComplexVector x = { c1, c2 } ;
+					return x ;
+					'
         		)
         	)
         	f <- c(f,g)
@@ -169,4 +201,20 @@
 	e[["x"]] <- sample(1:10)
 	checkEquals( funx(e), 1:10, msg = "ExpressionVector::eval in specific environment" )
 }
+         
+test.ComplexVector <- function(){
+	funx <- .rcpp.Vector$complex_
+	checkEquals( funx(), 0:9*(1+1i), msg = "ComplexVector" )
+}
 
+test.ComplexVector.INTSXP <- function(){
+	funx <- .rcpp.Vector$complex_INTSXP
+	checkEquals( funx(0:9*(1+1i)), 2*0:9*(1+1i), msg = "ComplexVector( CPLXSXP) " )
+}
+if( Rcpp:::capabilities()[["initializer lists"]] ){
+	test.ComplexVector.initializer.list <- function(){
+		funx <- .rcpp.Vector$complex_initializer_list
+		checkEquals( funx(), c( 0:1*(1+1i)), msg = "ComplexVector( initializer list) " )
+	}
+}
+



More information about the Rcpp-commits mailing list