SCM

SCM Repository

[matrix] Diff of /pkg/tests/simple.R
ViewVC logotype

Diff of /pkg/tests/simple.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 947, Wed Sep 28 08:57:37 2005 UTC revision 948, Wed Sep 28 08:57:56 2005 UTC
# Line 1  Line 1 
1    #### Currently a collection of simple tests
2    ##      (since 'Matrix' takes long to load, rather have fewer source files!)
3    
4  library(Matrix)  library(Matrix)
5    
6    source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
7    
8    ###--  Sparse Triangular :
9    
10    (t1 <- new("dtTMatrix", x= c(3,7), i= 0:1, j=3:2,
11               Dim= as.integer(c(4,4))))
12    stopifnot(validObject(t1),
13              validObject(t1c <- as(t1, "dtCMatrix")))
14    assert.EQ.mat(t1, as(t1c, "matrix"))
15    
16    ## from  0-diagonal to unit-diagonal {low-level step}:
17    tu <- t1 ; tu@diag <- "U"
18    tu
19    stopifnot(validObject(cu <- as(tu, "dtCMatrix")),
20              validObject(t(cu)),
21              validObject(t(tu)))
22    assert.EQ.mat(cu, as(tu,"matrix"), tol=0)
23    
24    
25    ###-- Numeric Dense: Crossprod & Solve
26    
27  set.seed(123)  set.seed(123)
28  mm <- Matrix(rnorm(500 * 150), nc = 150)  mm <- Matrix(rnorm(500 * 150), nc = 150)
29  stopifnot(validObject(mm))  stopifnot(validObject(mm))
# Line 16  Line 40 
40            validObject(res))            validObject(res))
41  stopifnot(all.equal(xpx %*% res, xpy, tol= 1e-12))  stopifnot(all.equal(xpx %*% res, xpy, tol= 1e-12))
42    
43    ###-- more solve() methods  {was ./solve.R }
44    
45    ## first for "dgeMatrix" and all kinds of RHS :
46    (m6 <- 1 + as(diag(0:5), "dgeMatrix"))
47    rcond(m6)
48    I6 <- as(diag(6), "dgeMatrix")
49    stopifnot(all.equal(I6, m6 %*% solve(m6)),
50              all.equal(I6, solve(m6) %*% m6) )
51    
52    (i6 <- solve(m6, Matrix(1:6)))
53    stopifnot(identical(i6, as(cbind(c(-4, rep(1,5))), "dgeMatrix")),
54              identical(i6, solve(m6, 1:6),
55              identical(i6, solve(m6, matrix(1:6))),
56              identical(i6, solve(m6, matrix(c(1,2,3,4,5,6)))),
57              )
58    
59    ###-- row- and column operations  {was ./rowcolOps.R }
60    
61    set.seed(321)
62    mm <- Matrix(round(rnorm(1000), 2), 50, 20)
63    m1 <- as(mm, "matrix")
64    stopifnot(all.equal(colMeans(mm), colMeans(m1)),
65              all.equal(colSums(mm), colSums(m1)),
66              all.equal(rowMeans(mm), rowMeans(m1)),
67              all.equal(rowSums(mm), rowSums(m1)))
68    
69    ###-- Testing expansions of factorizations {was ./expand.R }
70    
71    (m1 <- round(Matrix(rnorm(25), 5), 2))
72    (lul <- expand(lu(m1)))
73    stopifnot(all.equal(as(m1, "matrix"),
74                        as(lul$P %*% (lul$L %*% lul$U), "matrix")))
75    
76    
77  proc.time()  proc.time()

Legend:
Removed from v.947  
changed lines
  Added in v.948

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