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 1805, Tue Mar 27 16:46:03 2007 UTC revision 1825, Thu Apr 12 13:21:51 2007 UTC
# Line 124  Line 124 
124          if(length(data) == 1 && is0(data) && !identical(sparse, FALSE)) {          if(length(data) == 1 && is0(data) && !identical(sparse, FALSE)) {
125              ## Matrix(0, ...) : always sparse unless "sparse = FALSE":              ## Matrix(0, ...) : always sparse unless "sparse = FALSE":
126              if(is.null(sparse)) sparse1 <- sparse <- TRUE              if(is.null(sparse)) sparse1 <- sparse <- TRUE
127                i.M <- sM <- TRUE
128              ## will be sparse: do NOT construct full matrix!              ## will be sparse: do NOT construct full matrix!
129              data <- new(if(is.numeric(data)) "dgTMatrix" else              data <- new(if(is.numeric(data)) "dgTMatrix" else
130                          if(is.logical(data)) "lgTMatrix" else                          if(is.logical(data)) "lgTMatrix" else
# Line 183  Line 184 
184                    }, sep="")                    }, sep="")
185          }          }
186    
187      ## Now coerce and return      ## Can we coerce and be done?
188        if(!canCoerce(data,cl)) { ## try to coerce ``via'' virtual classes
189            if(sparse && !sM)
190                data <- as(data, "sparseMatrix")
191            else if(!sparse && !is(data, "denseMatrix"))
192                data <- as(data, "denseMatrix")
193            if(isTri && !is(data, "triangularMatrix"))
194                data <- as(data, "triangularMatrix")
195            else if(isSym && !is(data, "symmetricMatrix"))
196                data <- as(data, "symmetricMatrix")
197        }
198        ## now coerce in any case .. maybe producing sensible error message:
199      as(data, cl)      as(data, cl)
200  }  }
201    
# Line 247  Line 259 
259  setMethod("kronecker", signature(X = "Matrix", Y = "ANY",  setMethod("kronecker", signature(X = "Matrix", Y = "ANY",
260                                   FUN = "ANY", make.dimnames = "ANY"),                                   FUN = "ANY", make.dimnames = "ANY"),
261            function(X, Y, FUN, make.dimnames, ...) {            function(X, Y, FUN, make.dimnames, ...) {
262                warning("potentially slow kronecker() method")                if(is(X, "sparseMatrix"))
263                      warning("using slow kronecker() method")
264                X <- as(X, "matrix") ; Matrix(callGeneric()) })                X <- as(X, "matrix") ; Matrix(callGeneric()) })
265    
266  setMethod("kronecker", signature(X = "ANY", Y = "Matrix",  setMethod("kronecker", signature(X = "ANY", Y = "Matrix",
267                                   FUN = "ANY", make.dimnames = "ANY"),                                   FUN = "ANY", make.dimnames = "ANY"),
268            function(X, Y, FUN, make.dimnames, ...) {            function(X, Y, FUN, make.dimnames, ...) {
269                warning("potentially slow kronecker() method")                if(is(Y, "sparseMatrix"))
270                      warning("using slow kronecker() method")
271                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })                Y <- as(Y, "matrix") ; Matrix(callGeneric()) })
272    
273    

Legend:
Removed from v.1805  
changed lines
  Added in v.1825

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