# SCM Repository

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

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

revision 2239, Mon Jul 28 19:26:40 2008 UTC revision 2268, Mon Sep 22 15:17:12 2008 UTC
# Line 272  Line 272
272  setAs("diagonalMatrix", "generalMatrix", # prefer sparse:  setAs("diagonalMatrix", "generalMatrix", # prefer sparse:
273        function(from) as(as(from, "CsparseMatrix"), "generalMatrix"))        function(from) as(as(from, "CsparseMatrix"), "generalMatrix"))
274
275    setAs("diagonalMatrix", "denseMatrix",
276          function(from) as(as(from, "CsparseMatrix"), "denseMatrix"))
277
278  .diag.x <- function(m) if(m@diag == "U") rep.int(as1(m@x), m@Dim[1]) else m@x  .diag.x <- function(m) if(m@diag == "U") rep.int(as1(m@x), m@Dim[1]) else m@x
279
280  .diag.2N <- function(m) {  .diag.2N <- function(m) {
# Line 897  Line 900
900      setMethod("Ops", signature(e1 = other, e2 = "ldiMatrix"),      setMethod("Ops", signature(e1 = other, e2 = "ldiMatrix"),
901                function(e1,e2) callGeneric(e1, diag2tT.u(e2,e1, "l")))                function(e1,e2) callGeneric(e1, diag2tT.u(e2,e1, "l")))
902  }  }
903  ## This should *not* dispatch to <dense> methods (in ./Ops.R ), as  for(DI in diCls) {
##  FALSE & <anything> |-> FALSE : hence result should be diagonal:
for(cl in diCls) {
setMethod("&", signature(e1 = cl, e2 = "ANY"),
function(e1,e2) e1 & as(e2,"Matrix"))
setMethod("&", signature(e1 = "ANY", e2 = cl),
function(e1,e2) as(e1,"Matrix") & e2)
904      for(c2 in c("denseMatrix", "Matrix")) {      for(c2 in c("denseMatrix", "Matrix")) {
905          setMethod("&", signature(e1 = cl, e2 = c2),          for(Fun in c("*", "^", "&")) {
906                    function(e1,e2) e1 & Diagonal(x = diag(e2)))              setMethod(Fun, signature(e1 = DI, e2 = c2),
907          setMethod("&", signature(e1 = c2, e2 = cl),                        function(e1,e2) callGeneric(e1, Diagonal(x = diag(e2))))
908                    function(e1,e2) Diagonal(x = diag(e1)) & e2)              setMethod(Fun, signature(e1 = c2, e2 = DI),
909                          function(e1,e2) callGeneric(Diagonal(x = diag(e1)), e2))
910            }
911            ## NB: This arguably implicitly uses  0/0 :== 0  to keep diagonality
912            for(Fun in c("%%", "%/%", "/")) {
913                setMethod(Fun, signature(e1 = DI, e2 = c2),
914                          function(e1,e2) callGeneric(e1, Diagonal(x = diag(e2))))
915            }
916      }      }
917  }  }
918

Legend:
 Removed from v.2239 changed lines Added in v.2268