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 657 - (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 612 stopifnot(validObject(tp6),
10 : maechler 657 all.equal(tp6 %*% diag(6), as(tp6, "dgeMatrix")),
11 : maechler 630 validObject(tp6. <- diag(6) %*% tp6),
12 : maechler 612 class((tt6 <- t(tp6))) == "dtpMatrix",
13 : maechler 628 identical(t(tt6), tp6),
14 : maechler 612 tp6@uplo == "U" && tt6@uplo == "L")
15 : maechler 628
16 : maechler 630 all.equal(as(tp6.,"matrix"),
17 :     as(tp6, "matrix"), tol= 1e-15)
18 : maechler 620 (tr6 <- as(tp6, "dtrMatrix")) ## prints using wrong class name
19 : maechler 612 D. <- determinant(tp6)
20 :     rc <- rcond(tp6)
21 :     stopifnot(all.equal(D.$modulus, -6.579251212),
22 :     all.equal(rc, 1.791511257e-4),
23 : maechler 620 rc == tp6@rcond,
24 :     all.equal(norm(tp6, "I") , 2.45),
25 :     all.equal(norm(tp6, "1") , 1),
26 :     all.equal(norm(tp6, "F") , 1.37047826623)
27 :     )
28 : bates 597 object.size(tp6)
29 :     object.size(as(tp6, "dtrMatrix"))
30 :     object.size(as(tp6, "matrix"))
31 : bates 629 D6 <- as(diag(6), "dgeMatrix")
32 :     ge6 <- as(tp6, "dgeMatrix")
33 : maechler 630 ## Direct all.equal() fails, because ge6 has 'rcond', but the product not:
34 :     mge6 <- as(ge6, "matrix")
35 :     stopifnot(all.equal(as(D6 %*% tp6,"matrix"), mge6),
36 :     all.equal(as(tp6 %*% D6,"matrix"), mge6)
37 :     )
38 : maechler 612
39 :     ## larger case
40 : bates 597 set.seed(123)
41 :     rl <- new("dtpMatrix", uplo="L", diag="N", Dim = rep.int(1000:1000,2),
42 :     x = rnorm(500*1001))
43 :     validObject(rl)
44 :     str(rl)
45 : maechler 657 sapply(c("I", "1", "F"), function(type) norm(rl, type=type))
46 : maechler 612 rcond(rl)# 0 !
47 : maechler 657 stopifnot(all.equal(as(rl %*% diag(1000),"matrix"),
48 : maechler 630 as(rl, "matrix")))
49 : maechler 657 object.size(rl) ## 4 mio
50 :     object.size(as(rl, "dtrMatrix"))# 8 mio
51 :     object.size(as(rl, "matrix"))# dito
52 : bates 597 determinant(rl)
53 : maechler 620
54 : maechler 630
55 :     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