# SCM Repository

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

# Diff of /pkg/R/Matrix.R

revision 2158, Fri Mar 28 17:07:54 2008 UTC revision 2175, Wed Apr 23 11:23:50 2008 UTC
# Line 36  Line 36
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, mode) as.vector(as(x, "matrix"), mode))
40
41  ## mainly need these for "dMatrix" or "lMatrix" respectively, but why not general:  ## mainly need these for "dMatrix" or "lMatrix" respectively, but why not general:
42  setMethod("as.numeric", signature(x = "Matrix"),  setMethod("as.numeric", signature(x = "Matrix"),
# Line 44  Line 44
44  setMethod("as.logical", signature(x = "Matrix"),  setMethod("as.logical", signature(x = "Matrix"),
45            function(x, ...) as.logical(as.vector(x)))            function(x, ...) as.logical(as.vector(x)))
46
47    setMethod("mean", signature(x = "Matrix"),
48              function(x, trim = 0, ...) ## TODO: provide 'sparseMatrix method
49              if(is0(trim)) sum(x, ...) / length(x)
50              else mean(as.numeric(x), ...))
51
52  setMethod("cov2cor", signature(V = "Matrix"),  setMethod("cov2cor", signature(V = "Matrix"),
53            function(V) { ## was as(cov2cor(as(V, "matrix")), "dpoMatrix"))            function(V) { ## was as(cov2cor(as(V, "matrix")), "dpoMatrix"))
54                r <- V                r <- V
# Line 306  Line 311
311                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })
312
313
314    setMethod("determinant", signature(x = "Matrix", logarithm = "missing"),
315              function(x, logarithm, ...)
316              determinant(x, logarithm = TRUE, ...))
317
318    if(FALSE) { ## This is desired "in theory" - but gives
319        ## "The following object(s) are masked from package:base :   det
320    ## base::det() calls [base::]determinant();
321    ## our det() should call our determinant() :
322    det <- base::det
323    environment(det) <- environment()## == as.environment("Matrix")
324    }
325
326  ## FIXME: All of these should never be called  ## FIXME: All of these should never be called
327  setMethod("chol", signature(x = "Matrix"),  setMethod("chol", signature(x = "Matrix"),
328            function(x, pivot = FALSE, ...) .bail.out.1(.Generic, class(x)))            function(x, pivot, ...) .bail.out.1(.Generic, class(x)))
329  setMethod("determinant", signature(x = "Matrix"),  setMethod("determinant", signature(x = "Matrix", logarithm = "logical"),
330            function(x, logarithm = TRUE, ...) .bail.out.1(.Generic, class(x)))            function(x, logarithm, ...) .bail.out.1(.Generic, class(x)))
331
332  setMethod("diag", signature(x = "Matrix"),  setMethod("diag", signature(x = "Matrix"),
333            function(x, nrow, ncol) .bail.out.1(.Generic, class(x)))            function(x, nrow, ncol) .bail.out.1(.Generic, class(x)))
# Line 361  Line 378
378
379  ## Group Methods  ## Group Methods
380
##-> see ./Ops.R
##         ~~~~~
381  ## For all  non-dMatrix objects, and note that  "all" and "any" have their own  ## For all  non-dMatrix objects, and note that  "all" and "any" have their own
382  setMethod("Summary", signature(x = "Matrix", na.rm = "ANY"),  setMethod("Summary", signature(x = "Matrix", na.rm = "ANY"),
383            function(x, ..., na.rm)            function(x, ..., na.rm)
384            callGeneric(as(x,"dMatrix"), ..., na.rm = na.rm))            callGeneric(as(x,"dMatrix"), ..., na.rm = na.rm))
385
386    Summary.l <- function(x, ..., na.rm) { ## must be method directly
387        r <- callGeneric(as(x,"dMatrix"), ..., na.rm = na.rm)
388        if(!is.infinite(r) && .Generic %in% c("max", "min", "range", "sum"))
389            as.integer(r) else r
390    }
391    setMethod("Summary", signature(x = "lMatrix", na.rm = "ANY"), Summary.l)
392    setMethod("Summary", signature(x = "nMatrix", na.rm = "ANY"), Summary.l)
393    setMethod("Summary", signature(x = "pMatrix", na.rm = "ANY"), Summary.l)
394
395    ## Further, see ./Ops.R
396    ##                ~~~~~
397
398
399  ### --------------------------------------------------------------------------  ### --------------------------------------------------------------------------
400  ###  ###

Legend:
 Removed from v.2158 changed lines Added in v.2175