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 2505, Wed Dec 9 17:33:23 2009 UTC revision 2518, Thu Feb 4 17:09:33 2010 UTC
# Line 9  Line 9 
9      options(error = recover, warn = 1)      options(error = recover, warn = 1)
10  } else if(FALSE) { ## MM @ testing  } else if(FALSE) { ## MM @ testing
11      options(error = recover, Matrix.verbose = TRUE, warn = 1)      options(error = recover, Matrix.verbose = TRUE, warn = 1)
12  } else options(Matrix.verbose = TRUE, warn = 1)  } else
13    options(Matrix.verbose = TRUE, warn = 1)
14    
15    
16  ### Dense Matrices  ### Dense Matrices
# Line 96  Line 97 
97  str(mC <- as(m, "dgCMatrix"))  str(mC <- as(m, "dgCMatrix"))
98  str(mT <- as(m, "dgTMatrix"))  str(mT <- as(m, "dgTMatrix"))
99  stopifnot(identical(mT, as(mC, "dgTMatrix")),  stopifnot(identical(mT, as(mC, "dgTMatrix")),
100            identical(mC, as(mT, "dgCMatrix")))            identical(mC, as(mT, "dgCMatrix")),
101              identical(mC[0,0], new("dgCMatrix")),
102              identical(mT[0,0], new("dgTMatrix")),
103              identical(mT[0,], new("dgTMatrix", Dim = c(0L,20L))),
104              identical(mT[,0], new("dgTMatrix", Dim = c(40L,0L))),
105              identical(mC[0,], as(mT[FALSE,], "dgCMatrix")),
106              identical(mC[,0], as(mT[,FALSE], "dgCMatrix")),
107              TRUE)
108    
109  mC[,1]  mC[,1]
110  mC[1:2,]  mC[1:2,]
# Line 145  Line 153 
153  set.seed(11)  set.seed(11)
154  for(n in 1:50) {  for(n in 1:50) {
155      i <- sample(N, max(2, sample(N,1)), replace = FALSE)      i <- sample(N, max(2, sample(N,1)), replace = FALSE)
156      validObject(Tii <- T[i,i])      validObject(Tii <- T[i,i]) ; tTi <- t(T)[i,i]
157      stopifnot(is(Tii, "dsTMatrix"), # remained symmetric Tsparse      stopifnot(is(Tii, "dsTMatrix"), # remained symmetric Tsparse
158                identical(t(Tii), t(T)[i,i]))                is(tTi, "dsTMatrix"), # may not be identical when *sorted* differently
159                  identical(as(t(Tii),"CsparseMatrix"), as(tTi,"CsparseMatrix")))
160      assert.EQ.mat(Tii, ss[i,i])      assert.EQ.mat(Tii, ss[i,i])
161  }  }
162    
163    b <- diag(1:2)[,c(1,1,2,2)]
164    cb <- crossprod(b)
165    cB <- crossprod(Matrix(b, sparse=TRUE))
166    a <- matrix(0, 6, 6)
167    a[1:4, 1:4] <- cb
168    A1 <- A2 <- Matrix(0, 6, 6)#-> sparse
169    A1[1:4, 1:4] <- cb
170    A2[1:4, 1:4] <- cB
171    assert.EQ.mat(A1, a)# indeed
172    stopifnot(identical(A1, A2), is(A1, "dsCMatrix"))
173    
174  ## repeated ones ``the challenge'' (to do smartly):  ## repeated ones ``the challenge'' (to do smartly):
175  j <- c(4, 4, 9, 12, 9, 4, 17, 3, 18, 4, 12, 18, 4, 9)  j <- c(4, 4, 9, 12, 9, 4, 17, 3, 18, 4, 12, 18, 4, 9)
176  assert.EQ.mat(T[j,j], ss[j,j])  assert.EQ.mat(T[j,j], ss[j,j])
# Line 190  Line 210 
210  validObject(print(mT[,c(2,4)]))  validObject(print(mT[,c(2,4)]))
211  stopifnot(all.equal(mT[2,], mm[2,]),  stopifnot(all.equal(mT[2,], mm[2,]),
212            ## row or column indexing in combination with t() :            ## row or column indexing in combination with t() :
213            identical(mT[2,], t(mT)[,2]),            Q.C.identical(mT[2,], t(mT)[,2]),
214            identical(mT[-2,], t(t(mT)[,-2])),            Q.C.identical(mT[-2,], t(t(mT)[,-2])),
215            identical(mT[c(2,5),], t(t(mT)[,c(2,5)]))            Q.C.identical(mT[c(2,5),], t(t(mT)[,c(2,5)])) )
           )  
216  assert.EQ.mat(mT[4,, drop = FALSE], mm[4,, drop = FALSE])  assert.EQ.mat(mT[4,, drop = FALSE], mm[4,, drop = FALSE])
217  stopifnot(identical3(mm[,1], mC[,1], mT[,1]),  stopifnot(identical3(mm[,1], mC[,1], mT[,1]),
218            identical3(mm[3,], mC[3,], mT[3,]),            identical3(mm[3,], mC[3,], mT[3,]),
# Line 369  Line 388 
388    
389  ## Sub *Assignment* ---- now works (partially):  ## Sub *Assignment* ---- now works (partially):
390  mt0 <- mt  mt0 <- mt
391    nt <- as(mt, "nMatrix")
392  mt[1, 4] <- -99  mt[1, 4] <- -99
393  mt[2:3, 1:6] <- 0  mt[2:3, 1:6] <- 0
394  mt  mt
# Line 528  Line 548 
548  assert.EQ.mat(s2, m)# failed in 0.9975-8  assert.EQ.mat(s2, m)# failed in 0.9975-8
549    
550    
551  ## m[cbind(i,j)] <- value:  ## m[cbind(i,j)] <- value: (2-column matrix subassignment):
552  m.[ cbind(3:5, 1:3) ] <- 1:3  m.[ cbind(3:5, 1:3) ] <- 1:3
553  stopifnot(m.[3,1] == 1, m.[4,2] == 2)  stopifnot(m.[3,1] == 1, m.[4,2] == 2)
554    nt. <- nt ; nt[rbind(2:3, 3:4, c(3,3))] <- FALSE
555    s. <- m. ; m.[cbind(3:4,2:3)] <- 0 ## assigning 0 where there *is* 0 ..
556    stopifnot(identical(nt.,nt),       ## should not have changed
557              identical(s., m.))
558  x.x[ cbind(2:6, 2:6)] <- 12:16  x.x[ cbind(2:6, 2:6)] <- 12:16
559  stopifnot(isValid(x.x, "dsCMatrix"),  stopifnot(isValid(x.x, "dsCMatrix"),
560            12:16 == as.mat(x.x)[cbind(2:6, 2:6)])            12:16 == as.mat(x.x)[cbind(2:6, 2:6)])

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

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