SCM

SCM Repository

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

Diff of /pkg/R/sparseMatrix.R

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

revision 1851, Mon May 21 16:06:04 2007 UTC revision 1852, Mon May 21 16:42:35 2007 UTC
# Line 13  Line 13 
13    
14  setAs("sparseMatrix", "triangularMatrix", as_tSparse)  setAs("sparseMatrix", "triangularMatrix", as_tSparse)
15    
16    spMatrix <- function(nrow, ncol, i,j,x) {
17        ## Author: Martin Maechler, Date:  8 Jan 2007, 18:46
18        dim <- c(as.integer(nrow), as.integer(ncol))
19        ## The conformability of (i,j,x) with itself and with 'dim'
20        ## is checked automatically by internal "validObject()" inside new(.):
21        kind <- .M.kind(x)
22        new(paste(kind, "gTMatrix", sep=''), Dim = dim,
23            x = if(kind == "d") as.double(x) else x,
24            ## our "Tsparse" Matrices use  0-based indices :
25            i = as.integer(i - 1L),
26            j = as.integer(j - 1L))
27    }
28    
29    
30  ## "graph" coercions -- this needs the graph package which is currently  ## "graph" coercions -- this needs the graph package which is currently
31  ##  -----               *not* required on purpose  ##  -----               *not* required on purpose
32  ## Note: 'undirected' graph <==> 'symmetric' matrix  ## Note: 'undirected' graph <==> 'symmetric' matrix
# Line 332  Line 346 
346     })     })
347    
348    
349    ## For very large and very sparse matrices,  the above show()
350    ## is not really helpful;  Use  summary() as an alternative:
351    
352    setMethod("summary", signature(object = "sparseMatrix"),
353              function(object, ...) {
354                  d <- dim(object)
355                  T <- as(object, "TsparseMatrix")
356                  ## return a data frame (int, int,  {double|logical|...})  :
357                  r <- data.frame(i = T@i + 1L, j = T@j + 1L, x = T@x)
358                  attr(r, "header") <-
359                      sprintf('%d x %d sparse Matrix of class "%s", with entries',
360                              d[1], d[2], class(object))
361                  ## use ole' S3 technology for such a simple case
362                  class(r) <- c("sparseSummary", class(r))
363                  r
364              })
365    
366    print.sparseSummary <- function (x, ...) {
367        cat(attr(x, "header"),"\n")
368        print.data.frame(x, ...)
369        invisible(x)
370    }
371    
372  setMethod("isSymmetric", signature(object = "sparseMatrix"),  setMethod("isSymmetric", signature(object = "sparseMatrix"),
373            function(object, tol = 100*.Machine$double.eps) {            function(object, tol = 100*.Machine$double.eps) {
374                ## pretest: is it square?                ## pretest: is it square?

Legend:
Removed from v.1851  
changed lines
  Added in v.1852

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