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 1466, Wed Aug 30 03:35:53 2006 UTC revision 1467, Wed Aug 30 21:35:09 2006 UTC
# Line 38  Line 38 
38            function(x, ...) as.logical(as.vector(x)))            function(x, ...) as.logical(as.vector(x)))
39    
40    
41  ## Note that isSymmetric is *not* exported  ## "base" has an isSymmetric() S3-generic since R 2.3.0
 ## but that "base" has an isSymmetric() S3-generic since R 2.3.0  
42  setMethod("isSymmetric", signature(object = "symmetricMatrix"),  setMethod("isSymmetric", signature(object = "symmetricMatrix"),
43            function(object,tol) TRUE)            function(object,tol) TRUE)
44  setMethod("isSymmetric", signature(object = "triangularMatrix"),  setMethod("isSymmetric", signature(object = "triangularMatrix"),
45            ## TRUE iff diagonal:            ## TRUE iff diagonal:
46            function(object,tol) isDiagonal(object))            function(object,tol) isDiagonal(object))
47    
 if(paste(R.version$major, R.version$minor, sep=".") < "2.3")  
     ## need a "matrix" method as in R 2.3 and later  
     setMethod("isSymmetric", signature(object = "matrix"),  
               function(object, tol = 100*.Machine$double.eps, ...)  
           {  
               ## pretest: is it square?  
               d <- dim(object)  
               if(d[1] != d[2]) return(FALSE)  
               ## for `broken' all.equal in R <= 2.2.x:  
               dn <- dimnames(object)  
               if(!identical(dn[1], dn[2])) return(FALSE)  
               test <-  
                   if(is.complex(object))  
                       all.equal.numeric(object, Conj(t(object)), tol = tol, ...)  
                   else              # numeric, character, ..  
                       all.equal(object, t(object), tol = tol, ...)  
               isTRUE(test)  
           })  
   
   
48  setMethod("isTriangular", signature(object = "triangularMatrix"),  setMethod("isTriangular", signature(object = "triangularMatrix"),
49            function(object, ...) TRUE)            function(object, ...) TRUE)
50    
# Line 101  Line 80 
80                sparse = NULL, forceCheck = FALSE)                sparse = NULL, forceCheck = FALSE)
81  {  {
82      sparseDefault <- function(m)      sparseDefault <- function(m)
83          prod(dim(m)) > 2*sum(as(m, "matrix") != 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")))      if(is.null(sparse) && (i.M || is(data, "matrix")))
# Line 119  Line 98 
98              nrow <- ceiling(length(data)/ncol)              nrow <- ceiling(length(data)/ncol)
99          else if (missing(ncol))          else if (missing(ncol))
100              ncol <- ceiling(length(data)/nrow)              ncol <- ceiling(length(data)/nrow)
101          if(length(data) == 1 && data == 0 && !identical(sparse,FALSE)) {          if(length(data) == 1 && !is.na(data) && data == 0 &&
102               !identical(sparse, FALSE)) {
103    
104              if(is.null(sparse)) 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

Legend:
Removed from v.1466  
changed lines
  Added in v.1467

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