SCM

SCM Repository

[matrix] Diff of /pkg/R/sparseMatrix.R
ViewVC logotype

Diff of /pkg/R/sparseMatrix.R

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

revision 2206, Wed Jun 25 14:57:02 2008 UTC revision 2207, Mon Jul 7 22:34:52 2008 UTC
# Line 124  Line 124 
124    
125  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))
126  setAs("sparseMatrix", "graphNEL",  setAs("sparseMatrix", "graphNEL",
127        function(from) as(as(from, "TsparseMatrix"), "graphNEL"))        ## since have specific method for Tsparse below, are Csparse or Rsparse,
128          ## i.e. do not need to "uniquify" the T* matrix:
129          function(from) Tsp2grNEL(as(from, "TsparseMatrix"), need.uniq=FALSE))
130    
131  Tsp2grNEL <- function(from) {  Tsp2grNEL <- function(from, need.uniq = is_not_uniqT(from)) {
132      d <- dim(from)      d <- dim(from)
133      if(d[1] != d[2])      if(d[1] != d[2])
134          stop("only square matrices can be used as incidence matrices for graphs")          stop("only square matrices can be used as incidence matrices for graphs")
# Line 134  Line 136 
136      if(n == 0) return(new("graphNEL"))      if(n == 0) return(new("graphNEL"))
137      if(is.null(rn <- dimnames(from)[[1]]))      if(is.null(rn <- dimnames(from)[[1]]))
138          rn <- as.character(1:n)          rn <- as.character(1:n)
139      from <- uniq(from) ## Need to 'uniquify' the triplets!      if(need.uniq) ## Need to 'uniquify' the triplets!
140            from <- uniq(from)
141    
142      if(isSymmetric(from)) { # either "symmetricMatrix" or otherwise      if(isSymmetric(from)) { # either "symmetricMatrix" or otherwise
143          ##-> undirected graph: every edge only once!          ##-> undirected graph: every edge only once!
# Line 153  Line 156 
156      ftM2graphNEL(ft1, W = from@x, V= rn, edgemode= eMode)      ftM2graphNEL(ft1, W = from@x, V= rn, edgemode= eMode)
157    
158  }  }
159  setAs("TsparseMatrix", "graphNEL", Tsp2grNEL)  setAs("TsparseMatrix", "graphNEL", function(from) Tsp2grNEL(from))
160    
161    
162  ### Subsetting -- basic things (drop = "missing") are done in ./Matrix.R  ### Subsetting -- basic things (drop = "missing") are done in ./Matrix.R
# Line 211  Line 214 
214    
215  ## setReplaceMethod("[", .........)  ## setReplaceMethod("[", .........)
216  ## -> ./Tsparse.R  ## -> ./Tsparse.R
217  ## &  ./Csparse.R  ## &  ./Csparse.R  & ./Rsparse.R {those go via Tsparse}
218  ## FIXME: also for RsparseMatrix  ##
219    ## Do not use as.vector() (see ./Matrix.R ) for "scarce" matrices :
220    setReplaceMethod("[", signature(x = "sparseMatrix", i = "missing", j = "ANY",
221                                    value = "scarceMatrix"),
222                     function (x, i, j, ..., value)
223                     callGeneric(x=x, , j=j, value = as(value, "sparseVector")))
224    
225    setReplaceMethod("[", signature(x = "sparseMatrix", i = "ANY", j = "missing",
226                                    value = "scarceMatrix"),
227                     function (x, i, j, ..., value)
228                     callGeneric(x=x, i=i, , value = as(value, "sparseVector")))
229    
230    setReplaceMethod("[", signature(x = "sparseMatrix", i = "ANY", j = "ANY",
231                                    value = "scarceMatrix"),
232                     function (x, i, j, ..., value)
233                     callGeneric(x=x, i=i, j=j, value = as(value, "sparseVector")))
234    
235    
236    
237  ## Group Methods  ## Group Methods

Legend:
Removed from v.2206  
changed lines
  Added in v.2207

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