SCM

SCM Repository

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

Diff of /pkg/tests/indexing.R

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

revision 2363, Thu Apr 9 20:45:32 2009 UTC revision 2505, Wed Dec 9 17:33:23 2009 UTC
# Line 2  Line 2 
2    
3  library(Matrix)  library(Matrix)
4    
5  source(system.file("test-tools.R", package = "Matrix"))# identical3() etc  source(system.file("test-tools.R", package = "Matrix"), keep.source = FALSE)
6    ##-> identical3() etc
7    
8  if(interactive()) {  if(interactive()) {
9      options(error = recover, warn = 1)      options(error = recover, warn = 1)
10    } else if(FALSE) { ## MM @ testing
11        options(error = recover, Matrix.verbose = TRUE, warn = 1)
12  } else options(Matrix.verbose = TRUE, warn = 1)  } else options(Matrix.verbose = TRUE, warn = 1)
13    
14    
15  ### Dense Matrices  ### Dense Matrices
16    
17  m <- Matrix(1:28 +0, nrow = 7)  m <- Matrix(1:28 +0, nrow = 7)
# Line 39  Line 43 
43                       LETTERS[1:ncol(mn)])                       LETTERS[1:ncol(mn)])
44  checkMatrix(mn)  checkMatrix(mn)
45  mn["rd", "D"]  mn["rd", "D"]
46    ## Printing sparse colnames:
47    ms <- as(mn,"sparseMatrix")
48    ms[sample(28, 20)] <- 0
49    ms <- t(rbind2(ms, 3*ms))
50    cnam1 <- capture.output(show(ms))[2] ; op <- options("sparse.colnames" = "abb3")
51    cnam2 <- capture.output(show(ms))[2] ; options(op) # revert
52  stopifnot(identical(mn["rc", "D"], mn[3,4]), mn[3,4] == 24,  stopifnot(identical(mn["rc", "D"], mn[3,4]), mn[3,4] == 24,
53            identical(mn[, "A"], mn[,1]), mn[,1] == 1:7,            identical(mn[, "A"], mn[,1]), mn[,1] == 1:7,
54            identical(mn[c("re", "rb"), "B"], mn[c(5,2), 2])            identical(mn[c("re", "rb"), "B"], mn[c(5,2), 2]),
55            )            ## sparse printing
56              grep("^ +$", cnam1) == 1, # cnam1 is empty
57              identical(cnam2,
58                        paste(" ", paste(rep(rownames(mn), 2), collapse=" "))))
59    
60  mo <- m  mo <- m
61  m[2,3] <- 100  m[2,3] <- 100
# Line 116  Line 129 
129  assert.EQ.mat(ds[NA,NA], ss[NA,NA])  assert.EQ.mat(ds[NA,NA], ss[NA,NA])
130  assert.EQ.mat(ds[NA,  ], ss[NA,])  assert.EQ.mat(ds[NA,  ], ss[NA,])
131  assert.EQ.mat(ds[  ,NA], ss[,NA])  assert.EQ.mat(ds[  ,NA], ss[,NA])
 stopifnot(identical(ds[2 ,NA], ss[2,NA]),  
           identical(ds[NA, 1], ss[NA, 1]))  
