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 1269, Thu May 18 06:43:29 2006 UTC revision 1347, Mon Aug 7 08:47:43 2006 UTC
# Line 20  Line 20 
20  m[,2]     # 2nd column  m[,2]     # 2nd column
21  m[,1:2]   # sub matrix of first two columns  m[,1:2]   # sub matrix of first two columns
22  m[-(1:6),, drop=FALSE] # not the first 6 rows, i.e. only the 7th  m[-(1:6),, drop=FALSE] # not the first 6 rows, i.e. only the 7th
23    m[integer(0),] #-> 0 x 4 Matrix
24    m[2:4, numeric(0)] #-> 3 x 0 Matrix
25    
26  ## logical indexing  ## logical indexing
27  stopifnot(identical(m[2,3], m[(1:nrow(m)) == 2, (1:ncol(m)) == 3]),  stopifnot(identical(m[2,3], m[(1:nrow(m)) == 2, (1:ncol(m)) == 3]),
# Line 68  Line 70 
70  stopifnot(all.equal(mC[,3],   mm[,3]))  stopifnot(all.equal(mC[,3],   mm[,3]))
71  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])
72    
73  stopifnot(identical(mC[7,  drop = FALSE],  stopifnot(dim(mC[numeric(0), ]) == c(0,20), # used to give warnings
74              dim(mC[, integer(0)]) == c(40,0),
75              identical(mC[, integer(0)], mC[, FALSE]),
76              identical(mC[7,  drop = FALSE],
77                      mC[7,, drop = FALSE]))                      mC[7,, drop = FALSE]))
78  validObject(print(mT[,c(2,4)]))  validObject(print(mT[,c(2,4)]))
79  stopifnot(all.equal(mT[2,], mm[2,]),  stopifnot(all.equal(mT[2,], mm[2,]),
# Line 86  Line 91 
91            identical3(as(mC[c(3,7), 2:4],"matrix"), mm[c(3,7), 2:4],            identical3(as(mC[c(3,7), 2:4],"matrix"), mm[c(3,7), 2:4],
92                       as(mT[c(3,7), 2:4],"matrix")))                       as(mT[c(3,7), 2:4],"matrix")))
93    
94    x.x <- crossprod(mC)
95    stopifnot(class(x.x) == "dsCMatrix",
96              class(x.x. <- round(x.x / 10000)) == "dsCMatrix")
97    head(x.x.) # Note the *non*-structural 0's printed as "0"
98    if(paste(R.version$major, R.version$minor, sep=".") >= "2.4")
99        tail(x.x., -2) # the last two lines
100    
101    lx.x <- as(x.x, "lsCMatrix") # FALSE only for "structural" 0
102    if(FALSE) { ## FIXME: needs coercion  "lsCMatrix" to "lgTMatrix"
103        lx.x[1:10, 1:10]
104        lx.x[1:3, ]
105    }
106    
107  ## --- negative indices ----------  ## --- negative indices ----------
108  mc <- mC[1:5, 1:7]  mc <- mC[1:5, 1:7]
109  mt <- mT[1:5, 1:7]  mt <- mT[1:5, 1:7]
# Line 130  Line 148 
148  mt[1:5, 2:6]  mt[1:5, 2:6]
149  as((mt0 - mt)[1:5,], "dsparseMatrix")# [1,5] and lines 2:3  as((mt0 - mt)[1:5,], "dsparseMatrix")# [1,5] and lines 2:3
150    
151  mt[c(2,4), ] <- 0  mt[c(2,4), ] <- 0; stopifnot(as(mt[c(2,4), ],"matrix") == 0)
152  mt[2:3, 4:7] <- 33  mt[2:3, 4:7] <- 33
153  validObject(mt)  validObject(mt)
154  mt  mt
155    
156  mc[1,4] <- -99  mc[1,4] <- -99 ; stopifnot(mc[1,4] == -99)
157    mc[1,4] <-  00 ; stopifnot(mc[1,4] ==  00)
158    mc[1,4] <- -99 ; stopifnot(mc[1,4] == -99)
159    mc[1:2,4:3] <- 4:1; stopifnot(as.matrix(mc[1:2,4:3]) == 4:1)
160    
161    ## Debugging:  R bug --   debug(Matrix:::replCmat)  has no effect
162    
163  mc[-1, 3] <- -2:1 # 0 should not be entered; 'value' recycled  mc[-1, 3] <- -2:1 # 0 should not be entered; 'value' recycled
164  mt[-1, 3] <- -2:1  mt[-1, 3] <- -2:1
165  stopifnot(mc@x != 0, mt@x != 0)  stopifnot(mc@x != 0, mt@x != 0,
166  mc[1:5 %% 2 == 0, 3] <- 0            mc[-1,3] == -2:1, mt[-1,3] == -2:1) ##--> BUG -- fixed
167    ## source("~/R/Pkgs/Matrix/R/Tsparse.R")
168    ## Matrix_expand_pointers <- Matrix:::Matrix_expand_pointers
169    ## -> open ../R/dgCMatrix.R  --> replCmat  .. now eval-line by line ..
170    
171    ev <- 1:5 %% 2 == 0
172    mc[ev, 3] <- 0:1
173    ##FIXME stopifnot(mc[ev, 3] == 0:1) ##-> BUG  {very peculiar; the 2nd time it works ...}
174  validObject(mc)  validObject(mc)
175  mc  mc # now shows a non-structural zeros
176  mc[ii, jj] <- 1:6  mc[ii, jj] <- 1:6
177  mc[c(2,5), c(3,5)] <- 3.2  mc[c(2,5), c(3,5)] <- 3.2
178  validObject(mc)  validObject(mc)
179  mc  (m. <- mc)
180    ## FIXME: mc[4,] <- 0 # -> error -- another Bug
181    
182    H <- Hilbert(9)
183    Hc <- as(round(H, 3), "dsCMatrix")
184    tril(Hc[1:5, 1:5])
185    
186    H[c(1:2, 4, 6:7), c(2:4,6)] <- 0
187    (H. <- round(as(H, "sparseMatrix"), 3)[ , 2:7])
188    Hc. <- Hc
189    Hc.[c(1:2, 4, 6:7), c(2:4,6)] <- 0
190    Hc.[, 1:6]
191    
192  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''  cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''

Legend:
Removed from v.1269  
changed lines
  Added in v.1347

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