SCM

SCM Repository

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

Diff of /pkg/R/Matrix.R

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

revision 1673, Mon Nov 6 20:54:26 2006 UTC revision 2036, Mon Aug 6 12:03:47 2007 UTC
# Line 3  Line 3 
3    
4  ### Virtual coercions -- via smart "helpers" (-> ./Auxiliaries.R)  ### Virtual coercions -- via smart "helpers" (-> ./Auxiliaries.R)
5    
6  setAs("Matrix", "sparseMatrix", function(from) as_Csparse(from))  setAs("Matrix", "sparseMatrix", function(from) as(from, "CsparseMatrix"))
7    setAs("Matrix", "CsparseMatrix", function(from) as_Csparse(from))
8  setAs("Matrix", "denseMatrix",  function(from) as_dense(from))  setAs("Matrix", "denseMatrix",  function(from) as_dense(from))
9    
10    ## Maybe TODO:
11    ## setAs("Matrix", "nMatrix", function(from) ....)
12    
13  ## Most of these work; this is a last resort:  ## Most of these work; this is a last resort:
14  setAs(from = "Matrix", to = "matrix", # do *not* call base::as.matrix() here:  setAs(from = "Matrix", to = "matrix", # do *not* call base::as.matrix() here:
15        function(from) .bail.out.2("coerce", class(from), class(to)))        function(from) .bail.out.2("coerce", class(from), class(to)))
# Line 27  Line 31 
31  setMethod("head", signature(x = "Matrix"), utils::head.matrix)  setMethod("head", signature(x = "Matrix"), utils::head.matrix)
32  setMethod("tail", signature(x = "Matrix"), utils::tail.matrix)  setMethod("tail", signature(x = "Matrix"), utils::tail.matrix)
33    
34    setMethod("drop", signature(x = "Matrix"),
35              function(x) if(all(dim(x) != 1)) x else drop(as(x, "matrix")))
36    
37  ## slow "fall back" method {subclasses should have faster ones}:  ## slow "fall back" method {subclasses should have faster ones}:
38  setMethod("as.vector", signature(x = "Matrix", mode = "missing"),  setMethod("as.vector", signature(x = "Matrix", mode = "missing"),
39            function(x) as.vector(as(x, "matrix")))            function(x) as.vector(as(x, "matrix")))
# Line 56  Line 63 
63    
64  setMethod("dim", signature(x = "Matrix"),  setMethod("dim", signature(x = "Matrix"),
65            function(x) x@Dim, valueClass = "integer")            function(x) x@Dim, valueClass = "integer")
66    
67    setMethod("length", "Matrix", function(x) prod(dim(x)))
68    
69  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)
70    
71    
72  ## not exported but used more than once for "dimnames<-" method :  ## not exported but used more than once for "dimnames<-" method :
73  ## -- or do only once for all "Matrix" classes ??  ## -- or do only once for all "Matrix" classes ??
74  dimnamesGets <- function (x, value) {  dimnamesGets <- function (x, value) {
# Line 75  Line 87 
87  setMethod("unname", signature("Matrix", force="missing"),  setMethod("unname", signature("Matrix", force="missing"),
88            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})
89    
90    setMethod("all", signature(x = "Matrix"),
91              function(x, ..., na.rm)
92              callGeneric(as(x, "lMatrix"), ..., na.rm=na.rm))
93    
94    setMethod("any", signature(x = "Matrix"),
95              function(x, ..., na.rm)
96              callGeneric(as(x, "lMatrix"), ..., na.rm=na.rm))
97    
98    ## NOTE:  "&" and "|"  are now in group "Logic" c "Ops" --> ./Ops.R
99    ##        "!" is in ./not.R
100    
101    
102  Matrix <-  Matrix <-
103      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
104                sparse = NULL, forceCheck = FALSE)                sparse = NULL, forceCheck = FALSE)
# Line 88  Line 112 
112    
113      doDN <- TRUE      doDN <- TRUE
114      if (i.M) {      if (i.M) {
115            if(!missing(nrow) || !missing(ncol)|| !missing(byrow))
116                warning("'nrow', 'ncol', etc, are disregarded when 'data' is \"Matrix\" already")
117          sM <- is(data,"sparseMatrix")          sM <- is(data,"sparseMatrix")
118          if(!forceCheck && ((sparse && sM) || (!sparse && !sM)))          if(!forceCheck && ((sparse && sM) || (!sparse && !sM)))
119              return(data)              return(data)
# Line 101  Line 127 
127          if(length(data) == 1 && is0(data) && !identical(sparse, FALSE)) {          if(length(data) == 1 && is0(data) && !identical(sparse, FALSE)) {
128              ## Matrix(0, ...) : always sparse unless "sparse = FALSE":              ## Matrix(0, ...) : always sparse unless "sparse = FALSE":
129              if(is.null(sparse)) sparse1 <- sparse <- TRUE              if(is.null(sparse)) sparse1 <- sparse <- TRUE
130                i.M <- sM <- TRUE
131              ## will be sparse: do NOT construct full matrix!              ## will be sparse: do NOT construct full matrix!
132              data <- new(if(is.numeric(data)) "dgTMatrix" else              data <- new(if(is.numeric(data)) "dgTMatrix" else
133                          if(is.logical(data)) "lgTMatrix" else                          if(is.logical(data)) "lgTMatrix" else
# Line 115  Line 142 
142              dimnames(data) <- dimnames              dimnames(data) <- dimnames
143          }          }
144          doDN <- FALSE          doDN <- FALSE
145      }      } else if(!missing(nrow) || !missing(ncol)|| !missing(byrow))
146            warning("'nrow', 'ncol', etc, are disregarded for matrix 'data'")
147    
148      ## 'data' is now a "matrix" or "Matrix"      ## 'data' is now a "matrix" or "Matrix"
149      if (doDN && !is.null(dimnames))      if (doDN && !is.null(dimnames))
150          dimnames(data) <- dimnames          dimnames(data) <- dimnames
# Line 158  Line 187 
187                    }, sep="")                    }, sep="")
188          }          }
189    
190      ## Now coerce and return      ## Can we coerce and be done?
191        if(!canCoerce(data,cl)) { ## try to coerce ``via'' virtual classes
192            if(sparse && !sM)
193                data <- as(data, "sparseMatrix")
194            else if(!sparse && !is(data, "denseMatrix"))
195                data <- as(data, "denseMatrix")
196            if(isTri && !is(data, "triangularMatrix"))
197                data <- as(data, "triangularMatrix")
198            else if(isSym && !is(data, "symmetricMatrix"))
199                data <- as(data, "symmetricMatrix")
200        }
201        ## now coerce in any case .. maybe producing sensible error message:
202      as(data, cl)      as(data, cl)
203  }  }
204    
# Line 169  Line 209 
209    
210  setMethod("%*%", signature(x = "Matrix", y = "numeric"),  setMethod("%*%", signature(x = "Matrix", y = "numeric"),
211            function(x, y) callGeneric(x, as.matrix(y)))            function(x, y) callGeneric(x, as.matrix(y)))
   
