# SCM Repository

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

# Diff of /pkg/R/Matrix.R

revision 1617, Fri Oct 6 15:42:12 2006 UTC revision 1618, Fri Oct 6 15:44:01 2006 UTC
# Line 6  Line 6
6  setAs("Matrix", "sparseMatrix", function(from) as_Csparse(from))  setAs("Matrix", "sparseMatrix", function(from) as_Csparse(from))
7  setAs("Matrix", "denseMatrix",  function(from) as_dense(from))  setAs("Matrix", "denseMatrix",  function(from) as_dense(from))
8
9    ## Most of these work; this is a last resort:
10  setAs(from = "Matrix", to = "matrix", # do *not* call base::as.matrix() here:  setAs(from = "Matrix", to = "matrix", # do *not* call base::as.matrix() here:
11        function(from) .bail.out.2("coerce", class(from), class(to)))        function(from) .bail.out.2("coerce", class(from), class(to)))
12    setAs(from = "matrix", to = "Matrix", function(from) Matrix(from))
13
14  ## ## probably not needed eventually:  ## ## probably not needed eventually:
15  ## setAs(from = "ddenseMatrix", to = "matrix",  ## setAs(from = "ddenseMatrix", to = "matrix",
# Line 81  Line 83
83          prod(dim(m)) > 2*sum(is.na(m <- as(m, "matrix")) | m != 0)          prod(dim(m)) > 2*sum(is.na(m <- as(m, "matrix")) | m != 0)
84
85      i.M <- is(data, "Matrix")      i.M <- is(data, "Matrix")
86      if(is.null(sparse) && (i.M || is(data, "matrix")))
87        if(is.null(sparse1 <- sparse) && (i.M || is(data, "matrix")))
88          sparse <- sparseDefault(data)          sparse <- sparseDefault(data)
89
90      doDN <- TRUE      doDN <- TRUE
# Line 96  Line 99
99              nrow <- ceiling(length(data)/ncol)              nrow <- ceiling(length(data)/ncol)
100          else if (missing(ncol))          else if (missing(ncol))
101              ncol <- ceiling(length(data)/nrow)              ncol <- ceiling(length(data)/nrow)
102          if(length(data) == 1 && !is.na(data) && data == 0 &&          if(length(data) == 1 && is0(data) && !identical(sparse, FALSE)) {
103             !identical(sparse, FALSE)) {              ## Matrix(0, ...) : always sparse unless "sparse = FALSE":
104                if(is.null(sparse)) sparse1 <- sparse <- TRUE
if(is.null(sparse)) sparse <- TRUE
105              ## will be sparse: do NOT construct full matrix!              ## will be sparse: do NOT construct full matrix!
106              data <- new(if(is.numeric(data)) "dgTMatrix" else              data <- new(if(is.numeric(data)) "dgTMatrix" else
107                          if(is.logical(data)) "lgTMatrix" else                          if(is.logical(data)) "lgTMatrix" else
# Line 127  Line 129
129      if(isDiag)      if(isDiag)
130          isDiag <- isDiagonal(data)          isDiag <- isDiagonal(data)
131
### TODO: Compare with as.Matrix() and its tests in ./dgeMatrix.R

132      ## Find proper matrix class 'cl'      ## Find proper matrix class 'cl'
133      cl <-      cl <-
134          if(isDiag)          if(isDiag && !isTRUE(sparse1))
135              "diagonalMatrix" # -> will automatically check for type              "diagonalMatrix" # -> will automatically check for type
136          else {          else {
137              ## consider it's type              ## consider it's type

Legend:
 Removed from v.1617 changed lines Added in v.1618