SCM

SCM Repository

[matrix] Diff of /pkg/R/Matrix.R
ViewVC logotype

Diff of /pkg/R/Matrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 949, Wed Sep 28 09:17:08 2005 UTC revision 954, Wed Sep 28 19:34:31 2005 UTC
# Line 57  Line 57 
57            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})            function(obj) { obj@Dimnames <- list(NULL,NULL); obj})
58    
59  Matrix <-  Matrix <-
60      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL)      function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL,
61                  sparse = NULL)
62  {  {
63      if (is(data, "Matrix")) return(data)      sparseDefault <- function(m)
64      if (is.matrix(data)) { val <- data }          prod(dim(m)) > 2*sum(as(m, "matrix") != 0)
65      else { ## cut & paste from "base::matrix" :  
66        i.M <- is(data, "Matrix")
67        if(is.null(sparse) && (i.M || is(data, "matrix")))
68            sparse <- sparseDefault(data)
69    
70        if (i.M) {
71            sM <- is(data,"sparseMatrix")
72            if((sparse && sM) || (!sparse && !sM))
73                return(data)
74            ## else : convert  dense <-> sparse -> at end
75        }
76        else if (!is.matrix(data)) { ## cut & paste from "base::matrix" :
77          if (missing(nrow))          if (missing(nrow))
78              nrow <- ceiling(length(data)/ncol)              nrow <- ceiling(length(data)/ncol)
79          else if (missing(ncol))          else if (missing(ncol))
80              ncol <- ceiling(length(data)/nrow)              ncol <- ceiling(length(data)/nrow)
81          val <- .Internal(matrix(data, nrow, ncol, byrow))          data <- .Internal(matrix(data, nrow, ncol, byrow))
82          dimnames(val) <- dimnames          if(is.null(sparse))
83                sparse <- sparseDefault(data)
84            dimnames(data) <- dimnames
85      }      }
86      as(val, "dgeMatrix")  
87        ## 'data' is now a "matrix" or "Matrix"
88        ## FIXME: consider it's type (logical,....)
89        ## ctype <- substr(class(data), 1,1) # "d", "l", ...
90        ## FIXME(2): check for symmetric / triangular / ...
91        if(sparse)
92            as(data, "dgCMatrix")
93        else
94            as(data, "dgeMatrix")
95  }  }
96    
97  ## Methods for operations where one argument is numeric  ## Methods for operations where one argument is numeric
# Line 106  Line 128 
128    
129  ## Group Methods (bail-out)  ## Group Methods (bail-out)
130  setMethod("Compare", signature(e1 = "Matrix", e2 = "Matrix"),  setMethod("Compare", signature(e1 = "Matrix", e2 = "Matrix"),
131            function(e1, e2) .bail.out.2(.Generic, class(e1), class(e2)))            function(e1, e2) {
132                  d <- dimCheck(e1,e2)
133                  .bail.out.2(.Generic, class(e1), class(e2))
134              })
135  setMethod("Compare", signature(e1 = "Matrix", e2 = "ANY"),  setMethod("Compare", signature(e1 = "Matrix", e2 = "ANY"),
136            function(e1, e2) .bail.out.2(.Generic, class(e1), class(e2)))            function(e1, e2) .bail.out.2(.Generic, class(e1), class(e2)))
137  setMethod("Compare", signature(e1 = "ANY", e2 = "Matrix"),  setMethod("Compare", signature(e1 = "ANY", e2 = "Matrix"),

Legend:
Removed from v.949  
changed lines
  Added in v.954

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