SCM

SCM Repository

[matrix] Diff of /pkg/tests/indexing.Rout.save
ViewVC logotype

Diff of /pkg/tests/indexing.Rout.save

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1723, Sat Jan 13 16:29:29 2007 UTC revision 1724, Sat Jan 13 21:06:51 2007 UTC
# Line 1  Line 1 
1    
2  R version 2.4.1 Patched (2006-12-24 r40305)  R version 2.4.1 Patched (2007-01-11 r40446)
3  Copyright (C) 2006 The R Foundation for Statistical Computing  Copyright (C) 2007 The R Foundation for Statistical Computing
4  ISBN 3-900051-07-0  ISBN 3-900051-07-0
5    
6  R is free software and comes with ABSOLUTELY NO WARRANTY.  R is free software and comes with ABSOLUTELY NO WARRANTY.
# Line 430  Line 430 
430  > 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)))
431  >  >
432  >  >
 >  
433  > ## --- negative indices ----------  > ## --- negative indices ----------
434  > mc <- mC[1:5, 1:7]  > mc <- mC[1:5, 1:7]
435  > mt <- mT[1:5, 1:7]  > mt <- mT[1:5, 1:7]
# Line 532  Line 531 
531  +         mc[-1,3] == -2:1, mt[-1,3] == -2:1) ## failed earlier  +         mc[-1,3] == -2:1, mt[-1,3] == -2:1) ## failed earlier
532  >  >
533  > mc0 <- mc  > mc0 <- mc
534    > mt0 <- as(mc0, "TsparseMatrix")
535    > m0  <- as(mc0, "matrix")
536  > set.seed(1)  > set.seed(1)
537  > for(i in 1:20) {  > for(i in 1:50) {
538  +     mc <- mc0  +     mc <- mc0; mt <- mt0 ; m <- m0
539  +     ev <- 1:5 %% 2 == round(runif(1))# 0 or 1  +     ev <- 1:5 %% 2 == round(runif(1))# 0 or 1
540  +     j <- sample(ncol(mc), 1 + round(runif(1)))  +     j <- sample(ncol(mc), 1 + round(runif(1)))
541  +     nv <- rpois(sum(ev) * length(j), lambda = 1)  +     nv <- rpois(sum(ev) * length(j), lambda = 1)
542  +     mc[ev, j] <- nv  +     mc[ev, j] <- nv
543  +     if(i < 5) print(mc[ev,j, drop = FALSE])  +      m[ev, j] <- nv
544  +     stopifnot(as.vector(mc[ev, j]) == nv) ## failed earlier...  +     mt[ev, j] <- nv
545  +     validObject(mc)  +     if(i %% 10 == 1) print(mc[ev,j, drop = FALSE])
546    +     stopifnot(as.vector(mc[ev, j]) == nv, ## failed earlier...
547    +               as.vector(mt[ev, j]) == nv)
548    +     validObject(mc) ; assert.EQ.mat(mc, m)
549    +     validObject(mt) ; assert.EQ.mat(mt, m)
550  + }  + }
551  2 x 1 sparse Matrix of class "dgCMatrix"  2 x 1 sparse Matrix of class "dgCMatrix"
552    
553  [1,] 2  [1,] 2
554  [2,] .  [2,] .
555    2 x 1 sparse Matrix of class "dgCMatrix"
556    
557    [1,] 2
558    [2,] 1
559  3 x 2 sparse Matrix of class "dgCMatrix"  3 x 2 sparse Matrix of class "dgCMatrix"
560    
561  [1,] . 1  [1,] 1 .
562  [2,] . 1  [2,] . .
563  [3,] . 2  [3,] 1 .
564  2 x 2 sparse Matrix of class "dgCMatrix"  3 x 1 sparse Matrix of class "dgCMatrix"
565    
566  [1,] 2 .  [1,] 1
567  [2,] 3 1  [2,] 1
568  2 x 1 sparse Matrix of class "dgCMatrix"  [3,] 1
569    3 x 1 sparse Matrix of class "dgCMatrix"
570    
571  [1,] .  [1,] .
572  [2,] 1  [2,] 3
573    [3,] 1
574  >  >
575  > mc # no longer has non-structural zeros  > mc # no longer has non-structural zeros
576  5 x 7 sparse Matrix of class "dgCMatrix"  5 x 7 sparse Matrix of class "dgCMatrix"
577    
578  [1,] .  1  2 4 .   . 2  [1,] .  .  2 4 . . 241
579  [2,] . 42 -2 3 . 202 .  [2,] 1 42 -2 3 . 1   .
580  [3,] 3  1 -1 . .   . .  [3,] 3  . -1 . . . 243
581  [4,] .  .  . . .   . .  [4,] 1  .  . . . 1   .
582  [5,] .  .  1 . .   . 2  [5,] . 45  1 . . .   .
583  > mc[ii, jj] <- 1:6  > mc[ii, jj] <- 1:6
584  > mc[c(2,5), c(3,5)] <- 3.2  > mc[c(2,5), c(3,5)] <- 3.2
585  > validObject(mc)  > validObject(mc)
# Line 578  Line 589 
589  > mc  > mc
590  5 x 7 sparse Matrix of class "dgCMatrix"  5 x 7 sparse Matrix of class "dgCMatrix"
591    
592  [1,] . 1  2.0 4 .     . 2  [1,] . .  2.0 4 .   . 241
593  [2,] . 1  3.2 3 3.2 202 .  [2,] 1 1  3.2 3 3.2 1   .
594  [3,] 3 1 -1.0 . .     . .  [3,] 3 . -1.0 . .   . 243
595  [4,] . .  .   . .     . .  [4,] . .  .   . .     . .
596  [5,] . 2  3.2 . 3.2   . 2  [5,] . 2  3.2 . 3.2 .   .
597  >  >
598  > H <- Hilbert(9)  > H <- Hilbert(9)
599  > Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...  > Hc <- as(round(H, 3), "dsCMatrix")# a sparse matrix with no 0 ...
# Line 626  Line 637 
637   [8,] 0.125 0.111 0.100 0.091 0.083 0.077   [8,] 0.125 0.111 0.100 0.091 0.083 0.077
638   [9,] 0.111 0.100 0.091 0.083 0.077 0.071   [9,] 0.111 0.100 0.091 0.083 0.077 0.071
639  >  >
640  > ## an example that failed long  > ## an example that failed for a long time
641  > sy3 <- new("dsyMatrix", Dim = as.integer(c(2, 2)), x = c(14, -1, 2, -7))  > sy3 <- new("dsyMatrix", Dim = as.integer(c(2, 2)), x = c(14, -1, 2, -7))
642  > validObject(dm <- kronecker(Diagonal(2), sy3))  > validObject(dm <- kronecker(Diagonal(2), sy3))
643  Warning message:  Warning message:
# Line 666  Line 677 
677  [1] TRUE  [1] TRUE
678  > s2[I,I] <- 0; validObject(s2); stopifnot(is(s2,"symmetricMatrix"))  > s2[I,I] <- 0; validObject(s2); stopifnot(is(s2,"symmetricMatrix"))
679  [1] TRUE  [1] TRUE
680  >  > ##
681  > m <- as.mat(st)  > m <- as.mat(st)
682  >  m[2:1,2:1] <- 4:1  >  m[2:1,2:1] <- 4:1
683  > st[2:1,2:1] <- 4:1  > st[2:1,2:1] <- 4:1
# Line 675  Line 686 
686  +         1:4 == as.vector(s2[1:2,1:2]),  +         1:4 == as.vector(s2[1:2,1:2]),
687  +         identical(m, as.mat(s2)))  +         identical(m, as.mat(s2)))
688  >  >
689    > ## now a slightly different situation for 's2' (had bug)
690    > s2 <- as(dm, "sparseMatrix")
691    > s2[I,I] <- 0; diag(s2)[2:3] <- -(1:2)
692    > stopifnot(is(s2,"symmetricMatrix"), diag(s2) == c(0:-2,0))
693    > t2 <- as(s2, "TsparseMatrix")
694    > m <- as.mat(s2)
695    > s2[2:1,2:1] <- 4:1
696    > t2[2:1,2:1] <- 4:1
697    >  m[2:1,2:1] <- 4:1
698    > assert.EQ.mat(t2, m)
699    > assert.EQ.mat(s2, m)
700    > ## and the same (for a different s2 !)
701    > s2[2:1,2:1] <- 4:1
702    > t2[2:1,2:1] <- 4:1
703    > assert.EQ.mat(t2, m)# ok
704    > assert.EQ.mat(s2, m)# failed in 0.9975-8
705    >
706    >
707  > ## m[cbind(i,j)] <- value:  > ## m[cbind(i,j)] <- value:
708  > m.[ cbind(3:5, 1:3) ] <- 1:3  > m.[ cbind(3:5, 1:3) ] <- 1:3
709  > stopifnot(m.[3,1] == 1, m.[4,2] == 2)  > stopifnot(m.[3,1] == 1, m.[4,2] == 2)
# Line 685  Line 714 
714  +         12:16 == as.mat(x.x)[cbind(2:6, 2:6)])  +         12:16 == as.mat(x.x)[cbind(2:6, 2:6)])
715  >  >
716  > cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''  > cat('Time elapsed: ', proc.time(),'\n') # for ``statistical reasons''
717  Time elapsed:  4.363 0.13 5.224 0 0  Time elapsed:  5.951 0.154 6.891 0 0
718  >  >

Legend:
Removed from v.1723  
changed lines
  Added in v.1724

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