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 1290, Thu Jun 8 09:30:21 2006 UTC revision 1326, Wed Jul 19 14:58:26 2006 UTC
# Line 11  Line 11 
11  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))
12  ## for 'Matrix' objects, as.array() should be equivalent:  ## for 'Matrix' objects, as.array() should be equivalent:
13  setMethod("as.array",  signature(x = "Matrix"), function(x) as(x, "matrix"))  setMethod("as.array",  signature(x = "Matrix"), function(x) as(x, "matrix"))
14    ## head and tail apply to all Matrix objects for which subscripting is allowed
15    setMethod("head", signature(x = "Matrix"),
16              function(x, n = 6, ...)
17              x[seq(len = min(n, nrow(x))), , drop = FALSE])
18    setMethod("tail", signature(x = "Matrix"),
19              function (x, n = 6, addrownums = TRUE, ...)
20          {
21              nrx <- nrow(x)
22              sel <- seq(to = nrx, length = min(n, nrx))
23              ans <- x[sel, , drop = FALSE]
24              if (addrownums && is.null(rownames(x)))
25                  rownames(ans) <- paste("[", sel, ",]", sep = "")
26              ans
27          })
28    
29  ## slow "fall back" method {subclasses should have faster ones}:  ## slow "fall back" method {subclasses should have faster ones}:
30  setMethod("as.vector", signature(x = "Matrix", mode = "missing"),  setMethod("as.vector", signature(x = "Matrix", mode = "missing"),
# Line 97  Line 111 
111              nrow <- ceiling(length(data)/ncol)              nrow <- ceiling(length(data)/ncol)
112          else if (missing(ncol))          else if (missing(ncol))
113              ncol <- ceiling(length(data)/nrow)              ncol <- ceiling(length(data)/nrow)
114            if(length(data) == 1 && data == 0 && !identical(sparse,FALSE)) {
115                if(is.null(sparse)) sparse <- TRUE
116                ## will be sparse: do NOT construct full matrix!
117                data <- new(if(is.numeric(data)) "dgTMatrix" else
118                            if(is.logical(data)) "lgTMatrix" else
119                            stop("invalid 'data'"),
120                            Dim = as.integer(c(nrow,ncol)),
121                            Dimnames = if(is.null(dimnames))
122                            list(NULL,NULL) else dimnames)
123            } else { ## normal case
124          data <- .Internal(matrix(data, nrow, ncol, byrow))          data <- .Internal(matrix(data, nrow, ncol, byrow))
125          if(is.null(sparse))          if(is.null(sparse))
126              sparse <- sparseDefault(data)              sparse <- sparseDefault(data)
127          dimnames(data) <- dimnames          dimnames(data) <- dimnames
128            }
129      } else if (!is.null(dimnames))      } else if (!is.null(dimnames))
130          dimnames(data) <- dimnames          dimnames(data) <- dimnames
131    
# Line 192  Line 217 
217                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })
218    
219    
220    setMethod("diag", signature(x = "Matrix"),
221              function(x, nrow, ncol) .bail.out.1(.Generic, class(x)))
222  setMethod("t", signature(x = "Matrix"),  setMethod("t", signature(x = "Matrix"),
223            function(x) .bail.out.1(.Generic, class(x)))            function(x) .bail.out.1(.Generic, class(x)))
224    

Legend:
Removed from v.1290  
changed lines
  Added in v.1326

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