# SCM Repository

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

# Diff of /pkg/R/sparseMatrix.R

revision 907, Thu Sep 8 15:28:48 2005 UTC revision 908, Thu Sep 8 15:30:08 2005 UTC
# Line 36  Line 36
36            .Call("graphNEL_as_dgTMatrix",            .Call("graphNEL_as_dgTMatrix",
37                  from,                  from,
38                  symmetric = (from@edgemode == "undirected"))                  symmetric = (from@edgemode == "undirected"))

39        })        })
40  setAs("graph", "sparseMatrix",  setAs("graph", "sparseMatrix",
41        function(from) as(as(from,"graphNEL"), "sparseMatrix"))        function(from) as(as(from,"graphNEL"), "sparseMatrix"))
42
43  if(FALSE) {##--- not yet  ##! if(FALSE) {##--- not yet
44
45  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))  setAs("sparseMatrix", "graph", function(from) as(from, "graphNEL"))
46  setAs("sparseMatrix", "graphNEL",  setAs("sparseMatrix", "graphNEL",
47        function(from) as(as(from, "dgTMatrix"), "graphNEL"))        function(from) as(as(from, "dgTMatrix"), "graphNEL"))
48  setAs("dgTMatrix", "graphNEL",  setAs("dgTMatrix", "graphNEL",
49        function(from) {        function(from) {
50            d <- Dim(from)            d <- dim(from)
51            if(d[1] != d[2])            if(d[1] != d[2])
52                stop("only square matrices can be used as incidence matrices for grphs")                stop("only square matrices can be used as incidence matrices for grphs")
53            n <- d[1]            n <- d[1]
54            if(n == 0) return(new("graphNEL"))            if(n == 0) return(new("graphNEL"))
55              if(is.null(rn <- dimnames(from)[[1]]))
56                  rn <- as.character(1:n)
57              if(isSymmetric(from)) { # because it's "dsTMatrix" or otherwise
58                  ## Need to 'uniquify' the triplets!
59                  upper <- from@i <= from@j
60                  graph::ftM2graphNEL(cbind(from@i + 1:1, from@j + 1:1),
61                                      W = from@x, V=rn, edgemode="undirected")
62
63              } else { ## not symmetric
64
65                  graph::ftM2graphNEL(cbind(from@i + 1:1, from@j + 1:1),
66                                      W = from@x, V=rn, edgemode="directed")
67              }
68            stop("'dgTMatrix -> 'graphNEL' method is not yet implemented")            stop("'dgTMatrix -> 'graphNEL' method is not yet implemented")
69            ## new("graphNEL", nodes = paste(1:n) , edgeL = ...)            ## new("graphNEL", nodes = paste(1:n) , edgeL = ...)
70        })        })
71
72  }#--not_yet  ##! }#--not_yet
73
74
75

Legend:
 Removed from v.907 changed lines Added in v.908