# SCM Repository

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

# Diff of /pkg/R/diagMatrix.R

revision 2052, Wed Aug 15 13:33:19 2007 UTC revision 2096, Fri Dec 7 17:44:44 2007 UTC
# Line 214  Line 214
214  ## FIXME: this now fails because the "denseMatrix" methods come first in dispatch  ## FIXME: this now fails because the "denseMatrix" methods come first in dispatch
215  replDiag <- function(x, i, j, value) {  replDiag <- function(x, i, j, value) {
216      x <- as(x, "sparseMatrix")      x <- as(x, "sparseMatrix")
217        message(sprintf("diagnosing replDiag() -- nargs() = %d\n", nargs()))
218      if(missing(i))      if(missing(i))
219          x[, j] <- value          x[, j] <- value
220      else if(missing(j))      else if(missing(j))
# Line 228  Line 229
229  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "index",  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "index",
230                                  j = "missing", value = "replValue"),                                  j = "missing", value = "replValue"),
231                   function(x, i, value) replDiag(x, i=i, value=value))                   function(x, i, value) replDiag(x, i=i, value=value))
232    setReplaceMethod("[", signature(x = "diagonalMatrix", i = "matrix", # 2-col.matrix
233                                    j = "missing", value = "replValue"),
234                     function(x, i, value) {
235                         if(ncol(i) == 2) {
236                             if(all((ii <- i[,1]) == i[,2])) { # replace in diagonal only
237                                 x@x[ii] <- value
238                                 x
239                             } else { ## no longer diagonal, but remain sparse:
240                                 x <- as(x, "sparseMatrix")
241                                 x[i] <- value
242                                 x
243                             }
244                         }
245                         else { # behave as "base R": use as if vector
246                             x <- as(x, "matrix")
247                             x[i] <- value
248                             Matrix(x)
249                         }
250                     })
251
252  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing",  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing",
253                                  j = "index", value = "replValue"),                                  j = "index", value = "replValue"),
254                   function(x, j, value) replDiag(x, j=j, value=value))                   function(x, j, value) replDiag(x, j=j, value=value))

Legend:
 Removed from v.2052 changed lines Added in v.2096