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 924, Mon Sep 19 08:40:29 2005 UTC revision 925, Mon Sep 19 19:01:31 2005 UTC
# Line 7  Line 7 
7            array(from@x, dim = d, dimnames = dimnames(from))            array(from@x, dim = d, dimnames = dimnames(from))
8        })        })
9    
10  ## private function to be used as show() method possibly more than once  setMethod("show", signature(object = "ddenseMatrix"),
11  prMatrix <- function(object) {            function(object) prMatrix(object))
     d <- dim(object)  
     cl <- class(object)  
     cat(sprintf('%d x %d Matrix of class "%s"\n', d[1], d[2], cl))  
     m <- as(object, "matrix")  
     maxp <- getOption("max.print")  
     if(prod(d) <= maxp) print(m)  
     else { ## d[1] > maxp / d[2] >= nr :  
         nr <- maxp %/% d[2]  
         n2 <- ceiling(nr / 2)  
         print(head(m, max(1, n2)))  
         cat("\n ..........\n\n")  
         print(tail(m, max(1, nr - n2)))  
     }  
     ## DEBUG: cat("str(.):\n") ; str(object)  
     invisible(object)# as print() S3 methods do  
 }  
   
 setMethod("show", signature(object = "ddenseMatrix"), prMatrix)  
12    
13  ##- ## FIXME: The following is only for the "dMatrix" objects that are not  ##- ## FIXME: The following is only for the "dMatrix" objects that are not
14  ##- ##        "dense" nor "sparse" -- i.e. "packed" ones :  ##- ##        "dense" nor "sparse" -- i.e. "packed" ones :
# Line 35  Line 17 
17  ##- ## and improve this as well:  ##- ## and improve this as well:
18  ##- setMethod("show", signature(object = "pMatrix"), prMatrix)  ##- setMethod("show", signature(object = "pMatrix"), prMatrix)
19  ##- ## this should now be superfluous [keep for safety for the moment]:  ##- ## this should now be superfluous [keep for safety for the moment]:
20  setMethod("show", signature(object = "Matrix"), prMatrix)  setMethod("show", signature(object = "Matrix"),
21              function(object) prMatrix(object))
22    
23  ## should propagate to all subclasses:  ## should propagate to all subclasses:
24  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))
# Line 46  Line 29 
29  setMethod("isSymmetric", signature(object = "triangularMatrix"),  setMethod("isSymmetric", signature(object = "triangularMatrix"),
30            ## FIXME: 'TRUE' if *diagonal*, i.e. return(isDiagonal(object))            ## FIXME: 'TRUE' if *diagonal*, i.e. return(isDiagonal(object))
31            function(object) FALSE)            function(object) FALSE)
32    setMethod("isDiagonal", signature(object = "sparseMatrix"),
33              function(object) {
34                  gT <- as(object, "TsparseMatrix")
35                  all(gT@i == gT@j)
36              })
37    
38  setMethod("dim", signature(x = "Matrix"),  setMethod("dim", signature(x = "Matrix"),
39            function(x) x@Dim, valueClass = "integer")            function(x) x@Dim, valueClass = "integer")
# Line 104  Line 92 
92  setMethod("solve", signature(a = "Matrix", b = "numeric"),  setMethod("solve", signature(a = "Matrix", b = "numeric"),
93            function(a, b, ...) callGeneric(a, as.matrix(b)))            function(a, b, ...) callGeneric(a, as.matrix(b)))
94    
95    ## bail-out methods in order to get better error messages
96    setMethod("%*%", signature(x = "Matrix", y = "Matrix"),
97              function (x, y)
98              stop(gettextf('not-yet-implemented method for <%s> %%*%% <%s>',
99                            class(x), class(y))))
100    setMethod("crossprod", signature(x = "Matrix", y = "ANY"),
101              function (x, y = NULL)
102              stop(gettextf('not-yet-implemented method for crossprod(<%s>, <%s>)',
103                            class(x), class(y))))
104    
105    
106  ### --------------------------------------------------------------------------  ### --------------------------------------------------------------------------
107  ###  ###
108  ### Subsetting "["  and  ### Subsetting "["  and
# Line 154  Line 153 
153            function (x, i, j, value)            function (x, i, j, value)
154                   if(!is(value,"index"))                   if(!is(value,"index"))
155                   stop("RHS 'value' must be of class \"index\"")                   stop("RHS 'value' must be of class \"index\"")
156                   else stop("unimplemented 'Matrix[<-' method"))                   else stop("not-yet-implemented 'Matrix[<-' method"))
157    
158    
159    
# Line 171  Line 170 
170      setMethod("cbind2", signature(x = "NULL", y="Matrix"),      setMethod("cbind2", signature(x = "NULL", y="Matrix"),
171                function(x, y) x)                function(x, y) x)
172    
173        setMethod("rbind2", signature(x = "Matrix", y = "NULL"),
174                  function(x, y) x)
175        setMethod("rbind2", signature(x = "Matrix", y = "missing"),
176                  function(x, y) x)
177        setMethod("rbind2", signature(x = "NULL", y="Matrix"),
178                  function(x, y) x)
179    
180      ## Makes sure one gets x decent error message for the unimplemented cases:      ## Makes sure one gets x decent error message for the unimplemented cases:
181      setMethod("cbind2", signature(x = "Matrix", y = "Matrix"),      setMethod("cbind2", signature(x = "Matrix", y = "Matrix"),
182                function(x, y) {                function(x, y) {
# Line 179  Line 185 
185                                  class(x), class(y)))                                  class(x), class(y)))
186                })                })
187    
     if (isGeneric("rbind2"))  
188      setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),      setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),
189                function(x, y) {                function(x, y) {
190                    colCheck(x,y)                    colCheck(x,y)

Legend:
Removed from v.924  
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