Switch to unified view

a b/partyMod/tests/Utils-regtest.R
1
2
set.seed(290875)
3
library("party")
4
if (!require("MASS", quietly = TRUE))
5
    stop("cannot load package MASS")
6
7
### get rid of the NAMESPACE
8
attach(asNamespace("party"))
9
10
###
11
###
12
###    Regression tests for utility functions
13
###
14
###    functions defined in file ./src/Utils.c'
15
###
16
###
17
18
### tests for function C_kronecker
19
for (i in 1:10) {
20
    A = matrix(rnorm(i*5), ncol = i, nrow = 5)
21
    B = matrix(rnorm(i*10), ncol = 10, nrow = i)
22
    Rkr = kronecker(A, B)
23
    mykr = .Call("R_kronecker", A, B, PACKAGE = "party")
24
    stopifnot(isequal(Rkr, mykr))
25
}
26
27
### test for function CR_svd (singular value decomposition)
28
x <- matrix(rnorm(100), ncol = 10)
29
x <- t(x) %*% x
30
svdx <- qsvd(x)
31
stopifnot(isequal(svd(x)$d, svdx$d))
32
stopifnot(isequal(svd(x)$u, svdx$u))
33
stopifnot(isequal(svd(x)$v, t(svdx$vt)))
34
35
### test for function R_MPinv (Moore-Penrose inverse)
36
mpinvx <- MPinv(x)
37
stopifnot(isequal(mpinvx, ginv(x)))
38
39
### test for function C_max
40
y <- rnorm(1000)
41
stopifnot(isequal(max(y), .Call("R_max", y, PACKAGE = "party")))
42
43
### test for function C_abs
44
y <- rnorm(1000)
45
stopifnot(isequal(abs(y), .Call("R_abs", y, PACKAGE = "party")))
46
47
### tests for function C_matprod{T}
48
x <- matrix(rnorm(100), ncol = 4)
49
y <- matrix(rnorm(40), nrow = 4)
50
stopifnot(isequal(x %*% y, 
51
                  .Call("R_matprod", x, y, PACKAGE = "party")))
52
x <- matrix(rnorm(100), ncol = 20)
53
y <- matrix(rnorm(200), ncol = 20)
54
stopifnot(isequal(x %*% t(y), 
55
                  .Call("R_matprodT", x, y, PACKAGE = "party")))
56
57
### test for function C_SampleNoReplace
58
### permutation case
59
m <- 10000
60
storage.mode(m) <- "integer"
61
perm <- .Call("R_permute", m, PACKAGE = "party") + 1 
62
stopifnot(all(sort(perm) == (1:m)))
63
64
### the random subset case
65
k <- 100
66
storage.mode(k) <- "integer"
67
perm <- .Call("R_rsubset", m, k, PACKAGE = "party") + 1 
68
stopifnot(all(perm %in% (1:m)))