SCM

SCM Repository

[matrix] Annotation of /pkg/tests/group-methods.R
ViewVC logotype

Annotation of /pkg/tests/group-methods.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 954 - (view) (download)

1 : maechler 573 ### Testing the group methods
2 :    
3 :     library(Matrix)
4 :     set.seed(2001)
5 :    
6 :     mm <- Matrix(rnorm(50 * 7), nc = 7)
7 :     xpx <- crossprod(mm)# -> "factors" in mm !
8 :     round(xpx, 3) # works via "Math2"
9 :    
10 :     y <- rnorm(nrow(mm))
11 :     xpy <- crossprod(mm, y)
12 :     res <- solve(xpx, xpy)
13 :     signif(res, 4) # 7 x 1 Matrix
14 :    
15 :     ## exp(): component wise
16 :     signif(dd <- (expm(xpx) - exp(xpx)) / 1e34, 3)# 7 x 7
17 :    
18 :     stopifnot(validObject(xpx),
19 :     validObject(xpy),
20 :     validObject(dd))
21 :    
22 : maechler 925 ## "Math" also, for log() and [l]gamma() which need special treatment
23 :     stopifnot(identical(exp(res)@x, exp(res@x)),
24 :     identical(log(abs(res))@x, log(abs((res@x)))),
25 :     identical(lgamma(res)@x, lgamma(res@x)))
26 : maechler 573
27 :    
28 : maechler 925 ###--- sparse matrices ---------
29 :    
30 :     m <- Matrix(c(0,0,2:0), 3,5)
31 :     (mC <- as(m, "dgCMatrix"))
32 :     sm <- sin(mC)
33 :     stopifnot(class(sm) == class(mC),
34 :     dim(sm) == dim(mC),
35 :     class(0 + 100*mC) == class(mC),
36 :     all.equal(0.1 * ((0 + 100*mC)/10), mC),
37 :     all.equal(sqrt(mC ^ 2), mC))
38 :    
39 : maechler 954 cat('Time elapsed: ', proc.time(),'\n') # "stats"

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