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 1829, Thu Apr 26 06:35:20 2007 UTC revision 1833, Tue May 8 12:25:57 2007 UTC
# Line 82  Line 82 
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 ...  ## *repeated* (aka 'duplicated') indices - did not work at all ...
86  i <- rep(8:10,2)  i <- rep(8:10,2)
87  j <- c(2:4, 4:3)  j <- c(2:4, 4:3)
88  assert.EQ.mat(mC[i,], mm[i,])  assert.EQ.mat(mC[i,], mm[i,])
89  assert.EQ.mat(mC[,j], mm[,j])  assert.EQ.mat(mC[,j], mm[,j])
90  assert.EQ.mat(mC[i, 2:1], mm[i, 2:1])  assert.EQ.mat(mC[i, 2:1], mm[i, 2:1])
91  assert.EQ.mat(mC[c(4,1), j], mm[c(4,1), j])  assert.EQ.mat(mC[c(4,1,2:1), j], mm[c(4,1,2:1), j])
92  assert.EQ.mat(mC[i,j], mm[i,j])  assert.EQ.mat(mC[i,j], mm[i,j])
93  set.seed(7)  set.seed(7)
94  for(n in 1:50) {  for(n in 1:50) {
# Line 96  Line 96 
96      j <- sample(sample(ncol(mC), 6), 17, replace = TRUE)      j <- sample(sample(ncol(mC), 6), 17, replace = TRUE)
97      assert.EQ.mat(mC[i,j], mm[i,j])      assert.EQ.mat(mC[i,j], mm[i,j])
98  }  }
99  ## symmetric index of symmetric matrix 000 not yet  ok  ## symmetric index of symmetric matrix --- not yet  ok
100  m. <- mC; m.[, c(2, 7:12)] <- 0  m. <- mC; m.[, c(2, 7:12)] <- 0
101  validObject(S <- crossprod(m.) %% 100)  validObject(S <- crossprod(add.simpleDimnames(m.) %% 100))
102  ss <- as(S, "matrix")  ss <- as(S, "matrix")
103  T <- as(S, "TsparseMatrix")  T <- as(S, "TsparseMatrix")
104  i <- c(4:2,7) ;  assert.EQ.mat(T[i,i], ss[i,i])  ## non-repeated indices:
105  i <- c(7:5, 2:4);assert.EQ.mat(T[i,i], ss[i,i])  i <- c(7:5, 2:4);assert.EQ.mat(T[i,i], ss[i,i])
106    N <- nrow(T)
107    set.seed(11)
108    for(n in 1:50) {
109        i <- sample(N, max(2, sample(N,1)), replace = FALSE)
110        validObject(Tii <- T[i,i])
111        stopifnot(is(Tii, "dsTMatrix"), # remained symmetric Tsparse
112                  identical(t(Tii), t(T)[i,i]))
113        assert.EQ.mat(Tii, ss[i,i])
114    }
115    
116    ## repeeated ones:
117    j <- c(4, 4, 9, 12, 9, 4, 17, 3, 18, 4, 12, 18, 4, 9)
118  if(FALSE) ## FIXME  if(FALSE) ## FIXME
119  assert.EQ.mat(T[j,j], ss[j,j])  assert.EQ.mat(T[j,j], ss[j,j])
120    
# Line 151  Line 163 
163            identical(as.mat(l3 ), m.x[1:3, ] != 0)            identical(as.mat(l3 ), m.x[1:3, ] != 0)
164            )            )
165    
166    ##-- Sub*assignment* with repeated / duplicated index:
167    A <- Matrix(0,4,3) ; A[c(1,2,1), 2] <- 1 ; A
168    B <- A;              B[c(1,2,1), 2] <- 1:3; B
169    stopifnot(identical(unname(as.matrix(A)),
170                        local({a <- matrix(0,4,3); a[c(1,2,1), 2] <-  1 ; a})),
171              identical(unname(as.matrix(B)),
172                        local({a <- matrix(0,4,3); a[c(1,2,1), 2] <- 1:3; a})))
173    
174    
175  ## used to fail  ## used to fail
176  n <- 5 ## or much larger  n <- 5 ## or much larger
177  sm <- new("dsTMatrix", i=as.integer(1),j=as.integer(1),  sm <- new("dsTMatrix", i=as.integer(1),j=as.integer(1),

Legend:
Removed from v.1829  
changed lines
  Added in v.1833

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