[Rcpp-commits] r4053 - in pkg/Rcpp: . inst/unitTests inst/unitTests/cpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 29 19:01:09 CET 2012
Author: romain
Date: 2012-11-29 19:01:09 +0100 (Thu, 29 Nov 2012)
New Revision: 4053
Added:
pkg/Rcpp/inst/unitTests/cpp/DataFrame.cpp
Removed:
pkg/Rcpp/inst/unitTests/cpp/reg_tests_0_10_1.cpp
pkg/Rcpp/inst/unitTests/runit.reg_0_10_1.R
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/unitTests/runit.DataFrame.R
pkg/Rcpp/inst/unitTests/runit.Vector.R
pkg/Rcpp/inst/unitTests/runit.misc.R
Log:
using sourceCpp in runit.Vector tests
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-11-29 18:00:37 UTC (rev 4052)
+++ pkg/Rcpp/ChangeLog 2012-11-29 18:01:09 UTC (rev 4053)
@@ -1,3 +1,8 @@
+2012-11-29 Romain Francois <romain at r-enthusiasts.com>
+
+ * unitTests/runit.DataFrame.R: using sourceCpp
+ * include/Rcpp/vector/Matrix.h: fix yet another const correctness issue
+
2012-11-27 Dirk Eddelbuettel <edd at debian.org>
* inst/include/Rcpp/iostream/Rostream.h: Check before deleting buf
Added: pkg/Rcpp/inst/unitTests/cpp/DataFrame.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/DataFrame.cpp (rev 0)
+++ pkg/Rcpp/inst/unitTests/cpp/DataFrame.cpp 2012-11-29 18:01:09 UTC (rev 4053)
@@ -0,0 +1,91 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// DataFrame.cpp: Rcpp R/C++ interface class library -- DataFrame unit tests
+//
+// Copyright (C) 2012 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/>.
+
+#include <Rcpp.h>
+using namespace Rcpp ;
+
+// [[Rcpp::export]]
+DataFrame FromSEXP( SEXP x){
+ DataFrame df(x) ;
+ return df;
+}
+
+// [[Rcpp::export]]
+SEXP index_byName( DataFrame df, std::string s ){
+ return df[s];
+}
+
+// [[Rcpp::export]]
+SEXP index_byPosition( DataFrame df, int i ){
+ return df[i];
+}
+// [[Rcpp::export]]
+std::string string_element( DataFrame df ){
+ CharacterVector b = df[1];
+ std::string s;
+ s = b[1];
+ return s;
+}
+
+// [[Rcpp::export]]
+DataFrame createOne(){
+ IntegerVector v = IntegerVector::create(1,2,3);
+ return DataFrame::create(Named("a")=v);
+}
+
+// [[Rcpp::export]]
+DataFrame createTwo(){
+ IntegerVector v = IntegerVector::create(1,2,3);
+ std::vector<std::string> s(3);
+ s[0] = "a";
+ s[1] = "b";
+ s[2] = "c";
+ return DataFrame::create(Named("a")=v, Named("b")=s);
+}
+
+// [[Rcpp::export]]
+DataFrame SlotProxy( S4 o, std::string yy ){
+ return DataFrame( o.slot( yy ) ) ;
+}
+
+// [[Rcpp::export]]
+DataFrame AttributeProxy( List o, std::string y ){
+ return DataFrame( o.attr( y )) ;
+}
+
+// [[Rcpp::export]]
+DataFrame createTwoStringsAsFactors(){
+ IntegerVector v = IntegerVector::create(1,2,3);
+ std::vector<std::string> s(3);
+ s[0] = "a";
+ s[1] = "b";
+ s[2] = "c";
+ return DataFrame::create(
+ _["a"] = v,
+ _["b"] = s,
+ _["stringsAsFactors"] = false );
+}
+
+// [[Rcpp::export]]
+int DataFrame_nrows( DataFrame df){
+ return df.nrows() ;
+}
+
Deleted: pkg/Rcpp/inst/unitTests/cpp/reg_tests_0_10_1.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/reg_tests_0_10_1.cpp 2012-11-29 18:00:37 UTC (rev 4052)
+++ pkg/Rcpp/inst/unitTests/cpp/reg_tests_0_10_1.cpp 2012-11-29 18:01:09 UTC (rev 4053)
@@ -1,8 +0,0 @@
-#include <Rcpp.h>
-using namespace Rcpp ;
-
-// [[Rcpp::export]]
-int DataFrame_nrows( DataFrame df){
- return df.nrows() ;
-}
-
Modified: pkg/Rcpp/inst/unitTests/runit.DataFrame.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.DataFrame.R 2012-11-29 18:00:37 UTC (rev 4052)
+++ pkg/Rcpp/inst/unitTests/runit.DataFrame.R 2012-11-29 18:01:09 UTC (rev 4053)
@@ -22,142 +22,65 @@
if (.runThisTest) {
-definitions <- function(){
- list("FromSEXP"=list(
- signature(x="ANY"),
- 'DataFrame df(x) ;
- return df;')
-
- ,"index_byName"=list(
- signature(x='ANY', y='character'),
- 'DataFrame df(x);
- std::string s = as<std::string>(y);
- return df[s];')
-
- ,"index_byPosition"=list(
- signature(x='ANY', y='integer'),
- 'DataFrame df(x);
- int i = as<int>(y);
- return df[i]; ')
-
- ,"string_element"=list(
- signature(x='ANY'),
- 'DataFrame df(x);
- CharacterVector b = df[1];
- std::string s;
- s = b[1];
- return wrap(s); ')
-
- ,"createOne"=list(
- signature(),
- 'IntegerVector v = IntegerVector::create(1,2,3);
- return DataFrame::create(Named("a")=v); ')
-
- ,"createTwo"=list(
- signature(),
- 'IntegerVector v = IntegerVector::create(1,2,3);
- std::vector<std::string> s(3);
- s[0] = "a";
- s[1] = "b";
- s[2] = "c";
- return DataFrame::create(Named("a")=v, Named("b")=s); ')
-
- ,"SlotProxy"=list(
- signature(x="ANY", y="character"),
- '
- S4 o(x) ;
- std::string yy = as<std::string>( y ) ;
- return DataFrame( o.slot( yy ) ) ;
- ')
-
- ,"AttributeProxy"=list(
- signature(x="ANY", y="character"),
- 'List o(x) ;
- return DataFrame( o.attr( as<std::string>(y) )) ; ')
-
- ,"createTwoStringsAsFactors"=list(
- signature(),
- 'IntegerVector v = IntegerVector::create(1,2,3);
- std::vector<std::string> s(3);
- s[0] = "a";
- s[1] = "b";
- s[2] = "c";
- return DataFrame::create(
- _["a"] = v,
- _["b"] = s,
- _["stringsAsFactors"] = false ); ')
-
- )
-
-}
-
.setUp <- function(){
suppressMessages( require( datasets ) )
data( iris )
- tests <- ".Rcpp.DataFrame"
- if( ! exists(tests, globalenv() )) {
- fun <- Rcpp:::compile_unit_tests( definitions() )
- assign( tests, fun, globalenv() )
- }
+ sourceCpp( system.file( "unitTests/cpp/DataFrame.cpp" , package = "Rcpp" ) )
}
test.DataFrame.FromSEXP <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"))
- fun <- .Rcpp.DataFrame$FromSEXP
- checkEquals( fun(DF), DF, msg = "DataFrame pass-through")
+ checkEquals( FromSEXP(DF), DF, msg = "DataFrame pass-through")
}
test.DataFrame.index.byName <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"))
- fun <- .Rcpp.DataFrame$index_byName
- checkEquals( fun(DF, "a"), DF$a, msg = "DataFrame column by name 'a'")
- checkEquals( fun(DF, "b"), DF$b, msg = "DataFrame column by name 'b'")
+ checkEquals( index_byName(DF, "a"), DF$a, msg = "DataFrame column by name 'a'")
+ checkEquals( index_byName(DF, "b"), DF$b, msg = "DataFrame column by name 'b'")
}
test.DataFrame.index.byPosition <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"))
- fun <- .Rcpp.DataFrame$index_byPosition
- checkEquals( fun(DF, 0), DF$a, msg = "DataFrame column by position 0")
- checkEquals( fun(DF, 1), DF$b, msg = "DataFrame column by position 1")
+ checkEquals( index_byPosition(DF, 0), DF$a, msg = "DataFrame column by position 0")
+ checkEquals( index_byPosition(DF, 1), DF$b, msg = "DataFrame column by position 1")
}
test.DataFrame.string.element <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"), stringsAsFactors=FALSE)
- fun <- .Rcpp.DataFrame$string_element
- checkEquals( fun(DF), DF[2,"b"], msg = "DataFrame string element")
+ checkEquals( string_element(DF), DF[2,"b"], msg = "DataFrame string element")
}
test.DataFrame.CreateOne <- function() {
DF <- data.frame(a=1:3)
- fun <- .Rcpp.DataFrame$createOne
- checkEquals( fun(), DF, msg = "DataFrame create1")
+ checkEquals( createOne(), DF, msg = "DataFrame create1")
}
test.DataFrame.CreateTwo <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"))
- fun <- .Rcpp.DataFrame$createTwo
- checkEquals( fun(), DF, msg = "DataFrame create2")
+ checkEquals( createTwo(), DF, msg = "DataFrame create2")
}
test.DataFrame.SlotProxy <- function(){
setClass("track", representation(x="data.frame", y = "function"))
tr1 <- new( "track", x = iris, y = rnorm )
- fun <- .Rcpp.DataFrame$SlotProxy
- checkTrue( identical( fun(tr1, "x"), iris ), msg = "DataFrame( SlotProxy )" )
- checkException( fun(tr1, "y"), msg = "DataFrame( SlotProxy ) -> exception" )
+ checkTrue( identical( SlotProxy(tr1, "x"), iris ), msg = "DataFrame( SlotProxy )" )
+ checkException( SlotProxy(tr1, "y"), msg = "DataFrame( SlotProxy ) -> exception" )
}
test.DataFrame.AttributeProxy <- function(){
tr1 <- structure( NULL, x = iris, y = rnorm )
- fun <- .Rcpp.DataFrame$AttributeProxy
- checkTrue( identical( fun(tr1, "x"), iris) , msg = "DataFrame( AttributeProxy )" )
- checkException( fun(tr1, "y"), msg = "DataFrame( AttributeProxy ) -> exception" )
+ checkTrue( identical( AttributeProxy(tr1, "x"), iris) , msg = "DataFrame( AttributeProxy )" )
+ checkException( AttributeProxy(tr1, "y"), msg = "DataFrame( AttributeProxy ) -> exception" )
}
test.DataFrame.CreateTwo.stringsAsFactors <- function() {
DF <- data.frame(a=1:3, b=c("a","b","c"), stringsAsFactors = FALSE )
- fun <- .Rcpp.DataFrame$createTwoStringsAsFactors
- checkEquals( fun(), DF, msg = "DataFrame create2 stringsAsFactors = false")
+ checkEquals( createTwoStringsAsFactors(), DF, msg = "DataFrame create2 stringsAsFactors = false")
}
+test.DataFrame.nrows <- function(){
+ checkEquals( DataFrame_nrows( iris ), nrow(iris) )
}
+
+
+}
Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R 2012-11-29 18:00:37 UTC (rev 4052)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R 2012-11-29 18:01:09 UTC (rev 4053)
@@ -22,786 +22,22 @@
if (.runThisTest) {
-definitions <- function(){
- f <- list(
- "raw_" = list(
- signature(),
- '
- RawVector x(10) ;
- for( int i=0; i<10; i++) x[i] = (Rbyte)i ;
- return x ;
- '
- ),
-
- "raw_REALSXP" = list(
- signature(vec = "raw" ),
- '
- RawVector x(vec) ;
- for( int i=0; i<x.size(); i++) {
- x[i] = x[i]*2 ;
- }
- return x ;
- '
- ),
-
- "expression_" = list(
- signature(),
- '
- ExpressionVector x(2) ;
- x[0] = Symbol( "rnorm" ) ;
- x[1] = Rf_lcons( Symbol("rnorm"), Rf_cons( Rf_ScalarReal(10.0), R_NilValue) ) ;
- return x ;
- '
- ),
-
- "expression_variadic" = list(
- signature(),
- '
- ExpressionVector x(2) ;
- x[0] = Symbol( "rnorm" ) ;
- x[1] = Language( "rnorm", 10.0 ) ;
- return x ;
- '
- ),
-
- "expression_parse" = list(
- signature(),
- '
- ExpressionVector code( "local( { y <- sample(1:10); sort(y) })" ) ;
- return code ;
- '
- ),
-
- "expression_parseerror" = list(
- signature(),
- '
- ExpressionVector code( "rnorm(" ) ;
- return code ;
- '
- ),
-
- "expression_eval" = list(
- signature(),
- '
- ExpressionVector code( "local( { y <- sample(1:10); sort(y) })" ) ;
- return code.eval() ;
- '
- ),
-
- "expression_evalenv" = list(
- signature(env = "environment"),
- '
- 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_CPLXSXP" = list(
- signature(vec = "complex" ),
- '
- ComplexVector x(vec) ;
- int nn = x.size();
- for( int i=0; i<nn; i++) {
- x[i].r = x[i].r*2 ;
- x[i].i = x[i].i*2 ;
- }
- return x ;
- '
- ),
-
- "complex_INTSXP" = list(
- signature(vec = "integer" ),
- '
- ComplexVector x(vec);
- int nn = x.size();
- IntegerVector tmp(nn, 2.0);
- ComplexVector tmp1(tmp);
- x = x * tmp1;
- return x ;
- '
- ),
-
- "complex_REALSXP" = list(
- signature(vec = "numeric" ),
- '
- ComplexVector x(vec);
- int nn = x.size();
- NumericVector tmp(nn, 3.0);
- ComplexVector tmp1(tmp);
- x = x * tmp1;
- return x ;
- '
- ),
-
- "integer_ctor"=list(
- signature(),
- 'IntegerVector x(10) ;
- for( int i=0; i<10; i++) x[i] = i ;
- return x ;'
- ),
-
- "integer_INTSXP_"=list(
- signature(vec = "integer" ),
- 'IntegerVector x(vec) ;
- for( int i=0; i<x.size(); i++) {
- x[i] = x[i]*2 ;
- }
- return x ;'
- ),
-
- "integer_dimension_ctor_1"=list(
- signature(),
- 'return IntegerVector( Dimension( 5 ) ) ;'
- ),
-
- "integer_dimension_ctor_2"=list(
- signature(),
- 'return IntegerVector( Dimension( 5, 5 ) ) ;'
- ),
-
- "integer_dimension_ctor_3"=list(
- signature(),
- 'return IntegerVector( Dimension( 2, 3, 4) ) ;'
- ),
-
- "integer_range_ctor_1"=list(
- signature(),
- 'int x[] = { 0, 1, 2, 3 } ;
- IntegerVector y( x, x+4 ) ;
- return y; '
- ),
-
- "integer_range_ctor_2"=list(
- signature(),
- 'std::vector<int> vec(4) ;
- for( size_t i = 0; i<4; i++) vec[i] = i;
- IntegerVector y( vec.begin(), vec.end() ) ;
- return y;'
- ),
-
- "integer_names_set"=list(
- signature(),
- 'IntegerVector y(2) ;
- std::vector<std::string> names(2) ;
- names[0] = "foo" ;
- names[1] = "bar" ;
- y.names() = names ;
- return y ; '
- ),
-
- "integer_names_get"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- return y.names() ;'
- ),
-
- "integer_names_indexing"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- return wrap( y["foo"] ); '
- ),
-
- "integer_comma"=list(
- signature(),
- 'IntegerVector x(4) ;
- x = 0, 1, 2, 3 ;
- return x ;'
- ),
-
- "integer_push_back"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.push_back( 5 ) ;
- return y ;'
- ),
-
- "integer_push_front"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.push_front( 5 ) ;
- return y ;'
- ),
-
- "integer_insert"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.insert( 0, 5 ) ;
- y.insert( 2, 7 ) ;
- return y ;'
- ),
-
- "integer_erase"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.erase(2) ;
- return y ;'
- ),
-
- "integer_erase2"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.erase(1,2) ;
- return y ;'
- ),
-
- "integer_fill"=list(
- signature(x = "integer"),
- 'IntegerVector y(x) ;
- y.fill(10) ;
- return y ;'
- ),
-
- "integer_zero"=list(
- signature(),
- 'return IntegerVector(0);'
- ),
-
- "integer_create_zero"=list(
- signature(),
- 'return IntegerVector::create();'
- ),
-
- "integer_create_" = list(
- signature(),
- '
- List output(2);
- output[0] = IntegerVector::create( 10, 20 ) ;
- output[1] = IntegerVector::create(
- _["foo"] = 20,
- _["bar"] = 30 ) ;
- return output ;
- '
- ),
-
- "integer_clone_" = list(
- signature(x="integer"),
- '
- IntegerVector vec(x) ;
- IntegerVector dolly = clone( vec ) ;
- for( size_t i=0; i<10; i++){
- dolly[i] = 10 - i ;
- }
- return dolly ;
- '
- ),
-
-
- "numeric_" = list(
- signature(),
- '
- NumericVector x(10) ;
- for( int i=0; i<10; i++) x[i] = i ;
- return x ;
- '
- ),
-
- "numeric_REALSXP" = list(
- signature(vec = "numeric" ),
- '
- NumericVector x(vec) ;
- for( int i=0; i<x.size(); i++) {
- x[i] = x[i]*2.0 ;
- }
- return x ;
- '
- ),
-
- "numeric_import" = list(
- signature(),
- '
- std::vector<int> v(10) ;
- for( int i=0; i<10; i++) v[i] = i ;
-
- return IntegerVector::import( v.begin(), v.end() ) ;
-
- '
- ),
-
- "numeric_importtransform" = list(
- signature(),
- '
- std::vector<double> v(10) ;
- for( int i=0; i<10; i++) v[i] = i ;
-
- return NumericVector::import_transform( v.begin(), v.end(), square ) ;
-
- '
- ),
-
- "list_ctor"=list(
- signature(),
- 'List x(10) ;
- for( int i=0; i<10; i++) x[i] = Rf_ScalarInteger( i * 2) ;
- return x ;'
- ),
-
- "list_template_"=list(
- signature(),
- 'List x(4) ;
- x[0] = "foo" ;
- x[1] = 10 ;
- x[2] = 10.2 ;
- x[3] = false;
- return x ;'
- ),
-
- "list_VECSXP_"=list(
- signature(vec = "list" ),
- 'List x(vec) ;
- return x ;'
- ),
-
- "list_matrix_indexing_1"=list(
- signature(x = "character" ),
- 'GenericVector m(x) ;
- GenericVector out(4) ;
- for( size_t i=0 ; i<4; i++){
- out[i] = m(i,i) ;
- }
- return out ;'
- ),
-
- "list_matrix_indexing_2"=list(
- signature(x = "integer" ),
- 'GenericVector m(x) ;
- for(size_t i=0 ; i<4; i++){
- m(i,i) = "foo" ;
- }
- return m ; '
- ),
-
- "list_Dimension_constructor_1"=list(
- signature(),
- 'return List( Dimension( 5 ) ) ;'
- ),
-
- "list_Dimension_constructor_2"=list(
- signature(),
- 'return List( Dimension( 5, 5 ) );'
- ),
-
- "list_Dimension_constructor_3"=list(
- signature(),
- ' return List( Dimension( 2, 3, 4) ) ;'
- ),
-
- "list_iterator_"=list(
- signature(x = "list", g = "function" ),
- 'Function fun(g) ;
- List input(x) ;
- List output( input.size() ) ;
- std::transform( input.begin(), input.end(), output.begin(), fun ) ;
- output.names() = input.names() ;
- return output ; '
- ),
-
- "list_name_indexing"=list(
- signature(x = "data.frame"),
- 'List df(x) ;
- IntegerVector df_x = df["x"] ;
- int res = std::accumulate( df_x.begin(), df_x.end(), 0 ) ;
- return wrap(res); '
- ),
-
- "list_push_back"=list(
- signature(x = "list"),
- 'List list(x) ;
- list.push_back( 10 ) ;
- list.push_back( "bar", "foo" ) ;
- return list ;
- '
- ),
-
- "list_push_front"=list(
- signature(x = "list"),
- 'List list(x) ;
- list.push_front( 10 ) ;
- list.push_front( "bar", "foo" ) ;
- return list ; '
- ),
-
- "list_erase"=list(
- signature(x = "list"),
- 'List list(x) ;
- list.erase( list.begin() ) ;
- return list ; '
- ),
-
- "list_erase_range"=list(
- signature(x = "list"),
- 'List list(x) ;
- list.erase( 0, 1 ) ;
- return list ; '
- ),
-
- "list_implicit_push_back"=list(
- signature(),
- 'List list ;
- list["foo"] = 10 ;
- list["bar" ] = "foobar" ;
- return list ;
- '
- ),
-
- "list_create_" = list(
- signature(),
- '
- List output(2);
- output[0] = List::create( 10, "foo" ) ;
- output[1] = List::create(
- _["foo"] = 10,
- _["bar"] = true ) ;
- return output ;
- '
- ),
-
- "list_stdcomplex" = list(
- signature() , '
- std::vector< std::complex<double> > v_double(10) ;
- std::vector< std::complex<float> > v_float(10) ;
- return List::create( _["float"] = v_float, _["double"] = v_double ) ;
- '
- ),
-
- "character_ctor"=list(
- signature(),
- 'CharacterVector x(10) ;
- for( int i=0; i<10; i++) x[i] = "foo" ;
- return x ;'
- ),
-
- "character_STRSXP_"=list(
- signature(vec = "character" ),
- 'CharacterVector x(vec) ;
- std::string st = "" ;
- for( int i=0; i<x.size(); i++) {
- st += x[i] ;
- }
- return wrap( st ) ;'
- ),
-
- "character_plusequals"=list(
- signature(),
- 'CharacterVector x(2) ;
- x[0] = "foo" ;
- x[1] = "bar" ;
- x[0] += "bar" ;
- x[1] += x[0] ;
- return x ;'
- ),
-
- "character_matrix_indexing"=list(
- signature(x = "character" ),
- 'CharacterVector m(x) ;
- std::string trace;
- for( size_t i=0 ; i<4; i++){
- trace += m(i,i) ;
- }
- return wrap( trace ) ;'
- ),
-
- "character_matrix_indexing_lhs"=list(
- signature(x = "integer" ),
- 'CharacterVector m(x) ;
- for( size_t i=0 ; i<4; i++){
- m(i,i) = "foo" ;
- }
- return m ;'),
-
- "character_assign1"=list(
- signature(),
- 'const char* x[] = { "foo", "bar", "bling", "boom" } ;
- CharacterVector y ;
- y.assign( x, x+4 ) ;
- return y;'
- ),
-
- "character_assign2"=list(
- signature(),
- 'std::vector<std::string> vec(4) ;
- vec[0] = "foo";
- vec[1] = "bar";
- vec[2] = "bling";
- vec[3] = "boom" ;
- CharacterVector y ;
- y.assign( vec.begin(), vec.end() ) ;
- return y;'
- ),
-
- "character_range_ctor1"=list(
- signature(),
- 'const char* x[] = { "foo", "bar", "bling", "boom" } ;
- CharacterVector y( x, x+4 ) ;
- return y;'
- ),
-
- "character_range_ctor2"=list(
- signature(),
- 'std::vector<std::string> vec(4) ;
- vec[0] = "foo";
- vec[1] = "bar";
- vec[2] = "bling";
- vec[3] = "boom" ;
- CharacterVector y( vec.begin(), vec.end() ) ;
- return y; '
- ),
-
- "character_dimension_ctor1"=list(
- signature(),
- 'return CharacterVector( Dimension( 5 ) ) ;'
- ),
-
- "character_dimension_ctor2"=list(
- signature(),
- 'return CharacterVector( Dimension( 5, 5 ) ) ;'
- ),
-
- "character_dimension_ctor3"=list(
- signature(),
- 'return CharacterVector( Dimension( 2, 3, 4) ) ;'
- ),
-
- "character_iterator1"=list(
- signature(x = "character"),
- 'CharacterVector letters(x) ;
- std::string res ;
- CharacterVector::iterator first = letters.begin() ;
- CharacterVector::iterator last = letters.end() ;
- while( first != last ){
- res += *first ;
- ++first ;
- }
- return wrap(res) ;'
- ),
-
- "character_iterator2"=list(
- signature(x = "character"),
- 'CharacterVector letters(x) ;
- std::string res(std::accumulate(letters.begin(), letters.end(), std::string()));
- return wrap(res) ;'
- ),
-
- "character_reverse"=list(
- signature(x = "character"),
- 'CharacterVector y(x) ;
- std::reverse( y.begin(), y.end() ) ;
- return y ;'
- ),
-
- "character_names_indexing"=list(
- signature(x = "character"),
- 'CharacterVector y(x) ;
- std::string foo( y["foo"] ) ;
- return wrap(foo) ;'
- ),
-
- "character_comma"=list(
- signature(),
- 'CharacterVector x(3) ;
- x = "foo", "bar", "bling" ;
- return x ;'
- ),
-
- "character_listOf"=list(
- signature(l = "list"),
- 'List ll(l);
- CharacterVector cv1 = ll["foo"];
- CharacterVector cv2 = ll["bar"];
- std::string rv1 = std::string(cv1[0]) + cv1[1] + cv1[2];
- std::string rv2 = std::string(cv2[0]) + cv2[1] + cv2[2];
- return List::create(_["foo"] = rv1, _["bar"] = rv2); '
- ),
-
- "character_find_"=list(
- signature(x = "character"),
- 'CharacterVector y(x) ;
- CharacterVector::iterator it = std::find( y.begin(), y.end(), "foo" ) ;
- return wrap( std::distance( y.begin(), it )); '
-
- ),
-
- "character_create_" = list(
- signature(),
- '
- List output(2);
- output[0] = CharacterVector::create( "foo", "bar" ) ;
- output[1] = CharacterVector::create(
- _["foo"] = "bar",
- _["bar"] = "foo"
- ) ;
- return output ;
- '
- ),
-
- "complex_binary_sugar" = list(
- signature( x = "complex", y = "complex" ),
- '
- ComplexVector xx(x), yy(y) ;
- return List::create(
- _["+"] = xx + yy,
- _["-"] = xx - yy,
- _["*"] = xx * yy,
- _["/"] = xx / yy
- ) ;
-
- '
- ),
-
- "List_extract" = list(
- signature( x = "list" ),
- '
- List input(x) ;
- bool a = input[0] ;
- int b = input[1] ;
- return List::create(a, b) ;
- '
- ),
-
- "factors" = list(
- signature( x = "factor" ),
- '
- StringVector s(x) ;
- return s;
- '
- ),
-
- "IntegerVector_int_init" = list(
- signature(),
- '
- IntegerVector x(2,4) ;
- return x ;
- '
- ),
-
- "containsElementNamed" = list(
- signature(ls="list", ns="character"),
- '
- List l(ls);
- CharacterVector n(ns);
-
- return wrap(l.containsElementNamed(n[0]));
- '
- )
- )
-
- if (Rcpp:::capabilities()[["initializer lists"]]) {
- g <- list(
- "raw_initializer_list"=list(
- signature(),
- '
- RawVector x = {0,1,2,3} ;
- 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 ;
- '
- ),
-
-
- "integer_initializer_list"=list(
- signature(),
- '
- IntegerVector x = {0,1,2,3} ;
- for( int i=0; i<x.size(); i++) x[i] = x[i]*2 ;
- return x ;
- '
- ),
-
- "numeric_initlist" = list(
- signature(),
- '
- NumericVector x = {0.0,1.0,2.0,3.0} ;
- for( int i=0; i<x.size(); i++) x[i] = x[i]*2 ;
- return x ;
- '
- ),
-
- "list_initializer_list"=list(
- signature(),
- 'SEXP x0 = PROTECT( Rf_ScalarInteger( 0 ) ) ;
- SEXP x1 = PROTECT( Rf_ScalarInteger( 1 ) ) ;
- SEXP x2 = PROTECT( Rf_ScalarInteger( 2 ) ) ;
- List x = { x0, x1, x2} ;
- UNPROTECT(3) ;
- return x ;'
- ),
-
-
- "character_initializer_list"=list(
- signature(),
- 'CharacterVector x = {"foo", "bar"} ;
- return x ;'
- )
-
-
- )
- f <- c(f,g)
- }
- f
-}
-
-includes <- function(){
-"
- inline double square( double x){ return x*x; }
-"
-}
-
-cxxargs <- function(){
- ifelse(Rcpp:::capabilities()[["initializer lists"]],"-std=c++0x","")
-}
-
.setUp <- function() {
- tests <- ".rcpp.Vector"
- if( ! exists( tests, globalenv() )) {
- fun <- Rcpp:::compile_unit_tests(
- definitions(),
- includes = includes(),
- cxxargs = cxxargs()
- )
- assign( tests, fun, globalenv() )
- }
+ sourceCpp( system.file( "unitTests/cpp/Vector.cpp", package = "Rcpp" ) )
}
test.RawVector <- function(){
- funx <- .rcpp.Vector$raw_
+ funx <- raw_
checkEquals( funx(), as.raw(0:9), msg = "RawVector(int)" )
}
test.RawVector.REALSXP <- function(){
- funx <- .rcpp.Vector$raw_REALSXP
+ funx <- raw_REALSXP
checkEquals( funx(as.raw(0:9)), as.raw(2*0:9), msg = "RawVector( RAWSXP) " )
}
-if( Rcpp:::capabilities()[["initializer lists"]] ){
- test.RawVector.initializer.list <- function(){
- funx <- .rcpp.Vector$raw_initializer_list
- checkEquals( funx(), as.raw(2*0:3), msg = "RawVector( initializer list) " )
- }
-}
-
test.ExpressionVector <- function(){
- funx <- .rcpp.Vector$expression_
+ funx <- expression_
ex <- parse( text = "rnorm; rnorm(10)" )
# get rid of the srcref stuff so that we can compare
# more easily
@@ -810,134 +46,121 @@
}
test.ExpressionVector.variadic <- function(){
- funx <- .rcpp.Vector$expression_variadic
+ funx <- expression_variadic
ex <- parse( text = "rnorm; rnorm(10)" )
attributes(ex) <- NULL
checkEquals( funx(), ex , msg = "ExpressionVector (using variadic templates) " )
}
test.ExpressionVector.parse <- function( ){
- funx <- .rcpp.Vector$expression_parse
+ funx <- expression_parse
code <- funx()
results <- eval( code )
checkEquals( results, 1:10, msg = "ExpressionVector parsing" )
}
test.ExpressionVector.parse.error <- function(){
- funx <- .rcpp.Vector$expression_parseerror
+ funx <- expression_parseerror
checkException( funx(), msg = "parse error" )
}
test.ExpressionVector.eval <- function(){
- funx <- .rcpp.Vector$expression_eval
+ funx <- expression_eval
checkEquals( funx(), 1:10, msg = "ExpressionVector::eval" )
}
test.ExpressionVector.eval.env <- function(){
- funx <- .rcpp.Vector$expression_evalenv
+ funx <- expression_evalenv
e <- new.env()
e[["x"]] <- sample(1:10)
checkEquals( funx(e), 1:10, msg = "ExpressionVector::eval in specific environment" )
}
test.ComplexVector <- function(){
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 4053
More information about the Rcpp-commits
mailing list