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 2362, Tue Apr 7 09:44:11 2009 UTC revision 2363, Thu Apr 9 20:45:32 2009 UTC
# Line 6  Line 6 
6    
7  if(interactive()) {  if(interactive()) {
8      options(error = recover, warn = 1)      options(error = recover, warn = 1)
9  } else options(verbose = TRUE, warn = 1)  } else options(Matrix.verbose = TRUE, warn = 1)
10    
11  ### Dense Matrices  ### Dense Matrices
12    
# Line 167  Line 167 
167            identical(mC[iN], mm[iN]))            identical(mC[iN], mm[iN]))
168    
169  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])  assert.EQ.mat(mC[7, , drop=FALSE], mm[7, , drop=FALSE])
170    identical    (mC[7,   drop=FALSE], mm[7,   drop=FALSE]) # *vector* indexing
171    
172  stopifnot(dim(mC[numeric(0), ]) == c(0,20), # used to give warnings  stopifnot(dim(mC[numeric(0), ]) == c(0,20), # used to give warnings
173            dim(mC[, integer(0)]) == c(40,0),            dim(mC[, integer(0)]) == c(40,0),
174            identical(mC[, integer(0)], mC[, FALSE]),            identical(mC[, integer(0)], mC[, FALSE]))
           identical(mC[7,  drop = FALSE],  
                     mC[7,, drop = FALSE]))  
175  validObject(print(mT[,c(2,4)]))  validObject(print(mT[,c(2,4)]))
176  stopifnot(all.equal(mT[2,], mm[2,]),  stopifnot(all.equal(mT[2,], mm[2,]),
177            ## row or column indexing in combination with t() :            ## row or column indexing in combination with t() :
# Line 280  Line 279 
279    
280    
281  ## "Vector indices" -------------------  ## "Vector indices" -------------------
282    .iniDiag.example <- expression({
283  D <- Diagonal(6)  D <- Diagonal(6)
284  M <- as(D,"dgeMatrix")  M <- as(D,"dgeMatrix")
285  m <- as(D,"matrix")  m <- as(D,"matrix")
286  s <- as(D,"TsparseMatrix")  s <- as(D,"TsparseMatrix")
287  S <- as(s,"CsparseMatrix")  S <- as(s,"CsparseMatrix")
288    })
289    eval(.iniDiag.example)
290  i <- c(3,1,6); v <- c(10,15,20)  i <- c(3,1,6); v <- c(10,15,20)
291  ## (logical,value) which both are recycled:  ## (logical,value) which both are recycled:
292  L <- c(TRUE, rep(FALSE,8)) ; z <- c(50,99)  L <- c(TRUE, rep(FALSE,8)) ; z <- c(50,99)
# Line 296  Line 298 
298  D[i] <- v; assert.EQ.mat(D,m) # ddi -> dtT -> dgT  D[i] <- v; assert.EQ.mat(D,m) # ddi -> dtT -> dgT
299  s[i] <- v; assert.EQ.mat(s,m) # dtT -> dgT  s[i] <- v; assert.EQ.mat(s,m) # dtT -> dgT
300  S[i] <- v; assert.EQ.mat(S,m); S # dtC -> dtT -> dgT -> dgC  S[i] <- v; assert.EQ.mat(S,m); S # dtC -> dtT -> dgT -> dgC
301    stopifnot(identical(s,D))
302  ## logical  ## logical
303    eval(.iniDiag.example)
304  m[L] <- z  m[L] <- z
305  M[L] <- z; assert.EQ.mat(M,m)  M[L] <- z; assert.EQ.mat(M,m)
306  D[L] <- z; assert.EQ.mat(D,m)  D[L] <- z; assert.EQ.mat(D,m)
# Line 304  Line 308 
308  S[L] <- z; assert.EQ.mat(S,m) ; S  S[L] <- z; assert.EQ.mat(S,m) ; S
309    
310  ## indexing [i]  vs  [i,] --- now ok  ## indexing [i]  vs  [i,] --- now ok
311  stopifnot(identical4(m[i], M[i], D[i], s[i]), identical(s[i],S[i]))  eval(.iniDiag.example)
312  stopifnot(identical4(m[L], M[L], D[L], s[L]), identical(s[L],S[L]))  stopifnot(identical5(m[i], M[i], D[i], s[i], S[i]))
313    stopifnot(identical5(m[L], M[L], D[L], s[L], S[L]))
314    ## bordercase ' drop = .' *vector* indexing {failed till 2009-04-..)
315    stopifnot(identical5(m[i,drop=FALSE], M[i,drop=FALSE], D[i,drop=FALSE],
316                         s[i,drop=FALSE], S[i,drop=FALSE]))
317    stopifnot(identical5(m[L,drop=FALSE], M[L,drop=FALSE], D[L,drop=FALSE],
318                         s[L,drop=FALSE], S[L,drop=FALSE]))
319    ##
320  assert.EQ.mat(D[i,], m[i,])  assert.EQ.mat(D[i,], m[i,])
321  assert.EQ.mat(M[i,], m[i,])  assert.EQ.mat(M[i,], m[i,])
322  assert.EQ.mat(s[i,], m[i,])  assert.EQ.mat(s[i,], m[i,])

Legend:
Removed from v.2362  
changed lines
  Added in v.2363

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