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 1599, Fri Sep 29 09:39:50 2006 UTC revision 1665, Fri Nov 3 23:18:07 2006 UTC
# Line 45  Line 45 
45  m[1:3,]  m[1:3,]
46    
47  ## testing operations on logical Matrices rather more than indexing:  ## testing operations on logical Matrices rather more than indexing:
48    m. <- as.matrix(m)
49  g10 <- m [ m > 10 ]  g10 <- m [ m > 10 ]
50  stopifnot(18 == length(g10))  stopifnot(18 == length(g10))
51  stopifnot(10 == length(m[ m <= 10 ]))  stopifnot(10 == length(m[ m <= 10 ]))
52  sel <- (20 <  m) & (m <  150)  sel <- (20 <  m) & (m <  150)
53    sel.<- (20 <  m.)& (m.<  150)
54  nsel <-(20 >= m) | (m >= 150)  nsel <-(20 >= m) | (m >= 150)
55  (ssel <- as(sel, "sparseMatrix"))  (ssel <- as(sel, "sparseMatrix"))
56  stopifnot(is(sel, "lMatrix"), is(ssel, "lsparseMatrix"),  stopifnot(is(sel, "lMatrix"), is(ssel, "lsparseMatrix"),
57              identical3(as.mat(sel.), as.mat(sel), as.mat(ssel)),
58            identical3(!sel, !ssel, nsel), # !<sparse> is typically dense            identical3(!sel, !ssel, nsel), # !<sparse> is typically dense
59            identical3(m[ sel],  m[ ssel], as.matrix(m)[as.matrix( ssel)]),            identical3(m[ sel],  m[ ssel], as.matrix(m)[as.matrix( ssel)]),
60            identical3(m[!sel],  m[!ssel], as.matrix(m)[as.matrix(!ssel)])            identical3(m[!sel],  m[!ssel], as.matrix(m)[as.matrix(!ssel)])
# Line 93  Line 96 
96            identical3(mm[3,], mC[3,], mT[3,]),            identical3(mm[3,], mC[3,], mT[3,]),
97            identical3(mT[2,3], mC[2,3], 0),            identical3(mT[2,3], mC[2,3], 0),
98            identical(mT[], mT),            identical(mT[], mT),
99            ## TODO: identical4() with  m[c(3,7), 2:4] - fail because of 'dimnames'            identical4(       mm[c(3,7), 2:4],  as.mat( m[c(3,7), 2:4]),
100            ## TODO: identical3() with as(mC[c(3,7), 2:4],"matrix"),                       as.mat(mT[c(3,7), 2:4]), as.mat(mC[c(3,7), 2:4]))
           ##       fails because of 'dimnames'  
           identical(mm[c(3,7), 2:4], as(mT[c(3,7), 2:4],"matrix"))  
101            )            )
102    
103  x.x <- crossprod(mC)  x.x <- crossprod(mC)
# Line 106  Line 107 
107  tail(x.x., -3) # all but the first three lines  tail(x.x., -3) # all but the first three lines
108    
109  lx.x <- as(x.x, "lsCMatrix") # FALSE only for "structural" 0  lx.x <- as(x.x, "lsCMatrix") # FALSE only for "structural" 0
110  if(FALSE) { ## FIXME: needs coercion  "lsCMatrix" to "lgTMatrix"  (l10 <- lx.x[1:10, 1:10])# "lsC"
111      lx.x[1:10, 1:10]  (l3 <-  lx.x[1:3, ])
112      lx.x[1:3, ]  m.x <- as(x.x, "matrix")
113  }  stopifnot(class(l10) == "lsCMatrix", # symmetric indexing -> symmetric !
114              identical(as.mat(lx.x), m.x != 0),
115              identical(as.logical(lx.x), as.logical(m.x)),
116              identical(as.mat(l10), m.x[1:10, 1:10] != 0),
117              identical(as.mat(l3 ), m.x[1:3, ] != 0)
118              )
119    
120    
121  ## --- negative indices ----------  ## --- negative indices ----------
122  mc <- mC[1:5, 1:7]  mc <- mC[1:5, 1:7]
# Line 179  Line 186 
186  mc[ii, jj] <- 1:6  mc[ii, jj] <- 1:6
187  mc[c(2,5), c(3,5)] <- 3.2  mc[c(2,5), c(3,5)] <- 3.2
188  validObject(mc)  validObject(mc)
189  (m. <- mc)  m. <- mc
190  if(FALSE)## FIXME:  mc[4,] <- 0
191   mc[4,] <- 0 # -> error -- another Bug  mc
192    
193  H <- Hilbert(9)  H <- Hilbert(9)
194  Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...  Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...

Legend:
Removed from v.1599  
changed lines
  Added in v.1665

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