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 2508, Thu Dec 24 09:47:57 2009 UTC
# Line 145  Line 145 
145  set.seed(11)  set.seed(11)
146  for(n in 1:50) {  for(n in 1:50) {
147      i <- sample(N, max(2, sample(N,1)), replace = FALSE)      i <- sample(N, max(2, sample(N,1)), replace = FALSE)
148      validObject(Tii <- T[i,i])      validObject(Tii <- T[i,i]) ; tTi <- t(T)[i,i]
149      stopifnot(is(Tii, "dsTMatrix"), # remained symmetric Tsparse      stopifnot(is(Tii, "dsTMatrix"), # remained symmetric Tsparse
150                identical(t(Tii), t(T)[i,i]))                is(tTi, "dsTMatrix"), # may not be identical when *sorted* differently
151                  identical(as(t(Tii),"CsparseMatrix"), as(tTi,"CsparseMatrix")))
152      assert.EQ.mat(Tii, ss[i,i])      assert.EQ.mat(Tii, ss[i,i])
153  }  }
154    
155    b <- diag(1:2)[,c(1,1,2,2)]
156    cb <- crossprod(b)
157    cB <- crossprod(Matrix(b, sparse=TRUE))
158    a <- matrix(0, 6, 6)
159    a[1:4, 1:4] <- cb
160    A1 <- A2 <- Matrix(0, 6, 6)#-> sparse
161    A1[1:4, 1:4] <- cb
162    A2[1:4, 1:4] <- cB
163    assert.EQ.mat(A1, a)# indeed
164    stopifnot(identical(A1, A2), is(A1, "dsCMatrix"))
165    
166  ## repeated ones ``the challenge'' (to do smartly):  ## repeated ones ``the challenge'' (to do smartly):
167  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)
168  assert.EQ.mat(T[j,j], ss[j,j])  assert.EQ.mat(T[j,j], ss[j,j])
# Line 190  Line 202 
202  validObject(print(mT[,c(2,4)]))  validObject(print(mT[,c(2,4)]))
203  stopifnot(all.equal(mT[2,], mm[2,]),  stopifnot(all.equal(mT[2,], mm[2,]),
204            ## row or column indexing in combination with t() :            ## row or column indexing in combination with t() :
205            identical(mT[2,], t(mT)[,2]),            Q.C.identical(mT[2,], t(mT)[,2]),
206            identical(mT[-2,], t(t(mT)[,-2])),            Q.C.identical(mT[-2,], t(t(mT)[,-2])),
207            identical(mT[c(2,5),], t(t(mT)[,c(2,5)]))            Q.C.identical(mT[c(2,5),], t(t(mT)[,c(2,5)])) )
           )  
208  assert.EQ.mat(mT[4,, drop = FALSE], mm[4,, drop = FALSE])  assert.EQ.mat(mT[4,, drop = FALSE], mm[4,, drop = FALSE])
209  stopifnot(identical3(mm[,1], mC[,1], mT[,1]),  stopifnot(identical3(mm[,1], mC[,1], mT[,1]),
210            identical3(mm[3,], mC[3,], mT[3,]),            identical3(mm[3,], mC[3,], mT[3,]),

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

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