212  setMethod("%*%", signature(x = "numeric", y = "Matrix"),  setMethod("%*%", signature(x = "numeric", y = "Matrix"),
213            function(x, y) callGeneric(matrix(x, nrow = 1, byrow=TRUE), y))            function(x, y) callGeneric(matrix(x, nrow = 1, byrow=TRUE), y))
214    
215    setMethod("%*%", signature(x = "Matrix", y = "matrix"),
216              function(x, y) callGeneric(x, Matrix(y)))
217    setMethod("%*%", signature(x = "matrix", y = "Matrix"),
218              function(x, y) callGeneric(Matrix(x), y))
219    
220    
221  setMethod("crossprod", signature(x = "Matrix", y = "numeric"),  setMethod("crossprod", signature(x = "Matrix", y = "numeric"),
222            function(x, y = NULL) callGeneric(x, as.matrix(y)))            function(x, y = NULL) callGeneric(x, as.matrix(y)))
223  setMethod("crossprod", signature(x = "numeric", y = "Matrix"),  setMethod("crossprod", signature(x = "numeric", y = "Matrix"),
224            function(x, y = NULL)  callGeneric(as.matrix(x), y))            function(x, y = NULL)  callGeneric(as.matrix(x), y))
225    
226    setMethod("crossprod", signature(x = "Matrix", y = "matrix"),
227              function(x, y) callGeneric(x, Matrix(y)))
228    setMethod("crossprod", signature(x = "matrix", y = "Matrix"),
229              function(x, y) callGeneric(Matrix(x), y))
230    
231  ## The as.matrix() promotion seems illogical to MM,  ## The as.matrix() promotion seems illogical to MM,
232  ## but is according to help(tcrossprod, package = "base") :  ## but is according to help(tcrossprod, package = "base") :
233  setMethod("tcrossprod", signature(x = "Matrix", y = "numeric"),  setMethod("tcrossprod", signature(x = "Matrix", y = "numeric"),
234            function(x, y = NULL) callGeneric(x, as.matrix(y)))            function(x, y = NULL) callGeneric(x, as.matrix(y)))
235  setMethod("tcrossprod", signature(x = "numeric", y = "Matrix"),  setMethod("tcrossprod", signature(x = "numeric", y = "Matrix"),
236            function(x, y = NULL)  callGeneric(as.matrix(x), y))            function(x, y = NULL)  callGeneric(as.matrix(x), y))
237    setMethod("tcrossprod", signature(x = "Matrix", y = "matrix"),
238              function(x, y) callGeneric(x, Matrix(y)))
239    setMethod("tcrossprod", signature(x = "matrix", y = "Matrix"),
240              function(x, y) callGeneric(Matrix(x), y))
241    
242  ## maybe not optimal  ## maybe not optimal
243  setMethod("solve", signature(a = "Matrix", b = "missing"),  setMethod("solve", signature(a = "Matrix", b = "missing"),
244            function(a, b, ...) solve(a, Diagonal(nrow(a))))            function(a, b, ...) solve(a, Diagonal(nrow(a))))
245    
246  setMethod("solve", signature(a = "Matrix", b = "numeric"),  setMethod("solve", signature(a = "Matrix", b = "numeric"),
247            function(a, b, ...) callGeneric(a, as.matrix(b)))            function(a, b, ...) callGeneric(a, Matrix(b)))
248    setMethod("solve", signature(a = "Matrix", b = "matrix"),
249              function(a, b, ...) callGeneric(a, Matrix(b)))
250    setMethod("solve", signature(a = "matrix", b = "Matrix"),
251              function(a, b, ...) callGeneric(Matrix(a), b))
252    
253  ## when no sub-class method is found, bail out  ## when no sub-class method is found, bail out
254  setMethod("solve", signature(a = "Matrix", b = "matrix"),  setMethod("solve", signature(a = "Matrix", b = "matrix"),
255            function(a, b, ...) .bail.out.2("solve", class(a), "matrix"))            function(a, b, ...) .bail.out.2("solve", class(a), "matrix"))
256    setMethod("solve", signature(a = "Matrix", b = "Matrix"),
257              function(a, b, ...) .bail.out.2("solve", class(a), class(b)))
258    setMethod("solve", signature(a = "Matrix", b = "matrix"),
259              function(a, b, ...) .bail.out.2("solve", class(a), class(b)))
260    setMethod("solve", signature(a = "matrix", b = "Matrix"),
261              function(a, b, ...) .bail.out.2("solve", class(a), class(b)))
262    
263  ## bail-out methods in order to get better error messages  ## bail-out methods in order to get better error messages
264  setMethod("%*%", signature(x = "Matrix", y = "Matrix"),  setMethod("%*%", signature(x = "Matrix", y = "Matrix"),
# Line 220  Line 285 
285  setMethod("kronecker", signature(X = "Matrix", Y = "ANY",  setMethod("kronecker", signature(X = "Matrix", Y = "ANY",
286                                   FUN = "ANY", make.dimnames = "ANY"),                                   FUN = "ANY", make.dimnames = "ANY"),
287            function(X, Y, FUN, make.dimnames, ...) {            function(X, Y, FUN, make.dimnames, ...) {
288                  if(is(X, "sparseMatrix"))
289                      warning("using slow kronecker() method")
290                X <- as(X, "matrix") ; Matrix(callGeneric()) })                X <- as(X, "matrix") ; Matrix(callGeneric()) })
291    
292  setMethod("kronecker", signature(X = "ANY", Y = "Matrix",  setMethod("kronecker", signature(X = "ANY", Y = "Matrix",
293                                   FUN = "ANY", make.dimnames = "ANY"),                                   FUN = "ANY", make.dimnames = "ANY"),
294            function(X, Y, FUN, make.dimnames, ...) {            function(X, Y, FUN, make.dimnames, ...) {
295                  if(is(Y, "sparseMatrix"))
296                      warning("using slow kronecker() method")
297                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })
298    
299    
# Line 238  Line 308 
308  setMethod("t", signature(x = "Matrix"),  setMethod("t", signature(x = "Matrix"),
309            function(x) .bail.out.1(.Generic, class(x)))            function(x) .bail.out.1(.Generic, class(x)))
310    
311  ## Group Methods  setMethod("norm", signature(x = "Matrix", type = "character"),
312  setMethod("+", signature(e1 = "Matrix", e2 = "missing"), function(e1) e1)            function(x, type, ...) .bail.out.1(.Generic, class(x)))
313  ## "fallback":  setMethod("rcond", signature(x = "Matrix", type = "character"),
314  setMethod("-", signature(e1 = "Matrix", e2 = "missing"),            function(x, type, ...) .bail.out.1(.Generic, class(x)))
315            function(e1) {  
316                warning("inefficient method used for \"- e1\"")  
317                0-e1  ## for all :
318    setMethod("norm", signature(x = "ANY", type = "missing"),
319              function(x, type, ...) norm(x, type = "O", ...))
320    setMethod("rcond", signature(x = "ANY", type = "missing"),
321              function(x, type, ...) rcond(x, type = "O", ...))
322    
323    
324    
325    
326    
327    ## MM: More or less "Cut & paste" from
328    ## --- diff.default() from  R/src/library/base/R/diff.R :
329    setMethod("diff", signature(x = "Matrix"),
330              function(x, lag = 1, differences = 1, ...) {
331                  if (length(lag) > 1 || length(differences) > 1 ||
332                      lag < 1 || differences < 1)
333                      stop("'lag' and 'differences' must be integers >= 1")
334                  xlen <- nrow(x)
335                  if (lag * differences >= xlen)
336                      return(x[,FALSE][0])  # empty of proper mode
337    
338                  i1 <- -1:-lag
339                  for (i in 1:differences)
340                      x <- x[i1, , drop = FALSE] -
341                          x[-nrow(x):-(nrow(x)-lag+1), , drop = FALSE]
342                  x
343            })            })
344    
345  ## old-style matrices are made into new ones  setMethod("image", "Matrix",
346  setMethod("Ops", signature(e1 = "Matrix", e2 = "matrix"),            function(x, ...) { # coercing to sparse is not inefficient,
347            function(e1, e2) callGeneric(e1, Matrix(e2)))                ##               since we need 'i' and 'j' for levelplot()
348  ##          callGeneric(e1, Matrix(e2, sparse=is(e1,"sparseMatrix"))))                x <- as(as(x, "sparseMatrix"), "dMatrix")
349  setMethod("Ops", signature(e1 = "matrix", e2 = "Matrix"),                callGeneric()
           function(e1, e2) callGeneric(Matrix(e1), e2))  
   
 ## bail-outs -- on highest possible level, hence "Ops", not "Compare"/"Arith" :  
 setMethod("Ops", signature(e1 = "Matrix", e2 = "Matrix"),  
           function(e1, e2) {  
               d <- dimCheck(e1,e2)  
               .bail.out.2(.Generic, class(e1), class(e2))  
350            })            })
 setMethod("Ops", signature(e1 = "Matrix", e2 = "ANY"),  
           function(e1, e2) .bail.out.2(.Generic, class(e1), class(e2)))  
 setMethod("Ops", signature(e1 = "ANY", e2 = "Matrix"),  
           function(e1, e2) .bail.out.2(.Generic, class(e1), class(e2)))  
351    
352    
353    ## Group Methods
354    
355    ##-> see ./Ops.R
356    ##         ~~~~~
357    ## For all  non-dMatrix objects, and note that  "all" and "any" have their own
358    setMethod("Summary", signature(x = "Matrix", na.rm = "ANY"),
359              function(x, ..., na.rm)
360              callGeneric(as(x,"dMatrix"), ..., na.rm = na.rm))
361    
362    
363  ### --------------------------------------------------------------------------  ### --------------------------------------------------------------------------
364  ###  ###
# Line 285  Line 378 
378  ## select rows  ## select rows
379  setMethod("[", signature(x = "Matrix", i = "index", j = "missing",  setMethod("[", signature(x = "Matrix", i = "index", j = "missing",
380                           drop = "missing"),                           drop = "missing"),
381            function(x,i,j, drop) callGeneric(x, i=i, drop= TRUE))            function(x,i,j, drop) {
382                  if(nargs() == 1) { ## e.g. M[0] , M[TRUE],  M[1:2]
383                      if(any(i)) as.vector(x)[i] else as.vector(x[1,1])[FALSE]
384                  } else callGeneric(x, i=i, drop= TRUE)})
385    
386  ## select columns  ## select columns
387  setMethod("[", signature(x = "Matrix", i = "missing", j = "index",  setMethod("[", signature(x = "Matrix", i = "missing", j = "index",
388                           drop = "missing"),                           drop = "missing"),
# Line 313  Line 410 
410          stop("not-yet-implemented 'Matrix' subsetting") ## FIXME          stop("not-yet-implemented 'Matrix' subsetting") ## FIXME
411    
412      } else stop("nargs() = ", nA,      } else stop("nargs() = ", nA,
413                  " should never happen; please report.")                  ".  Extraneous illegal arguments inside '[ .. ]' ?")
414  }  }
415  setMethod("[", signature(x = "Matrix", i = "lMatrix", j = "missing",  setMethod("[", signature(x = "Matrix", i = "lMatrix", j = "missing",
416                           drop = "ANY"),                           drop = "ANY"),
# Line 343  Line 440 
440          ## potentially inefficient -- FIXME --          ## potentially inefficient -- FIXME --
441          unlist(lapply(seq_len(m), function(j) x[i1[j], i2[j]]))          unlist(lapply(seq_len(m), function(j) x[i1[j], i2[j]]))
442    
443      } else stop("nargs() = ", nA, " should never happen; please report.")      } else stop("nargs() = ", nA,
444                    ".  Extraneous illegal arguments inside '[ .. ]' ?")
445  }  }
446  setMethod("[", signature(x = "Matrix", i = "matrix", j = "missing"),# drop="ANY"  setMethod("[", signature(x = "Matrix", i = "matrix", j = "missing"),# drop="ANY"
447            .M.sub.i.2col)            .M.sub.i.2col)
# Line 356  Line 454 
454                                  value = "ANY"),## double/logical/...                                  value = "ANY"),## double/logical/...
455            function (x, value) {            function (x, value) {
456                ## Fails for 'nMatrix' ... FIXME : make sure have method there                ## Fails for 'nMatrix' ... FIXME : make sure have method there
457                x@x <- value                x@x <- rep(value, length = length(x@x))
458                validObject(x)# check if type and lengths above match                validObject(x)# check if type and lengths above match
459                x                x
460            })            })
461    
462  ## A[ ij ] <- value,  where ij is (i,j) 2-column matrix :  ## A[ ij ] <- value,  where ij is (i,j) 2-column matrix :
463    ## ----------------   The cheap general method --- FIXME: provide special ones
464  .M.repl.i.2col <- function (x, i, j, value)  .M.repl.i.2col <- function (x, i, j, value)
465  {  {
466      nA <- nargs()      nA <- nargs()
# Line 369  Line 468 
468          if(!is.integer(nc <- ncol(i)))          if(!is.integer(nc <- ncol(i)))
469              stop("'i' has no integer column number",              stop("'i' has no integer column number",
470                   " should never happen; please report")                   " should never happen; please report")
471            else if(!is.numeric(i) || nc != 2)
472                stop("such indexing must be by logical or 2-column numeric matrix")
473          if(is.logical(i)) {          if(is.logical(i)) {
474                message(".M.repl.i.2col(): drop 'matrix' case ...")
475              i <- c(i) # drop "matrix"              i <- c(i) # drop "matrix"
476              return( callNextMethod() )              return( callNextMethod() )
477          } else if(!is.numeric(i) || nc != 2)          }
478              stop("such indexing must be by logical or 2-column numeric matrix")          if(!is.integer(i)) storage.mode(i) <- "integer"
479            if(any(i < 0))
480                stop("negative values are not allowed in a matrix subscript")
481            if(any(is.na(i)))
482                stop("NAs are not allowed in subscripted assignments")
483            if(any(i0 <- (i == 0))) # remove them
484                i <- i[ - which(i0, arr.ind = TRUE)[,"row"], ]
485            ## now have integer i >= 1
486          m <- nrow(i)          m <- nrow(i)
487          mod.x <- .type.kind[.M.kind(x)]          ## mod.x <- .type.kind[.M.kind(x)]
488          if(length(value) > 0 && m %% length(value) != 0)          if(length(value) > 0 && m %% length(value) != 0)
489              warning("number of items to replace is not a multiple of replacement length")              warning("number of items to replace is not a multiple of replacement length")
490          ## recycle:          ## recycle:
# Line 385  Line 494 
494          ## inefficient -- FIXME -- (also loses "symmetry" unnecessarily)          ## inefficient -- FIXME -- (also loses "symmetry" unnecessarily)
495          for(k in seq_len(m))          for(k in seq_len(m))
496              x[i1[k], i2[k]] <- value[k]              x[i1[k], i2[k]] <- value[k]
         x  
497    
498      } else stop("nargs() = ", nA, " should never happen; please report.")          x
499        } else stop("nargs() = ", nA,
500                    ".  Extraneous illegal arguments inside '[ .. ]' ?")
501  }  }
502    
503  setReplaceMethod("[", signature(x = "Matrix", i = "matrix", j = "missing",  setReplaceMethod("[", signature(x = "Matrix", i = "matrix", j = "missing",
504                                  value = "replValue"),                                  value = "replValue"),
505            .M.repl.i.2col)            .M.repl.i.2col)
# Line 396  Line 507 
507    
508  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
509                                  value = "Matrix"),                                  value = "Matrix"),
510                     function (x, i, j, value) {
511    ### *TEMPORARY* diagnostic output:
512    ##                  cat("<Matrix1>[i,j] <- <Matrix1>:\n<Matrix1> = x :")
513    ##                  str(x)
514    ##                  cat("<Matrix2> = value :")
515    ##                  str(value)
516    ##                  cat("i :"); if(!missing(i)) str(i) else cat("<missing>\n")
517    ##                  cat("j :"); if(!missing(j)) str(j) else cat("<missing>\n")
518    
519                         callGeneric(x=x, i=i, j=j, value = as.vector(value))
520                     })
521    setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
522                                    value = "Matrix"),
523                   function (x, i, j, value)                   function (x, i, j, value)
524                   callGeneric(x=x, i=i, j=j, value = as.vector(value)))                   callGeneric(x=x, i=i, j=j, value = as.vector(value)))
525    
526  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
527                                  value = "matrix"),                                  value = "matrix"),
528                   function (x, i, j, value)                   function (x, i, j, value)
# Line 412  Line 537 
537                                 class(value),class(x)))                                 class(value),class(x)))
538                else stop("not-yet-implemented 'Matrix[<-' method")                else stop("not-yet-implemented 'Matrix[<-' method")
539            })            })
   
   
 ## The trivial methods :  
 setMethod("cbind2", signature(x = "Matrix", y = "NULL"),  
           function(x, y) x)  
 setMethod("cbind2", signature(x = "Matrix", y = "missing"),  
           function(x, y) x)  
 setMethod("cbind2", signature(x = "NULL", y="Matrix"),  
           function(x, y) x)  
   
 setMethod("rbind2", signature(x = "Matrix", y = "NULL"),  
           function(x, y) x)  
 setMethod("rbind2", signature(x = "Matrix", y = "missing"),  
           function(x, y) x)  
 setMethod("rbind2", signature(x = "NULL", y="Matrix"),  
           function(x, y) x)  
   
 ## Makes sure one gets x decent error message for the unimplemented cases:  
 setMethod("cbind2", signature(x = "Matrix", y = "Matrix"),  
           function(x, y) {  
               rowCheck(x,y)  
               stop(gettextf("cbind2() method for (%s,%s) not-yet defined",  
                             class(x), class(y)))  
           })  
   
 ## Use a working fall back {particularly useful for sparse}:  
 ## FIXME: implement rbind2 via "cholmod" for C* and Tsparse ones  
 setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),  
           function(x, y) {  
               colCheck(x,y)  
               t(cbind2(t(x), t(y)))  
           })  

Legend:
Removed from v.1673  
changed lines
  Added in v.2036

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