# SCM Repository

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

# Diff of /pkg/R/diagMatrix.R

revision 1655, Mon Oct 30 17:16:27 2006 UTC revision 1707, Thu Dec 21 08:03:05 2006 UTC
# Line 360  Line 360
360
361
362  ## FIXME?: In theory, this can be done *FASTER*, in some cases, via tapply1()  ## FIXME?: In theory, this can be done *FASTER*, in some cases, via tapply1()

363  setMethod("%*%", signature(x = "diagonalMatrix", y = "sparseMatrix"),  setMethod("%*%", signature(x = "diagonalMatrix", y = "sparseMatrix"),
364            function(x, y) as(x, "sparseMatrix") %*% y)            function(x, y) as(x, "sparseMatrix") %*% y)
365    ## NB: The previous is *not* triggering for  "ddi" o "dgC" (= distance 3)
366    ##     since there's a "ddense" o "Csparse" at dist. 2 => triggers first.
367    ## ==> do this:
368    setMethod("%*%", signature(x = "diagonalMatrix", y = "CsparseMatrix"),
369              function(x, y) as(x, "CsparseMatrix") %*% y)
370    ## NB: this is *not* needed for Tsparse & Rsparse
371    ## TODO: Write tests in ./tests/ which ensure that many "ops" with diagonal*
372    ##       do indeed work by going throug sparse (and *not* ddense)!
373
374  setMethod("%*%", signature(x = "sparseMatrix", y = "diagonalMatrix"),  setMethod("%*%", signature(x = "sparseMatrix", y = "diagonalMatrix"),
375            function(x, y) x %*% as(y, "sparseMatrix"))            function(x, y) x %*% as(y, "sparseMatrix"))
# Line 380  Line 387
387            function(x, y = NULL) { y <- as(y, "sparseMatrix"); callGeneric() })            function(x, y = NULL) { y <- as(y, "sparseMatrix"); callGeneric() })
388
389
390    ## cbind/rbind:  preserve sparseness {not always optimal}
391
392    ## hack to suppress the obnoxious dispatch ambiguity warnings:
393    diag2Sp <- function(x) suppressWarnings(as(x, "CsparseMatrix"))
394
395    ## in order to evade method dispatch ambiguity, but still remain "general"
396    ## we use this hack instead of signature  x = "diagonalMatrix"
397    for(cls in names(getClass("diagonalMatrix")@subclasses)) {
398     setMethod("cbind2", signature(x = cls, y = "matrix"),
399               function(x,y) cbind2(diag2Sp(x), as_Csparse(y)))
400     setMethod("cbind2", signature(x = "matrix", y = cls),
401               function(x,y) cbind2(as_Csparse(x), diag2Sp(y)))
402     setMethod("rbind2", signature(x = cls, y = "matrix"),
403               function(x,y) rbind2(diag2Sp(x), as_Csparse(y)))
404     setMethod("rbind2", signature(x = "matrix", y = cls),
405               function(x,y) rbind2(as_Csparse(x), diag2Sp(y)))
406    }
407
408
409  ## similar to prTriang() in ./Auxiliaries.R :  ## similar to prTriang() in ./Auxiliaries.R :

Legend:
 Removed from v.1655 changed lines Added in v.1707