SCM

SCM Repository

[matrix] Annotation of /pkg/tests/indexing.R
ViewVC logotype

Annotation of /pkg/tests/indexing.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 687 - (view) (download)

1 : maechler 687 #### For both 'Extract' ("[") and 'Replace' ("[<-") Method testing
2 :    
3 :     library(Matrix)
4 :    
5 :     identical3 <- function(x,y,z) identical(x,y) && identical (y,z)
6 :     identical4 <- function(a,b,c,d) identical(a,b) && identical3(b,c,d)
7 :    
8 :     m <- Matrix(1:28, nrow = 7)
9 :    
10 :     ## TODO: not yet for dense matrices
11 :    
12 :    
13 :     ### Sparse Matrices
14 :    
15 :     m <- 1:800
16 :     set.seed(101) ; m[sample(800, 600)] <- 0
17 :     m <- Matrix(m, nrow = 40)
18 :     mm <- as(m, "matrix")
19 :     dimnames(mm) <- NULL ## << workaround: as(<sparse>, "matrix") has NULL dimnames
20 :     str(mC <- as(m, "dgCMatrix"))
21 :     str(mT <- as(m, "dgTMatrix"))
22 :     stopifnot(identical(mT, as(mC, "dgTMatrix")),
23 :     identical(mC, as(mT, "dgCMatrix")))
24 :    
25 :     mC[,1]
26 :     mC[1:2,]
27 :     mC[7, drop = FALSE]
28 :    
29 :     mT[,c(2,4)]
30 :     mT[1,]
31 :     mT[4, drop = FALSE]
32 :     stopifnot(identical3(mm[,1], mC[,1], mT[,1]),
33 :     identical3(mm[3,], mC[3,], mT[3,]),
34 :     identical3(mT[2,3], mC[2,3], 0),
35 :     identical(mT[], mT),
36 :     ## TODO: identical4() with m[c(3,7), 2:4]
37 :     identical3(as(mC[c(3,7), 2:4],"matrix"), mm[c(3,7), 2:4],
38 :     as(mT[c(3,7), 2:4],"matrix")))
39 :    
40 :    

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