SCM

SCM Repository

[matrix] Diff of /pkg/tests/matprod.R
ViewVC logotype

Diff of /pkg/tests/matprod.R

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

revision 1547, Mon Sep 11 14:49:39 2006 UTC revision 1548, Mon Sep 11 22:13:07 2006 UTC
# Line 85  Line 85 
85  nrFT <- nrow(fromTo)  nrFT <- nrow(fromTo)
86  rowi <- rep.int(1:nrFT, fromTo[,2]-fromTo[,1] + 1) - 1:1  rowi <- rep.int(1:nrFT, fromTo[,2]-fromTo[,1] + 1) - 1:1
87  coli <- unlist(lapply(1:nrFT, function(x) fromTo[x,1]:fromTo[x,2])) - 1:1  coli <- unlist(lapply(1:nrFT, function(x) fromTo[x,1]:fromTo[x,2])) - 1:1
88    
89    ## "n" --- nonzero pattern Matrices
90    sM  <- new("ngTMatrix", i = rowi, j=coli, Dim=as.integer(c(N,N)))
91    sM # nice
92    
93    sm <- as(sM, "matrix")
94    sM %*% sM
95    assert.EQ.mat(sM %*% sM,        sm %*% sm)
96    assert.EQ.mat(t(sM) %*% sM,
97                  (t(sm) %*% sm) > 0, tol=0)
98    crossprod(sM)
99    tcrossprod(sM)
100    stopifnot(identical(as( crossprod(sM), "ngCMatrix"), t(sM) %*%   sM),
101              identical(as(tcrossprod(sM), "ngCMatrix"),  sM  %*% t(sM)))
102    
103    assert.EQ.mat( crossprod(sM),  crossprod(sm) > 0)
104    assert.EQ.mat(tcrossprod(sM), as(tcrossprod(sm),"matrix") > 0)
105    
106    ## "l" --- logical Matrices -- use usual 0/1 arithmetic
107    if(FALSE) { ### Matrix product for lsparse --> garbage --- FIXME
108  sM  <- new("lgTMatrix", i = rowi, j=coli, Dim=as.integer(c(N,N)))  sM  <- new("lgTMatrix", i = rowi, j=coli, Dim=as.integer(c(N,N)))
109  sM # nice  sM # nice
110    
# Line 100  Line 120 
120    
121  assert.EQ.mat( crossprod(sM),  crossprod(sm) > 0)  assert.EQ.mat( crossprod(sM),  crossprod(sm) > 0)
122  assert.EQ.mat(tcrossprod(sM), as(tcrossprod(sm),"matrix") > 0)  assert.EQ.mat(tcrossprod(sM), as(tcrossprod(sm),"matrix") > 0)
123    }
124    
125  ## A sparse example - with *integer* matrix:  ## A sparse example - with *integer* matrix:
126  M <- Matrix(cbind(c(1,0,-2,0,0,0,0,0,2.2,0),  M <- Matrix(cbind(c(1,0,-2,0,0,0,0,0,2.2,0),
# Line 113  Line 134 
134  stopifnot(class(MM.) == "dsCMatrix",  stopifnot(class(MM.) == "dsCMatrix",
135            class(M.M) == "dsCMatrix")            class(M.M) == "dsCMatrix")
136    
137    
138  ## even simpler  ## even simpler
139  m <- matrix(0, 4,7); m[c(1, 3, 6, 9, 11, 22, 27)] <- 1  m <- matrix(0, 4,7); m[c(1, 3, 6, 9, 11, 22, 27)] <- 1
140  (mm <- Matrix(m))  (mm <- Matrix(m))

Legend:
Removed from v.1547  
changed lines
  Added in v.1548

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