SCM

SCM Repository

[matrix] Annotation of /pkg/tests/validObj.R
ViewVC logotype

Annotation of /pkg/tests/validObj.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 907 - (view) (download)

1 : maechler 509 library(Matrix)
2 :    
3 : maechler 516 ### Do all kinds of object creation and coercion
4 : maechler 509
5 : maechler 907 source(system.file("test-tools.R", package = "Matrix"))
6 : maechler 516
7 : maechler 612 ## the empty ones:
8 :     chk.matrix(new("dgeMatrix"))
9 : maechler 538
10 : maechler 516 ## "dge"
11 : maechler 538 assertError( new("dgeMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'
12 :     assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'
13 :     assertError( new("dgeMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2
14 :     assertError( new("dgeMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))
15 :    
16 : maechler 516 chk.matrix(m1 <- Matrix(1:6, ncol=2))
17 : maechler 834 chk.matrix(m2 <- Matrix(1:7, ncol=3)) # a (desired) warning
18 : maechler 850 stopifnot(unique(is(m1)) == c("dgeMatrix", "ddenseMatrix",
19 :     "dMatrix", "denseMatrix", "Matrix"),
20 :     dim(t(m1)) == 2:3,
21 :     identical(m1, t(t(m1))))
22 : maechler 579 c.nam <- paste("C",1:2, sep='')
23 :     dimnames(m1) <- list(NULL, c.nam)
24 :     stopifnot(colnames(m1) == c.nam,
25 : maechler 850 identical(dimnames(t(m1)), list(c.nam, NULL)),
26 :     identical(m1, t(t(m1))))
27 : maechler 538
28 : maechler 620 ## an example of *named* dimnames
29 :     (t34N <- as(unclass(table(x = gl(3,4), y=gl(4,3))), "dgeMatrix"))
30 :     stopifnot(identical(dimnames(t34N),
31 : maechler 850 dimnames(as(t34N, "matrix"))))
32 : maechler 579
33 : maechler 516 ## "dpo"
34 :     chk.matrix(cm <- crossprod(m1))
35 : maechler 873 chk.matrix(cp <- as(cm, "dppMatrix"))# 'dpp'
36 : maechler 516 chk.matrix(as(cm, "dsyMatrix"))
37 : maechler 768 chk.matrix(dcm <- as(cm, "dgeMatrix"))
38 :     chk.matrix(mcm <- as(cm, "dMatrix"))
39 : maechler 834 ##BUG - FIXME: stopifnot(identical(dcm, mcm))
40 : maechler 850 ##--- ------ mcm[2,1] is garbage
41 : maechler 577 try( chk.matrix(as(cm, "Matrix")) )# gives an error: "Matrix" has NULL 'dim()'
42 : maechler 516
43 :     ## Cholesky
44 :     chk.matrix(ch <- chol(cm))
45 : maechler 768 #if(FALSE)# fails for Doug in R-devel (2005-06-06) :
46 :     chk.matrix(ch2 <- chol(as(cm, "dsyMatrix")))
47 :     #not yet{FIXME}: chk.matrix(ch3 <- chol(as(cm, "dgeMatrix")))
48 :     #if(FALSE)# ...R-devel
49 :     stopifnot(all.equal(as(ch, "matrix"), as(ch2, "matrix")))
50 : maechler 538
51 : maechler 850 ### Very basic triangular matrix stuff
52 : maechler 538
53 :     assertError( new("dtrMatrix", Dim = c(2,2), x= 1:4) )# double 'Dim'
54 : maechler 657 if(paste(R.version$major, R.version$minor, sep=".") >= "2.0.1")
55 : maechler 538 assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= 1:4) )# int 'x'
56 : maechler 577 ## This caused a segfault (before revision r1172 in ../src/dtrMatrix.c):
57 : maechler 538 assertError( new("dtrMatrix", Dim = 2:2, x=as.double(1:4)) )# length(Dim) !=2
58 :     assertError( new("dtrMatrix", Dim = as.integer(c(2,2)), x= as.double(1:5)))
59 :    
60 :     tr22 <- new("dtrMatrix", Dim = as.integer(c(2,2)), x=as.double(1:4))
61 : maechler 579 tt22 <- t(tr22)
62 :     (tPt <- tr22 + tt22)
63 :     stopifnot(identical(10 * tPt, tPt * 10),
64 : maechler 850 (t.22 <- (tr22 / .5)* .5)@x == c(1,0,3,4),
65 :     TRUE) ## not yet: class(t.22) == "dtrMatrix")
66 : maechler 538
67 : maechler 579
68 : maechler 850 ## non-square triagonal Matrices --- are forbidden ---
69 :     try(tru <- new("dtrMatrix", Dim = 2:3,
70 :     x=as.double(1:6), uplo="L", diag="U"))

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge