# SCM Repository

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

# Diff of /pkg/R/Matrix.R

revision 1225, Mon Mar 13 14:06:17 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 46  Line 60
60
61
62  setMethod("isTriangular", signature(object = "triangularMatrix"),  setMethod("isTriangular", signature(object = "triangularMatrix"),
63            function(object,tol) TRUE)            function(object, ...) TRUE)
64  setMethod("isTriangular", signature(object = "matrix"),
65            .is.triangular)  setMethod("isTriangular", signature(object = "matrix"), isTriMat)
66
67  setMethod("isDiagonal", signature(object = "matrix"), .is.diagonal)  setMethod("isDiagonal", signature(object = "matrix"), .is.diagonal)
68
# 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
# Line 290  Line 317
317            })            })
318
319

## NOTE: the following only works for R 2.2.x (and later) ---
## ----  *and* 'Matrix' must have been *installed* by R >= 2.2.x

if(paste(R.version\$major, R.version\$minor, sep=".") >= "2.2") {

320      ## The trivial methods :      ## The trivial methods :
321      setMethod("cbind2", signature(x = "Matrix", y = "NULL"),      setMethod("cbind2", signature(x = "Matrix", y = "NULL"),
322                function(x, y) x)                function(x, y) x)
# Line 326  Line 347
347                    colCheck(x,y)                    colCheck(x,y)
348                    t(cbind2(t(x), t(y)))                    t(cbind2(t(x), t(y)))
349                })                })

}## R-2.2.x and newer

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

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