# SCM Repository

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

# Diff of /pkg/R/diagMatrix.R

revision 1725, Wed Jan 17 08:01:10 2007 UTC revision 1748, Mon Jan 29 20:48:26 2007 UTC
# Line 384  Line 384
384  setMethod("%*%", signature(x = "sparseMatrix", y = "diagonalMatrix"),  setMethod("%*%", signature(x = "sparseMatrix", y = "diagonalMatrix"),
385            function(x, y) x %*% as(y, "sparseMatrix"))            function(x, y) x %*% as(y, "sparseMatrix"))
386
387    setMethod("solve", signature(a = "diagonalMatrix", b = "missing"),
388              function(a, b, ...) {
389                  a@x <- 1/ a@x
390                  a@Dimnames <- a@Dimnames[2:1]
391                  a
392              })
393
394    solveDiag <- function(a, b, ...) {
395        if((n <- a@Dim[1]) != nrow(b))
396            stop("incompatible matrix dimensions")
397        ## trivially invert a 'in place' and multiply:
398        a@x <- 1/ a@x
399        a@Dimnames <- a@Dimnames[2:1]
400        a %*% b
401    }
402    setMethod("solve", signature(a = "diagonalMatrix", b = "matrix"),
403              solveDiag)
404    setMethod("solve", signature(a = "diagonalMatrix", b = "Matrix"),
405              solveDiag)
406
407
408  setMethod("crossprod", signature(x = "diagonalMatrix", y = "sparseMatrix"),  setMethod("crossprod", signature(x = "diagonalMatrix", y = "sparseMatrix"),
409            function(x, y = NULL) { x <- as(x, "sparseMatrix"); callGeneric() })            function(x, y = NULL) { x <- as(x, "sparseMatrix"); callGeneric() })
410

Legend:
 Removed from v.1725 changed lines Added in v.1748