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 954, Wed Sep 28 19:34:31 2005 UTC revision 956, Fri Sep 30 17:28:00 2005 UTC
# Line 1  Line 1 
1  #### Toplevel ``virtual'' class "Matrix"  #### Toplevel ``virtual'' class "Matrix"
2    
3  ## probably not needed eventually:  ## ## probably not needed eventually:
4  setAs(from = "ddenseMatrix", to = "matrix",  ## setAs(from = "ddenseMatrix", to = "matrix",
5        function(from) {  ##       function(from) {
6            if(length(d <- dim(from)) != 2) stop("dim(.) has not length 2")  ##        if(length(d <- dim(from)) != 2) stop("dim(.) has not length 2")
7            array(from@x, dim = d, dimnames = dimnames(from))  ##        array(from@x, dim = d, dimnames = dimnames(from))
8        })  ##       })
   
 setMethod("show", signature(object = "ddenseMatrix"),  
           function(object) prMatrix(object))  
   
 ##- ## FIXME: The following is only for the "dMatrix" objects that are not  
 ##- ##        "dense" nor "sparse" -- i.e. "packed" ones :  
 ##- ## But these could be printed better -- "." for structural zeros.  
 ##- setMethod("show", signature(object = "dMatrix"), prMatrix)  
 ##- ## and improve this as well:  
 ##- setMethod("show", signature(object = "pMatrix"), prMatrix)  
 ##- ## this should now be superfluous [keep for safety for the moment]:  
 setMethod("show", signature(object = "Matrix"),  
           function(object) prMatrix(object))  
9    
10  ## should propagate to all subclasses:  ## should propagate to all subclasses:
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:
13    setMethod("as.array",  signature(x = "Matrix"), function(x) as(x, "matrix"))
14    
15    ## slow "fall back" method {subclasses should have faster ones}:
16    setMethod("as.vector", signature(x = "Matrix", mode = "missing"),
17              function(x) as.vector(as(x, "matrix")))
18    
19    
20  ## Note that isSymmetric is *not* exported  ## Note that isSymmetric is *not* exported
21  setMethod("isSymmetric", signature(object = "symmetricMatrix"),  setMethod("isSymmetric", signature(object = "symmetricMatrix"),
# Line 122  Line 116 
116    
117  setMethod("crossprod", signature(x = "Matrix", y = "ANY"),  setMethod("crossprod", signature(x = "Matrix", y = "ANY"),
118            function (x, y = NULL) .bail.out.2(.Generic, class(x), class(y)))            function (x, y = NULL) .bail.out.2(.Generic, class(x), class(y)))
119    setMethod("crossprod", signature(x = "ANY", y = "Matrix"),
120              function (x, y = NULL) .bail.out.2(.Generic, class(x), class(y)))
121    
122    ## There are special sparse methods; this is a "fall back":
123    setMethod("kronecker", signature(X = "Matrix", Y = "ANY",
124                                     FUN = "ANY", make.dimnames = "ANY"),
125              function(X, Y, FUN, make.dimnames, ...) {
126                  X <- as(X, "matrix") ; Matrix(callGeneric()) })
127    setMethod("kronecker", signature(X = "ANY", Y = "Matrix",
128                                     FUN = "ANY", make.dimnames = "ANY"),
129              function(X, Y, FUN, make.dimnames, ...) {
130                  Y <- as(Y, "matrix") ; Matrix(callGeneric()) })
131    
132    
133  setMethod("t", signature(x = "Matrix"),  setMethod("t", signature(x = "Matrix"),
134            function(x) .bail.out.1(.Generic, class(x)))            function(x) .bail.out.1(.Generic, class(x)))
135    
136  ## Group Methods (bail-out)  ## Group Methods
137    setMethod("+", signature(e1 = "Matrix", e2 = "missing"), function(e1) e1)
138    ## "fallback":
139    setMethod("-", signature(e1 = "Matrix", e2 = "missing"),
140              function(e1) {
141                  warning("inefficient method used for \"- e1\"")
142                  0-e1
143              })
144    
145    ## bail-outs:
146  setMethod("Compare", signature(e1 = "Matrix", e2 = "Matrix"),  setMethod("Compare", signature(e1 = "Matrix", e2 = "Matrix"),
147            function(e1, e2) {            function(e1, e2) {
148                d <- dimCheck(e1,e2)                d <- dimCheck(e1,e2)
# Line 221  Line 237 
237                                  class(x), class(y)))                                  class(x), class(y)))
238                })                })
239    
240        ## Use a working fall back {particularly useful for sparse}:
241        ## FIXME: implement rbind2 via "cholmod" for C* and Tsparse ones
242      setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),      setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),
243                function(x, y) {                function(x, y) {
244                    colCheck(x,y)                    colCheck(x,y)
245                    stop(gettextf("rbind2() method for (%s,%s) not-yet defined",                    t(cbind2(t(x), t(y)))
                                 class(x), class(y)))  
246                })                })
247    
248  }## R-2.2.x and newer  }## R-2.2.x and newer

Legend:
Removed from v.954  
changed lines
  Added in v.956

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