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 873, Sat Aug 27 21:26:23 2005 UTC revision 1215, Wed Feb 8 17:54:57 2006 UTC
# Line 2  Line 2 
2    
3  library(Matrix)  library(Matrix)
4    
5  identical3 <- function(x,y,z)   identical(x,y) && identical (y,z)  source(system.file("test-tools.R", package = "Matrix"))# identical3() etc
 identical4 <- function(a,b,c,d) identical(a,b) && identical3(b,c,d)  
6    
7  ### Dense Matrices  ### Dense Matrices
8    
# Line 27  Line 26 
26            identical(m[2,], m[(1:nrow(m)) == 2, ]),            identical(m[2,], m[(1:nrow(m)) == 2, ]),
27            identical(m[,3:4], m[, (1:4) >= 3]))            identical(m[,3:4], m[, (1:4) >= 3]))
28    
29  ## dimnames index (TODO)  ## dimnames indexing:
30    mn <- m
31    dimnames(mn) <- list(paste("r",letters[1:nrow(mn)],sep=""),
32                         LETTERS[1:ncol(mn)])
33    mn["rd", "D"]
34    stopifnot(identical(mn["rc", "D"], mn[3,4]),
35              identical(mn[, "A"], mn[,1]),
36              identical(mn[c("re", "rb"), "B"], mn[c(5,2), 2])
37              )
38    
39    mo <- m
40    m[2,3] <- 100
41    m[1:2, 4] <- 200
42    m[, 1] <- -1
43    m[1:3,]
44    
45  ## TODO: more --- particularly once we have "m > 10" working!  ## TODO: more --- particularly once we have "m > 10" working!
46    
# Line 47  Line 60 
60  mC[,1]  mC[,1]
61  mC[1:2,]  mC[1:2,]
62  mC[7, drop = FALSE]  mC[7, drop = FALSE]
63    stopifnot(identical(mC[7,  drop = FALSE],
64                        mC[7,, drop = FALSE]))
65  mT[,c(2,4)]  mT[,c(2,4)]
66  mT[1,]  mT[1,]
67  mT[4, drop = FALSE]  mT[4, drop = FALSE]
# Line 55  Line 69 
69            identical3(mm[3,], mC[3,], mT[3,]),            identical3(mm[3,], mC[3,], mT[3,]),
70            identical3(mT[2,3], mC[2,3], 0),            identical3(mT[2,3], mC[2,3], 0),
71            identical(mT[], mT),            identical(mT[], mT),
72            ## TODO: identical4() with  m[c(3,7), 2:4]            ## TODO: identical4() with  m[c(3,7), 2:4] - fail because of 'dimnames'
73            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],
74                       as(mT[c(3,7), 2:4],"matrix")))                       as(mT[c(3,7), 2:4],"matrix")))
75    
76    ## --- negative indices ----------
77    mc <- mC[1:5, 1:7]
78    mt <- mT[1:5, 1:7]
79    ## sub matrix
80    stopifnot(identical(mc[-(3:5), 0:2], mC[1:2, 0:2]),
81              identical(mt[-(3:5), 0:2], mT[1:2, 0:2]))
82    ## sub vector
83    stopifnot(identical4(mc[-(1:4), ], mC[5, 1:7],
84                         mt[-(1:4), ], mT[5, 1:7]))
85    stopifnot(identical4(mc[-(1:4), -(2:4)], mC[5, c(1,5:7)],
86                         mt[-(1:4), -(2:4)], mT[5, c(1,5:7)]))
87    
88    ## mixing of negative and positive must give error
89    assertError(mT[-1:1,])
90    
91    
92    # now works
93    mT[1, 4] <- -99
94    mT[1:2, 1:7]
95    ## At least these now give a nicely understandable error:
96    try(mT[2:3, ] <- 0)
97    

Legend:
Removed from v.873  
changed lines
  Added in v.1215

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