Skip to content

Commit 5929007

Browse files
committed
new unit tests for transpose
1 parent 1a82598 commit 5929007

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* inst/include/Rcpp/vector/Matrix.h (Rcpp): Matrix transpose is now a
44
free function for both INTSXP and REALSXP
55

6+
* inst/unitTests/runit.Matrix.R: New unit tests
7+
* inst/unitTests/cpp/Matrix.cpp: Ditto
8+
69
2015-11-08 Daniel C. Dillon <[email protected]>
710

811
* inst/include/Rcpp/Nullable.h: No longer prevent assignment of

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.12.1.4
4-
Date: 2015-11-01
3+
Version: 0.12.1.5
4+
Date: 2015-11-08
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey,
66
Qiang Kou, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/unitTests/cpp/Matrix.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,14 @@ NumericVector runit_const_Matrix_column( const NumericMatrix& m ){
242242
int mat_access_with_bounds_checking(const IntegerMatrix m, int i, int j) {
243243
return m.at(i, j);
244244
}
245+
246+
247+
// [[Rcpp::export]]
248+
IntegerMatrix transposeInteger(const IntegerMatrix & x) {
249+
return transpose(x);
250+
}
251+
252+
// [[Rcpp::export]]
253+
NumericMatrix transposeNumeric(const NumericMatrix & x) {
254+
return transpose(x);
255+
}

inst/unitTests/runit.Matrix.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,22 @@ if (.runThisTest) {
183183
checkException(mat_access_with_bounds_checking(m, -1, -1) , msg = "index out of bounds not detected" )
184184
}
185185

186+
test.IntegerMatrix.transpose <- function() {
187+
M <- matrix(1:12, 3, 4)
188+
checkEquals(transposeInteger(M), t(M), msg="integer transpose")
189+
rownames(M) <- letters[1:nrow(M)]
190+
checkEquals(transposeInteger(M), t(M), msg="integer transpose with rownames")
191+
colnames(M) <- LETTERS[1:ncol(M)]
192+
checkEquals(transposeInteger(M), t(M), msg="integer transpose with row and colnames")
193+
}
194+
195+
test.NumericMatrix.transpose <- function() {
196+
M <- matrix(1.0 * (1:12), 3, 4)
197+
checkEquals(transposeNumeric(M), t(M), msg="numeric transpose")
198+
rownames(M) <- letters[1:nrow(M)]
199+
checkEquals(transposeNumeric(M), t(M), msg="numeric transpose with rownames")
200+
colnames(M) <- LETTERS[1:ncol(M)]
201+
checkEquals(transposeNumeric(M), t(M), msg="numeric transpose with row and colnames")
202+
}
203+
186204
}

0 commit comments

Comments
 (0)