SCM

SCM Repository

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

Diff of /pkg/R/ddenseMatrix.R

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

revision 908, Thu Sep 8 15:30:08 2005 UTC revision 925, Mon Sep 19 19:01:31 2005 UTC
# Line 60  Line 60 
60  if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {  if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {
61      ## for R 2.2.x (and later):      ## for R 2.2.x (and later):
62    
63    ### cbind2
64      setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),      setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),
65                function(x, y) {                function(x, y) {
66                    d <- dim(x); nr <- d[1]; nc <- d[2]                    d <- dim(x); nr <- d[1]; nc <- d[2]
# Line 115  Line 116 
116                    x                    x
117                })                })
118    
119    ### rbind2 -- analogous to cbind2 --- more to do for @x though:
120    
121        setMethod("rbind2", signature(x = "ddenseMatrix", y = "numeric"),
122                  function(x, y) {
123                      if(is.character(dn <- x@Dimnames[[1]])) dn <- c(dn, "")
124                      new("dgeMatrix", Dim = x@Dim + 1:0,
125                          Dimnames = list(dn, x@Dimnames[[2]]),
126                          x = c(rbind2(as(x,"matrix"), y)))
127                  })
128        ## the same, (x,y) <-> (y,x):
129        setMethod("rbind2", signature(x = "numeric", y = "ddenseMatrix"),
130                  function(x, y) {
131                      if(is.character(dn <- y@Dimnames[[1]])) dn <- c("", dn)
132                      new("dgeMatrix", Dim = y@Dim + 1:0,
133                          Dimnames = list(dn, y@Dimnames[[2]]),
134                          x = c(rbind2(x, as(y,"matrix"))))
135                  })
136    
137        setMethod("rbind2", signature(x = "ddenseMatrix", y = "matrix"),
138                  function(x, y) callGeneric(x, as(y, "dgeMatrix")))
139        setMethod("rbind2", signature(x = "matrix", y = "ddenseMatrix"),
140                  function(x, y) callGeneric(as(x, "dgeMatrix"), y))
141    
142        setMethod("rbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
143                  function(x, y) {
144                      nc <- colCheck(x,y)
145                      nrx <- x@Dim[1]
146                      nry <- y@Dim[1]
147                      dn <-
148                          if(!is.null(dnx <- dimnames(x)) |
149                             !is.null(dny <- dimnames(y))) {
150                              ## R and S+ are different in which names they take
151                              ## if they differ -- but there's no warning in any case
152                              list(if(is.null(rx <- dnx[[1]]) && is.null(ry <- dny[[1]]))
153                                   NULL else
154                                   c(if(!is.null(rx)) rx else rep.int("", nrx),
155                                     if(!is.null(ry)) ry else rep.int("", nry)),
156                                   if(!is.null(dnx[[2]])) dnx[[2]] else dny[[2]])
157    
158                          } else list(NULL, NULL)
159                      ## beware of (packed) triangular, symmetric, ...
160                      new("dgeMatrix", Dim = c(nrx + nry, nc), Dimnames = dn,
161                          x = c(rbind2(as(x,"matrix"), as(y,"matrix"))))
162                  })
163    
164  }## R-2.2.x ff  }## R-2.2.x ff

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

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