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 2863, Mon Dec 31 20:21:11 2012 UTC revision 2877, Wed May 8 20:59:04 2013 UTC
# Line 316  Line 316 
316  setAs("diagonalMatrix", "denseMatrix",  setAs("diagonalMatrix", "denseMatrix",
317        function(from) as(as(from, "CsparseMatrix"), "denseMatrix"))        function(from) as(as(from, "CsparseMatrix"), "denseMatrix"))
318    
319    ..diag.x <- function(m)                   rep.int(as1(m@x), m@Dim[1])
320  .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
321    
322  .diag.2N <- function(m) {  .diag.2N <- function(m) {
# Line 435  Line 436 
436                           replDiag(x, i=i, , value=value)                           replDiag(x, i=i, , value=value)
437                   })                   })
438    
439    setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing",
440                                    j = "index", value = "replValue"),
441                     function(x,i,j, ..., value) replDiag(x, j=j, value=value))
442    
443    ## x[] <- value :
444    setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing",
445                                    j = "missing", value = "ANY"),
446                     function(x,i,j, ..., value)
447                 {
448                  if(all0(value)) { # be faster
449                      r <- new(paste0(.M.kindC(getClassDef(class(x))),"tTMatrix"))# of all "0"
450                      r@Dim <- x@Dim
451                      r@Dimnames <- x@Dimnames
452                      r
453                  } else { ## typically non-sense: assigning to full sparseMatrix
454                      x[TRUE] <- value
455                      x
456                  }
457              })
458    
459    
460  setReplaceMethod("[", signature(x = "diagonalMatrix",  setReplaceMethod("[", signature(x = "diagonalMatrix",
461                                  i = "matrix", # 2-col.matrix                                  i = "matrix", # 2-col.matrix
462                                  j = "missing", value = "replValue"),                                  j = "missing", value = "replValue"),
# Line 463  Line 485 
485                       }                       }
486                   })                   })
487    
 setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing",  
                                 j = "index", value = "replValue"),  
                  function(x,i,j, ..., value) replDiag(x, j=j, value=value))  
488    
489    ## value = "sparseMatrix":
490  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing", j = "index",  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing", j = "index",
491                                  value = "sparseMatrix"),                                  value = "sparseMatrix"),
492                   function (x, i, j, ..., value)                   function (x, i, j, ..., value)
# Line 480  Line 500 
500                   function (x, i, j, ..., value)                   function (x, i, j, ..., value)
501                   callGeneric(x=x, i=i, j=j, value = as(value, "sparseVector")))                   callGeneric(x=x, i=i, j=j, value = as(value, "sparseVector")))
502    
503    ## value = "sparseVector":
504  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing", j = "index",  setReplaceMethod("[", signature(x = "diagonalMatrix", i = "missing", j = "index",
505                                  value = "sparseVector"),                                  value = "sparseVector"),
506                   replDiag)                   replDiag)

Legend:
Removed from v.2863  
changed lines
  Added in v.2877

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