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 2110, Sat Jan 26 20:59:26 2008 UTC revision 2113, Mon Feb 18 08:27:41 2008 UTC
# Line 4  Line 4 
4    
5  source(system.file("test-tools.R", package = "Matrix"))# identical3() etc  source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
6    
7    options(verbose = TRUE)# to show message()s
8    
9  ### Dense Matrices  ### Dense Matrices
10    
11  m <- Matrix(1:28 +0, nrow = 7)  m <- Matrix(1:28 +0, nrow = 7)
# Line 13  Line 15 
15            identical(m[2, 3:4], c(16,23))) # simple numeric of length 2            identical(m[2, 3:4], c(16,23))) # simple numeric of length 2
16    
17  m[2, 3:4, drop=FALSE] # sub matrix of class 'dgeMatrix'  m[2, 3:4, drop=FALSE] # sub matrix of class 'dgeMatrix'
18  m[-(4:7), 3:4]        # dito; the upper right corner of 'm'  m[-(4:7), 3:4]        # ditto; the upper right corner of 'm'
19    
20  ## rows or columns only:  ## rows or columns only:
21  m[1,]     # first row, as simple numeric vector  m[1,]     # first row, as simple numeric vector
# Line 385  Line 387 
387  ## equivalent to tmp <- `diag<-`(S[,-1], -2:1); S[,-1] <- tmp  ## equivalent to tmp <- `diag<-`(S[,-1], -2:1); S[,-1] <- tmp
388  ## which dispatches to (x="TsparseMatrix", i="missing",j="index", value="replValue")  ## which dispatches to (x="TsparseMatrix", i="missing",j="index", value="replValue")
389  diag(S[,-1]) <- -2:1 # used to give a wrong warning  diag(S[,-1]) <- -2:1 # used to give a wrong warning
390  ## FIXME? the above *could* return triangular -- but for that  S <- as(S,"triangularMatrix")
391    assert.EQ.mat(S, local({s <- diag(5); diag(s[,-1]) <- -2:1; s}))
392    
393  trH[c(1:2,4), c(2:3,5)] <- 0 # gave an *error* upto Jan.2008  trH[c(1:2,4), c(2:3,5)] <- 0 # gave an *error* upto Jan.2008
394  trH[ lower.tri(trH) ] <- 0   # ditto, because of callNextMethod()  trH[ lower.tri(trH) ] <- 0   # ditto, because of callNextMethod()
# Line 478  Line 481 
481  ne. <- mc != m.  # was wrong (+ warning)  ne. <- mc != m.  # was wrong (+ warning)
482  stopifnot(identical(!(m. < mc), m. >= mc),  stopifnot(identical(!(m. < mc), m. >= mc),
483            identical(m. < mc, as(!ge, "sparseMatrix")),            identical(m. < mc, as(!ge, "sparseMatrix")),
484            identical(ne., Matrix:::drop0(ne1)))            identical(ne., drop0(ne1)))
485    
486  (M3 <- Matrix(upper.tri(matrix(, 3, 3)))) # ltC; indexing used to fail  (M3 <- Matrix(upper.tri(matrix(, 3, 3)))) # ltC; indexing used to fail
487  T3 <- as(M3, "TsparseMatrix")  T3 <- as(M3, "TsparseMatrix")
# Line 489  Line 492 
492            !is(T3[,2, drop=FALSE], "triangularMatrix")            !is(T3[,2, drop=FALSE], "triangularMatrix")
493            )            )
494    
495    M <- Diagonal(4); M[1,2] <- 2
496    M. <- as(M, "CsparseMatrix")
497    (R <- as(M., "RsparseMatrix"))
498    stopifnot(is(M, "triangularMatrix"),
499              is(M.,"triangularMatrix"),
500              is(R, "triangularMatrix"))
501    stopifnot(dim(M[2:3, FALSE]) == c(2,0),
502              dim(R[2:3, FALSE]) == c(2,0),
503              identical(M [2:3,TRUE], M [2:3,]),
504              identical(M.[2:3,TRUE], M.[2:3,]),
505              identical(R [2:3,TRUE], R [2:3,]),
506              dim(R[FALSE, FALSE]) == c(0,0))
507    
508  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''

Legend:
Removed from v.2110  
changed lines
  Added in v.2113

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