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 1835, Fri May 11 10:41:21 2007 UTC revision 2098, Sun Dec 9 00:35:14 2007 UTC
# Line 186  Line 186 
186    
187  ##-- Sub*assignment* with repeated / duplicated index:  ##-- Sub*assignment* with repeated / duplicated index:
188  A <- Matrix(0,4,3) ; A[c(1,2,1), 2] <- 1 ; A  A <- Matrix(0,4,3) ; A[c(1,2,1), 2] <- 1 ; A
189  B <- A;              B[c(1,2,1), 2] <- 1:3; B  B <- A;              B[c(1,2,1), 2] <- 1:3; B; B. <- B
190    B.[3,] <- rbind(4:2)
191    diag(B.) <- 10 * diag(B.)
192    C <- B.; C[,2] <- C[,2];  C[1,] <- C[1,]; C[2:3,2:1] <- C[2:3,2:1]
193  stopifnot(identical(unname(as.matrix(A)),  stopifnot(identical(unname(as.matrix(A)),
194                      local({a <- matrix(0,4,3); a[c(1,2,1), 2] <-  1 ; a})),                      local({a <- matrix(0,4,3); a[c(1,2,1), 2] <-  1 ; a})),
195            identical(unname(as.matrix(B)),            identical(unname(as.matrix(B)),
196                      local({a <- matrix(0,4,3); a[c(1,2,1), 2] <- 1:3; a})))                      local({a <- matrix(0,4,3); a[c(1,2,1), 2] <- 1:3; a})),
197              identical(C, drop0(B.)))
198    
199    
200  ## used to fail  ## used to fail
# Line 245  Line 249 
249  stopifnot(is(T, "dtCMatrix"), identical(T[,3], c(10,10,10,0,0)))  stopifnot(is(T, "dtCMatrix"), identical(T[,3], c(10,10,10,0,0)))
250    
251    
252    ## "Vector indices" -------------------
253    D <- Diagonal(6)
254    M <- as(D,"dgeMatrix")
255    m <- as(D,"matrix")
256    s <- as(D,"TsparseMatrix")
257    S <- as(s,"CsparseMatrix")
258    i <- c(3,1,6); v <- c(10,15,20)
259    ## (logical,value) which both are recycled:
260    L <- c(TRUE, rep(FALSE,8)) ; z <- c(50,99)
261    
262    ## vector subassignment, both with integer & logical
263    ## these now work correctly {though not very efficiently; hence warnings}
264    m[i] <- v # the role model: only first column is affected
265    M[i] <- v; assert.EQ.mat(M,m) # dge
266    D[i] <- v; assert.EQ.mat(D,m) # ddi -> dtT -> dgT
267    s[i] <- v; assert.EQ.mat(s,m) # dtT -> dgT
268    S[i] <- v; assert.EQ.mat(S,m); S # dtC -> dtT -> dgT -> dgC
269    ## logical
270    m[L] <- z
271    M[L] <- z; assert.EQ.mat(M,m)
272    D[L] <- z; assert.EQ.mat(D,m)
273    s[L] <- z; assert.EQ.mat(s,m)
274    S[L] <- z; assert.EQ.mat(S,m) ; S
275    
276    ## indexing [i]  vs  [i,] --- now ok
277    stopifnot(identical4(m[i], M[i], D[i], s[i]), identical(s[i],S[i]))
278    stopifnot(identical4(m[L], M[L], D[L], s[L]), identical(s[L],S[L]))
279    assert.EQ.mat(D[i,], m[i,])
280    assert.EQ.mat(M[i,], m[i,])
281    assert.EQ.mat(s[i,], m[i,])
282    assert.EQ.mat(S[i,], m[i,])
283    
284    assert.EQ.mat(D[,i], m[,i])
285    assert.EQ.mat(M[,i], m[,i])
286    assert.EQ.mat(s[,i], m[,i])
287    assert.EQ.mat(S[,i], m[,i])
288    
289    
290  ## --- negative indices ----------  ## --- negative indices ----------
291  mc <- mC[1:5, 1:7]  mc <- mC[1:5, 1:7]
292  mt <- mT[1:5, 1:7]  mt <- mT[1:5, 1:7]

Legend:
Removed from v.1835  
changed lines
  Added in v.2098

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