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 1724, Sat Jan 13 21:06:51 2007 UTC revision 1799, Sat Mar 24 14:54:00 2007 UTC
# Line 81  Line 81 
81  mC[1:2,]  mC[1:2,]
82  mC[7,  drop = FALSE]  mC[7,  drop = FALSE]
83  assert.EQ.mat(mC[1:2,], mm[1:2,])  assert.EQ.mat(mC[1:2,], mm[1:2,])
84    
85    ## *repeated* indices - did not work at all ...
86    i <- rep(8:10,2)
87    j <- c(2:4, 4:3)
88    assert.EQ.mat(mC[i,], mm[i,])
89    assert.EQ.mat(mC[,j], mm[,j])
90    if(FALSE) ## FIXME
91    assert.EQ.mat(mC[i,j], mm[i,j])
92    
93  stopifnot(all.equal(mC[,3], mm[,3]),  stopifnot(all.equal(mC[,3], mm[,3]),
94            identical(mC[ij], mm[ij]))            identical(mC[ij], mm[ij]))
95  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])
# Line 142  Line 151 
151  m0 <- Diagonal(5)  m0 <- Diagonal(5)
152  (m1 <- as(m0, "sparseMatrix"))  # dtTMatrix  (m1 <- as(m0, "sparseMatrix"))  # dtTMatrix
153  (m2 <- as(m0, "CsparseMatrix")) # dtCMatrix (with an irrelevant warning)  (m2 <- as(m0, "CsparseMatrix")) # dtCMatrix (with an irrelevant warning)
154    m1g <- as(m1, "generalMatrix")
155    stopifnot(is(m1g, "dgTMatrix"))
156    assert.EQ.mat(m2[1:3,],    diag(5)[1:3,])
157    assert.EQ.mat(m2[,c(4,1)], diag(5)[,c(4,1)])
158    stopifnot(identical(m2[1:3,], as(m1[1:3,], "CsparseMatrix")),
159              identical(Matrix:::uniqTsparse(m1[, c(4,2)]),
160                        Matrix:::uniqTsparse(as(m2[, c(4,2)], "TsparseMatrix")))
161              )## failed in 0.9975-11
162    
163  M <- m0; M[1,] <- 0  M <- m0; M[1,] <- 0
164  stopifnot(identical(M, Diagonal(x=c(0, rep(1,4)))))  stopifnot(identical(M, Diagonal(x=c(0, rep(1,4)))))
# Line 273  Line 290 
290  validObject(dm <- kronecker(Diagonal(2), sy3))  validObject(dm <- kronecker(Diagonal(2), sy3))
291  (s2 <- as(dm, "sparseMatrix"))  (s2 <- as(dm, "sparseMatrix"))
292  validObject(st <- as(s2, "TsparseMatrix"))  validObject(st <- as(s2, "TsparseMatrix"))
293    stopifnot(is(s2, "symmetricMatrix"),
294              is(st, "symmetricMatrix"))
295  validObject(s.32  <- st[1:3,1:2]) ## 3 x 2 - and *not* dsTMatrix  validObject(s.32  <- st[1:3,1:2]) ## 3 x 2 - and *not* dsTMatrix
296  validObject(s2.32 <- s2[1:3,1:2])  validObject(s2.32 <- s2[1:3,1:2])
297  I <- c(1,4:3)  I <- c(1,4:3)
# Line 325  Line 344 
344  validObject(x.x)  validObject(x.x)
345  stopifnot(class(x.x) == "dsCMatrix",  stopifnot(class(x.x) == "dsCMatrix",
346            12:16 == as.mat(x.x)[cbind(2:6, 2:6)])            12:16 == as.mat(x.x)[cbind(2:6, 2:6)])
347    (ne1 <- (mc - m.) != 0)
348    stopifnot(identical(ne1, 0 != abs(mc - m.)))
349    (ge <- m. >= mc) # contains "=" -> result is dense
350    ne. <- mc != m.  # was wrong (+ warning)
351    stopifnot(identical(!(m. < mc), m. >= mc),
352              identical(m. < mc, as(!ge, "sparseMatrix")),
353              identical(ne., Matrix:::drop0(ne1)))
354    
355    (M3 <- Matrix(upper.tri(matrix(, 3, 3)))) # ltC; indexing used to fail
356    T3 <- as(M3, "TsparseMatrix")
357    stopifnot(identical(drop(M3), M3),
358              identical4(drop(M3[,2, drop = FALSE]), M3[,2, drop = TRUE],
359                         drop(T3[,2, drop = FALSE]), T3[,2, drop = TRUE]),
360              is(T3, "triangularMatrix"),
361              !is(T3[,2, drop=FALSE], "triangularMatrix")
362              )
363    
364  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''

Legend:
Removed from v.1724  
changed lines
  Added in v.1799

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