132  T <- as(S, "TsparseMatrix")  T <- as(S, "TsparseMatrix")
133    stopifnot(identical(ds[2 ,NA], ss[2,NA]),
134              identical(ds[NA, 1], ss[NA, 1]),
135              identical(S, as(T, "CsparseMatrix")) )
136    
137  ## non-repeated indices:  ## non-repeated indices:
138  i <- c(7:5, 2:4);assert.EQ.mat(T[i,i], ss[i,i])  i <- c(7:5, 2:4);assert.EQ.mat(T[i,i], ss[i,i])
139  ## NA in indices  -- check that we get a helpful error message:  ## NA in indices  -- check that we get a helpful error message:
# Line 259  Line 274 
274  M <- m0; M[1:3, 3] <- 0 ;M  M <- m0; M[1:3, 3] <- 0 ;M
275  T <- m0; T[1:3, 3] <- 10  T <- m0; T[1:3, 3] <- 10
276  stopifnot(identical(M, Diagonal(x=c(1,1, 0, 1,1))),  stopifnot(identical(M, Diagonal(x=c(1,1, 0, 1,1))),
277            is(T, "triangularMatrix"), identical(T[,3], c(10,10,10,0,0)))            isValid(T, "triangularMatrix"), identical(T[,3], c(10,10,10,0,0)))
278    
279  M <- m1; M[1,] <- 0 ; M ; assert.EQ.mat(M, diag(c(0,rep(1,4))), tol=0)  M <- m1; M[1,] <- 0 ; M ; assert.EQ.mat(M, diag(c(0,rep(1,4))), tol=0)
280  M <- m1; M[,3] <- 3 ; stopifnot(is(M,"sparseMatrix"), M[,3] == 3)  M <- m1; M[,3] <- 3 ; stopifnot(is(M,"sparseMatrix"), M[,3] == 3)
# Line 267  Line 282 
282  M <- m1; M[1:3, 3] <- 0 ;M  M <- m1; M[1:3, 3] <- 0 ;M
283  assert.EQ.mat(M, diag(c(1,1, 0, 1,1)), tol=0)  assert.EQ.mat(M, diag(c(1,1, 0, 1,1)), tol=0)
284  T <- m1; T[1:3, 3] <- 10; checkMatrix(T)  T <- m1; T[1:3, 3] <- 10; checkMatrix(T)
285  stopifnot(is(T, "dtTMatrix"), identical(T[,3], c(10,10,10,0,0)))  stopifnot(isValid(T, "dtTMatrix"), identical(T[,3], c(10,10,10,0,0)))
286    
287  M <- m2; M[1,] <- 0 ; M ; assert.EQ.mat(M, diag(c(0,rep(1,4))), tol=0)  M <- m2; M[1,] <- 0 ; M ; assert.EQ.mat(M, diag(c(0,rep(1,4))), tol=0)
288  M <- m2; M[,3] <- 3 ; stopifnot(is(M,"sparseMatrix"), M[,3] == 3)  M <- m2; M[,3] <- 3 ; stopifnot(is(M,"sparseMatrix"), M[,3] == 3)
# Line 316  Line 331 
331                       s[i,drop=FALSE], S[i,drop=FALSE]))                       s[i,drop=FALSE], S[i,drop=FALSE]))
332  stopifnot(identical5(m[L,drop=FALSE], M[L,drop=FALSE], D[L,drop=FALSE],  stopifnot(identical5(m[L,drop=FALSE], M[L,drop=FALSE], D[L,drop=FALSE],
333                       s[L,drop=FALSE], S[L,drop=FALSE]))                       s[L,drop=FALSE], S[L,drop=FALSE]))
334  ##  ## using L for row-indexing should give an error
335    assertError(m[L,]); assertError(m[L,, drop=FALSE])
336    ## these did not signal an error, upto (including) 0.999375-30:
337    assertError(s[L,]); assertError(s[L,, drop=FALSE])
338    assertError(S[L,]); assertError(S[L,, drop=FALSE])
339    
340    ## row indexing:
341  assert.EQ.mat(D[i,], m[i,])  assert.EQ.mat(D[i,], m[i,])
342  assert.EQ.mat(M[i,], m[i,])  assert.EQ.mat(M[i,], m[i,])
343  assert.EQ.mat(s[i,], m[i,])  assert.EQ.mat(s[i,], m[i,])
344  assert.EQ.mat(S[i,], m[i,])  assert.EQ.mat(S[i,], m[i,])
345    ## column indexing:
346  assert.EQ.mat(D[,i], m[,i])  assert.EQ.mat(D[,i], m[,i])
347  assert.EQ.mat(M[,i], m[,i])  assert.EQ.mat(M[,i], m[,i])
348  assert.EQ.mat(s[,i], m[,i])  assert.EQ.mat(s[,i], m[,i])
# Line 614  Line 635 
635  sv <- as(thisCol, "sparseVector")  sv <- as(thisCol, "sparseVector")
636  str(sv) ## "empty" !  str(sv) ## "empty" !
637  validObject(spCol <- f[,5000, drop=FALSE])  validObject(spCol <- f[,5000, drop=FALSE])
638    ## ^^ FIXME slow Tsparse_to_Csparse from memory-hog
639    ## cholmod_sparse *CHOLMOD(triplet_to_sparse)
640    ## which has  "workspace: Iwork (max (nrow,ncol))"
641    ## in ../src/CHOLMOD/Core/cholmod_triplet.c  *and*
642    ## in ../src/CHOLMOD/Core/t_cholmod_triplet.c
643    ##
644  ## *not* identical(): as(spCol, "sparseVector")@length is "double"prec:  ## *not* identical(): as(spCol, "sparseVector")@length is "double"prec:
645  stopifnot(all.equal(as(spCol, "sparseVector"),  stopifnot(all.equal(as(spCol, "sparseVector"),
646                      as(sv,   "nsparseVector"), tol=0))                      as(sv,   "nsparseVector"), tol=0))

Legend:
Removed from v.2363  
changed lines
  Added in v.2505

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