SCM Repository

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

revision 1347, Mon Aug 7 08:47:43 2006 UTC revision 1348, Mon Aug 7 09:05:00 2006 UTC
# Line 85  Line 85
85  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))
86  setAs("sparseMatrix", "graphNEL",  setAs("sparseMatrix", "graphNEL",
87        function(from) as(as(from, "TsparseMatrix"), "graphNEL"))        function(from) as(as(from, "TsparseMatrix"), "graphNEL"))
88  setAs("TsparseMatrix", "graphNEL",
89        function(from) {  Tsp2grNEL <- function(from) {
90            d <- dim(from)            d <- dim(from)
91            if(d != d)            if(d != d)
92                stop("only square matrices can be used as incidence matrices for grphs")                stop("only square matrices can be used as incidence matrices for grphs")
# Line 95  Line 95
95            if(is.null(rn <- dimnames(from)[]))            if(is.null(rn <- dimnames(from)[]))
96                rn <- as.character(1:n)                rn <- as.character(1:n)
97            from <- uniq(from) ## Need to 'uniquify' the triplets!            from <- uniq(from) ## Need to 'uniquify' the triplets!
98            if(isSymmetric(from)) { # because it's "dsTMatrix" or otherwise
99                upper <- from@i <= from@j      if(isSymmetric(from)) { # either "symmetricMatrix" or otherwise
100            ##-> undirected graph: every edge only once!
101            if(!is(from, "symmetricMatrix")) {
102                ## a general matrix which happens to be symmetric
103                ## ==> remove the double indices
104                from <- tril(from)
105            }
106            ## every edge is there only once, either upper or lower triangle
107                ft1 <- cbind(from@i + 1:1, from@j + 1:1)                ft1 <- cbind(from@i + 1:1, from@j + 1:1)
108                graph::ftM2graphNEL(rbind(ft1, ft1[, 2:1]),          graph::ftM2graphNEL(ft1, W = from@x, V= rn, edgemode= "undirected")
W = from@x, V=rn, edgemode="undirected")
109
110            } else { ## not symmetric            } else { ## not symmetric
111
112                graph::ftM2graphNEL(cbind(from@i + 1:1, from@j + 1:1),                graph::ftM2graphNEL(cbind(from@i + 1:1, from@j + 1:1),
113                                    W = from@x, V=rn, edgemode="directed")                                    W = from@x, V=rn, edgemode="directed")
114            }            }
## stop("'dgTMatrix -> 'graphNEL' method is not yet implemented")
})

115
116    }
117    setAs("TsparseMatrix", "graphNEL", Tsp2grNEL)
118
119
120  ### Subsetting -- basic things (drop = "missing") are done in ./Matrix.R  ### Subsetting -- basic things (drop = "missing") are done in ./Matrix.R

Legend:
 Removed from v.1347 changed lines Added in v.1348

 root@r-forge.r-project.org ViewVC Help Powered by ViewVC 1.0.0
Thanks to:  