SCM

SCM Repository

[matrix] Diff of /pkg/Matrix/R/diagMatrix.R
ViewVC logotype

Diff of /pkg/Matrix/R/diagMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1707, Thu Dec 21 08:03:05 2006 UTC revision 1708, Fri Dec 22 19:53:37 2006 UTC
# Line 173  Line 173 
173                x = if(uni) x[FALSE] else x)                x = if(uni) x[FALSE] else x)
174        })        })
175    
176    
177    setMethod("diag", signature(x = "diagonalMatrix"),
178              function(x = 1, nrow, ncol = n) .diag.x(x))
179    
180  ## When you assign to a diagonalMatrix, the result should be  ## When you assign to a diagonalMatrix, the result should be
181  ## diagonal or sparse  ## diagonal or sparse ---
182    ## FIXME: this now fails because the "denseMatrix" methods come first in dispatch
183  setReplaceMethod("[", signature(x = "diagonalMatrix",  setReplaceMethod("[", signature(x = "diagonalMatrix",
184                                  i = "ANY", j = "ANY", value = "ANY"),                                  i = "ANY", j = "ANY", value = "ANY"),
185                   function(x, i, j, value) {                   function(x, i, j, value) {
# Line 203  Line 208 
208  ## chol(L) is L for logical diagonal:  ## chol(L) is L for logical diagonal:
209  setMethod("chol", signature(x = "ldiMatrix"), function(x, pivot) x)  setMethod("chol", signature(x = "ldiMatrix"), function(x, pivot) x)
210    
   
 setMethod("diag", signature(x = "diagonalMatrix"),  
           function(x = 1, nrow, ncol = n) {  
              if(x@diag == "U")  
                  rep.int(if(is.logical(x@x)) TRUE else 1, x@Dim[1])  
              else x@x  
           })  
   
211  setMethod("!", "ldiMatrix", function(e1) {  setMethod("!", "ldiMatrix", function(e1) {
212      if(e1@diag == "N")      if(e1@diag == "N")
213          e1@x <- !e1@x          e1@x <- !e1@x
# Line 387  Line 384 
384            function(x, y = NULL) { y <- as(y, "sparseMatrix"); callGeneric() })            function(x, y = NULL) { y <- as(y, "sparseMatrix"); callGeneric() })
385    
386    
 ## cbind/rbind:  preserve sparseness {not always optimal}  
   
 ## hack to suppress the obnoxious dispatch ambiguity warnings:  
 diag2Sp <- function(x) suppressWarnings(as(x, "CsparseMatrix"))  
   
 ## in order to evade method dispatch ambiguity, but still remain "general"  
 ## we use this hack instead of signature  x = "diagonalMatrix"  
 for(cls in names(getClass("diagonalMatrix")@subclasses)) {  
  setMethod("cbind2", signature(x = cls, y = "matrix"),  
            function(x,y) cbind2(diag2Sp(x), as_Csparse(y)))  
  setMethod("cbind2", signature(x = "matrix", y = cls),  
            function(x,y) cbind2(as_Csparse(x), diag2Sp(y)))  
  setMethod("rbind2", signature(x = cls, y = "matrix"),  
            function(x,y) rbind2(diag2Sp(x), as_Csparse(y)))  
  setMethod("rbind2", signature(x = "matrix", y = cls),  
            function(x,y) rbind2(as_Csparse(x), diag2Sp(y)))  
 }  
   
   
387  ## similar to prTriang() in ./Auxiliaries.R :  ## similar to prTriang() in ./Auxiliaries.R :
388  prDiag <-  prDiag <-
389      function(x, digits = getOption("digits"), justify = "none", right = TRUE)      function(x, digits = getOption("digits"), justify = "none", right = TRUE)

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