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 1174, Mon Jan 16 20:03:48 2006 UTC revision 1290, Thu Jun 8 09:30:21 2006 UTC
# Line 24  Line 24 
24  setMethod("isSymmetric", signature(object = "triangularMatrix"),  setMethod("isSymmetric", signature(object = "triangularMatrix"),
25            ## TRUE iff diagonal:            ## TRUE iff diagonal:
26            function(object,tol) isDiagonal(object))            function(object,tol) isDiagonal(object))
27    
28  if(paste(R.version$major, R.version$minor, sep=".") < "2.3")  if(paste(R.version$major, R.version$minor, sep=".") < "2.3")
29      ## need a "matrix" method as in R 2.3 and later      ## need a "matrix" method as in R 2.3 and later
30      setMethod("isSymmetric", signature(object = "matrix"),      setMethod("isSymmetric", signature(object = "matrix"),
# Line 32  Line 33 
33                ## pretest: is it square?                ## pretest: is it square?
34                d <- dim(object)                d <- dim(object)
35                if(d[1] != d[2]) return(FALSE)                if(d[1] != d[2]) return(FALSE)
36                  ## for `broken' all.equal in R <= 2.2.x:
37                  dn <- dimnames(object)
38                  if(!identical(dn[1], dn[2])) return(FALSE)
39                test <-                test <-
40                    if(is.complex(object))                    if(is.complex(object))
41                        all.equal.numeric(object, Conj(t(object)), tol = tol, ...)                        all.equal.numeric(object, Conj(t(object)), tol = tol, ...)
# Line 42  Line 46 
46    
47    
48  setMethod("isTriangular", signature(object = "triangularMatrix"),  setMethod("isTriangular", signature(object = "triangularMatrix"),
49            function(object,tol) TRUE)            function(object, ...) TRUE)
50  setMethod("isTriangular", signature(object = "matrix"),  
51            .is.triangular)  setMethod("isTriangular", signature(object = "matrix"), isTriMat)
52    
53  setMethod("isDiagonal", signature(object = "matrix"), .is.diagonal)  setMethod("isDiagonal", signature(object = "matrix"), .is.diagonal)
54    
# Line 97  Line 101 
101          if(is.null(sparse))          if(is.null(sparse))
102              sparse <- sparseDefault(data)              sparse <- sparseDefault(data)
103          dimnames(data) <- dimnames          dimnames(data) <- dimnames
104      }      } else if (!is.null(dimnames))
105            dimnames(data) <- dimnames
106    
107      ## 'data' is now a "matrix" or "Matrix"      ## 'data' is now a "matrix" or "Matrix"
108    
# Line 224  Line 229 
229  setMethod("[", signature(x = "Matrix",  setMethod("[", signature(x = "Matrix",
230                           i = "missing", j = "missing", drop = "ANY"),                           i = "missing", j = "missing", drop = "ANY"),
231            function (x, i, j, drop) x)            function (x, i, j, drop) x)
232    
233  ## missing 'drop' --> 'drop = TRUE'  ## missing 'drop' --> 'drop = TRUE'
234  ##                     -----------  ##                     -----------
235  ## select rows  ## select rows
# Line 243  Line 249 
249            function(x,i,j, drop)            function(x,i,j, drop)
250            stop("invalid or not-yet-implemented 'Matrix' subsetting"))            stop("invalid or not-yet-implemented 'Matrix' subsetting"))
251    
252    ##  "logical *vector* indexing, such as  M [ M >= 10 ] :
253    setMethod("[", signature(x = "Matrix", i = "lMatrix", j = "missing",
254                             drop = "ANY"),
255              function (x, i, j, drop) {
256                  as(x, geClass(x))@x[as.vector(i)]
257                                            # -> error when lengths don't match
258              })
259    
260    setMethod("[", signature(x = "Matrix", i = "logical", j = "missing",
261                             drop = "ANY"),
262              function (x, i, j, drop) as(x, geClass(x))@x[i])
263    
264    
265  ## "FIXME:"  ## "FIXME:"
266  ## How can we get at   A[ ij ]  where ij is (i,j) 2-column matrix?  ## How can we get at   A[ ij ]  where ij is (i,j) 2-column matrix?
267  ##  and                A[ LL ]  where LL is a logical *vector*  ##  and                A[ LL ]  where LL is a logical *vector*
# Line 253  Line 272 
272    
273  ## x[] <- value :  ## x[] <- value :
274  setReplaceMethod("[", signature(x = "Matrix", i = "missing", j = "missing",  setReplaceMethod("[", signature(x = "Matrix", i = "missing", j = "missing",
275                                  value = "index"),##  double/logical/...                                  value = "ANY"),## double/logical/...
276            function (x, value) { x@x <- value ; validObject(x); x })            function (x, value) {
277                  x@x <- value
278                  validObject(x)# check if type and lengths above match
279                  x
280              })
281    
282  ## Otherwise (value is not "index"): bail out  ## Method for all 'Matrix' kinds (rather than incomprehensible error messages);
283    ## (ANY,ANY,ANY) is used when no `real method' is implemented :
284  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",  setReplaceMethod("[", signature(x = "Matrix", i = "ANY", j = "ANY",
285                                  value = "ANY"),                                  value = "ANY"),
286            function (x, i, j, value)            function (x, i, j, value) {
287                   if(!is(value,"index"))                if(!is.atomic(value))
288                   stop("RHS 'value' must be of class \"index\"")                    stop("RHS 'value' must match matrix class ", class(x))
289                   else stop("not-yet-implemented 'Matrix[<-' method"))                else stop("not-yet-implemented 'Matrix[<-' method")
290              })
   
   
 ## NOTE: the following only works for R 2.2.x (and later) ---  
 ## ----  *and* 'Matrix' must have been *installed* by R >= 2.2.x  
291    
 if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {  
292    
293      ## The trivial methods :      ## The trivial methods :
294      setMethod("cbind2", signature(x = "Matrix", y = "NULL"),      setMethod("cbind2", signature(x = "Matrix", y = "NULL"),
# Line 301  Line 320 
320                    colCheck(x,y)                    colCheck(x,y)
321                    t(cbind2(t(x), t(y)))                    t(cbind2(t(x), t(y)))
322                })                })
   
 }## R-2.2.x and newer  

Legend:
Removed from v.1174  
changed lines
  Added in v.1290

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