SCM

SCM Repository

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

Annotation of /pkg/tests/dtpMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1167 - (view) (download)

1 : maechler 612 ### triangular packed
2 : bates 597 library(Matrix)
3 : maechler 628
4 :     cp6 <- chol(Hilbert(6))
5 :     tp6 <- as(cp6,"dtpMatrix")
6 :     round(tp6, 3)## round() is "Math2" group method
7 :     1/tp6 ## "Arith" group : gives 'dgeMatrix'
8 : bates 597 str(tp6)
9 : maechler 1087 ## arithmetic with a mix of dimnames / no dimnames
10 :     tp <- tp6; dimnames(tp) <- list(LETTERS[1:6], letters[11:16])
11 :     stopifnot(all(tp - tp6 == tp6 - tp),
12 :     0 == as.matrix(tp - tp6)) # FIXME: fails w/o 'as.matrix'
13 :    
14 : maechler 612 stopifnot(validObject(tp6),
15 : maechler 657 all.equal(tp6 %*% diag(6), as(tp6, "dgeMatrix")),
16 : maechler 630 validObject(tp6. <- diag(6) %*% tp6),
17 : maechler 612 class((tt6 <- t(tp6))) == "dtpMatrix",
18 : maechler 628 identical(t(tt6), tp6),
19 : maechler 612 tp6@uplo == "U" && tt6@uplo == "L")
20 : maechler 628
21 : maechler 630 all.equal(as(tp6.,"matrix"),
22 :     as(tp6, "matrix"), tol= 1e-15)
23 : maechler 620 (tr6 <- as(tp6, "dtrMatrix")) ## prints using wrong class name
24 : maechler 612 D. <- determinant(tp6)
25 :     rc <- rcond(tp6)
26 : maechler 1107 stopifnot(all.equal(c(D.$modulus), -6.579251212),
27 : maechler 612 all.equal(rc, 1.791511257e-4),
28 : maechler 620 all.equal(norm(tp6, "I") , 2.45),
29 :     all.equal(norm(tp6, "1") , 1),
30 :     all.equal(norm(tp6, "F") , 1.37047826623)
31 :     )
32 : bates 597 object.size(tp6)
33 :     object.size(as(tp6, "dtrMatrix"))
34 :     object.size(as(tp6, "matrix"))
35 : bates 629 D6 <- as(diag(6), "dgeMatrix")
36 :     ge6 <- as(tp6, "dgeMatrix")
37 : bates 1167 stopifnot(all.equal(D6 %*% tp6, ge6),
38 :     all.equal(tp6 %*% D6, ge6))
39 : maechler 612
40 :     ## larger case
41 : bates 597 set.seed(123)
42 :     rl <- new("dtpMatrix", uplo="L", diag="N", Dim = rep.int(1000:1000,2),
43 :     x = rnorm(500*1001))
44 :     validObject(rl)
45 :     str(rl)
46 : maechler 657 sapply(c("I", "1", "F"), function(type) norm(rl, type=type))
47 : maechler 612 rcond(rl)# 0 !
48 : maechler 657 stopifnot(all.equal(as(rl %*% diag(1000),"matrix"),
49 : maechler 630 as(rl, "matrix")))
50 : bates 1167 object.size(rl) ## 4 MB
51 :     object.size(as(rl, "dtrMatrix"))# 8 MB
52 :     object.size(as(rl, "matrix"))# ditto
53 : bates 597 determinant(rl)
54 : maechler 620
55 : maechler 630
56 :     proc.time() # for ``statistical reasons''

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