[Rcpp-commits] r3768 - in pkg/Rcpp: . inst/unitTests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Sep 8 21:39:00 CEST 2012
Author: edd
Date: 2012-09-08 21:39:00 +0200 (Sat, 08 Sep 2012)
New Revision: 3768
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/unitTests/runit.sugarOps.R
Log:
more sugar unit tests
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-09-07 13:39:34 UTC (rev 3767)
+++ pkg/Rcpp/ChangeLog 2012-09-08 19:39:00 UTC (rev 3768)
@@ -1,7 +1,11 @@
-2012-09-07 Dirk Eddelbuettel <edd at dexter>
+2012-09-08 Dirk Eddelbuettel <edd at debian.org>
+ * inst/unitTests/runit.sugarOps.R: More sugar Ops unit tests
+
+2012-09-07 Dirk Eddelbuettel <edd at debian.org>
+
* inst/unitTests/runit.sugarOps.R: (Incomplete) beginnings of new
- unit test file for sugar operations on vectors and matrices
+ unit test file for sugar operations on vectors and matrices
2012-09-07 Romain Francois <romain at r-enthusiasts.com>
Modified: pkg/Rcpp/inst/unitTests/runit.sugarOps.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.sugarOps.R 2012-09-07 13:39:34 UTC (rev 3767)
+++ pkg/Rcpp/inst/unitTests/runit.sugarOps.R 2012-09-08 19:39:00 UTC (rev 3768)
@@ -20,22 +20,51 @@
definitions <- function() {
list(
- "vector_plus" = list(signature(x = "numeric"),
+ "vector_scalar_ops" = list(signature(x = "numeric"),
'
NumericVector xx(x);
- NumericVector yy = xx + 2;
- return yy;
+ NumericVector y1 = xx + 2;
+ NumericVector y2 = 2 - xx;
+ NumericVector y3 = xx * 2.0;
+ NumericVector y4 = 2.0 / xx;
+ return List::create(y1, y2, y3, y4);
'
)
- ,
- "matrix_plus" = list(signature(x = "numeric"),
+
+ ,
+ "vector_scalar_logical" = list(signature(x = "numeric"),
+ '
+ NumericVector xx(x);
+ LogicalVector y1 = xx < 2;
+ LogicalVector y2 = 2 > xx;
+ LogicalVector y3 = xx <= 2;
+ LogicalVector y4 = 2 != xx;
+ return List::create(y1, y2, y3, y4);
'
- NumericMatrix xx(x);
- // -- fails to compile NumericMatrix yy = xx + 2;
- NumericMatrix yy = xx;
- return yy;
+ )
+
+ ,
+ "vector_vector_ops" = list(signature(x = "numeric", y="numeric"),
+ '
+ NumericVector xx(x);
+ NumericVector yy(y);
+ NumericVector y1 = xx + yy;
+ NumericVector y2 = yy - xx;
+ NumericVector y3 = xx * yy;
+ NumericVector y4 = yy / xx;
+ return List::create(y1, y2, y3, y4);
'
- )
+ )
+
+ ## ,
+ ## "matrix_plus" = list(signature(x = "numeric"),
+ ## '
+ ## NumericMatrix xx(x);
+ ## // -- fails to compile
+ ## NumericMatrix yy = xx + 2;
+ ## return yy;
+ ## '
+ ## )
)
}
@@ -46,15 +75,28 @@
}
}
-test.vector.plus <- function( ){
- fx <- .rcpp.sugarOps$vector_plus
+test.vector.scalar.ops <- function( ){
+ fx <- .rcpp.sugarOps$vector_scalar_ops
x <- rnorm(10)
- checkEquals(fx(x) , x + 2)
+ checkEquals(fx(x), list(x + 2, 2 - x, x * 2, 2 / x), "sugar vector scalar operations")
}
-test.matrix.plus <- function( ){
- fx <- .rcpp.sugarOps$matrix_plus
- x <- matrix(rnorm(10), 5, 2)
- #checkEquals(fx(x) , x + 2)
- checkEquals(fx(x) , x ) # DUMMY
+test.vector.scalar.logical <- function( ){
+ fx <- .rcpp.sugarOps$vector_scalar_logical
+ x <- rnorm(10) + 2
+ checkEquals(fx(x), list(x < 2, 2 > x, x <= 2, 2 != x), "sugar vector scalara logical operations")
}
+
+test.vector.vector.ops <- function( ){
+ fx <- .rcpp.sugarOps$vector_vector_ops
+ x <- rnorm(10)
+ y <- runif(10)
+ checkEquals(fx(x,y), list(x + y, y - x, x * y, y / x), "sugar vector vector operations")
+}
+
+## test.matrix.plus <- function( ){
+## fx <- .rcpp.sugarOps$matrix_plus
+## x <- matrix(rnorm(10), 5, 2)
+## checkEquals(fx(x) , x + 2)
+## #checkEquals(fx(x) , x ) # DUMMY
+## }
More information about the Rcpp-commits
mailing list