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 1673, Mon Nov 6 20:54:26 2006 UTC revision 1708, Fri Dec 22 19:53:37 2006 UTC
# Line 56  Line 56 
56    
57  setMethod("dim", signature(x = "Matrix"),  setMethod("dim", signature(x = "Matrix"),
58            function(x) x@Dim, valueClass = "integer")            function(x) x@Dim, valueClass = "integer")
59    
60  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)
61    
62    
63  ## not exported but used more than once for "dimnames<-" method :  ## not exported but used more than once for "dimnames<-" method :
64  ## -- or do only once for all "Matrix" classes ??  ## -- or do only once for all "Matrix" classes ??
65  dimnamesGets <- function (x, value) {  dimnamesGets <- function (x, value) {
# Line 75  Line 78 
78  setMethod("unname", signature("Matrix", force="missing"),  setMethod("unname", signature("Matrix", force="missing"),
79            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})
80    
81    setMethod("all", signature(x = "Matrix"),
82              function(x, ..., na.rm) { x <- as(x, "lMatrix"); callNextMethod()})
83    setMethod("any", signature(x = "Matrix"),
84              function(x, ..., na.rm) { x <- as(x, "lMatrix"); callNextMethod()})
85    
86    
87    
88  Matrix <-  Matrix <-
89      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
90                sparse = NULL, forceCheck = FALSE)                sparse = NULL, forceCheck = FALSE)
# Line 396  Line 406 
406    
407  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
408                                  value = "Matrix"),                                  value = "Matrix"),
409                     function (x, i, j, value) {
410    ### FIXME: *TEMPORARY* diagnostic output:
411                         cat("<Matrix1>[i,j] <- <Matrix1>:\n<Matrix1> = x :")
412                         str(x)
413                         cat("<Matrix2> = value :")
414                         str(value)
415                         cat("i :"); if(!missing(i)) str(i) else cat("<missing>\n")
416                         cat("j :"); if(!missing(j)) str(j) else cat("<missing>\n")
417    
418                         callGeneric(x=x, i=i, j=j, value = as.vector(value))
419                     })
420    setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
421                                    value = "Matrix"),
422                   function (x, i, j, value)                   function (x, i, j, value)
423                   callGeneric(x=x, i=i, j=j, value = as.vector(value)))                   callGeneric(x=x, i=i, j=j, value = as.vector(value)))
424    
425  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
426                                  value = "matrix"),                                  value = "matrix"),
427                   function (x, i, j, value)                   function (x, i, j, value)
# Line 412  Line 436 
436                                 class(value),class(x)))                                 class(value),class(x)))
437                else stop("not-yet-implemented 'Matrix[<-' method")                else stop("not-yet-implemented 'Matrix[<-' method")
438            })            })
   
   
 ## The trivial methods :  
 setMethod("cbind2", signature(x = "Matrix", y = "NULL"),  
           function(x, y) x)  
 setMethod("cbind2", signature(x = "Matrix", y = "missing"),  
           function(x, y) x)  
 setMethod("cbind2", signature(x = "NULL", y="Matrix"),  
           function(x, y) x)  
   
 setMethod("rbind2", signature(x = "Matrix", y = "NULL"),  
           function(x, y) x)  
 setMethod("rbind2", signature(x = "Matrix", y = "missing"),  
           function(x, y) x)  
 setMethod("rbind2", signature(x = "NULL", y="Matrix"),  
           function(x, y) x)  
   
 ## Makes sure one gets x decent error message for the unimplemented cases:  
 setMethod("cbind2", signature(x = "Matrix", y = "Matrix"),  
           function(x, y) {  
               rowCheck(x,y)  
               stop(gettextf("cbind2() method for (%s,%s) not-yet defined",  
                             class(x), class(y)))  
           })  
   
 ## Use a working fall back {particularly useful for sparse}:  
 ## FIXME: implement rbind2 via "cholmod" for C* and Tsparse ones  
 setMethod("rbind2", signature(x = "Matrix", y = "Matrix"),  
           function(x, y) {  
               colCheck(x,y)  
               t(cbind2(t(x), t(y)))  
           })  

Legend:
Removed from v.1673  
changed lines
  Added in v.1708

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