# SCM Repository

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

# Diff of /pkg/R/sparseMatrix.R

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)
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, ...) {