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 1844, Wed May 16 20:40:34 2007 UTC revision 1845, Wed May 16 21:24:41 2007 UTC
# Line 7  Line 7 
7    
8  setAs("ANY", "sparseMatrix", function(from) as(from, "CsparseMatrix"))  setAs("ANY", "sparseMatrix", function(from) as(from, "CsparseMatrix"))
9    
10  setAs(from = "sparseMatrix", to = "generalMatrix",  setAs("sparseMatrix", "generalMatrix", as_gSparse)
11        function(from) as_gSparse(from))  
12    setAs("sparseMatrix", "symmetricMatrix", as_sSparse)
13    
14    setAs("sparseMatrix", "triangularMatrix", as_tSparse)
15    
16  ## "graph" coercions -- this needs the graph package which is currently  ## "graph" coercions -- this needs the graph package which is currently
17  ##  -----               *not* required on purpose  ##  -----               *not* required on purpose
# Line 293  Line 296 
296             nR <- d[1] # nrow             nR <- d[1] # nrow
297             useW <- getOption("width") - (format.info(nR)[1] + 3+1)             useW <- getOption("width") - (format.info(nR)[1] + 3+1)
298             ##                           space for "[<last>,] "             ##                           space for "[<last>,] "
299    
300               ## --> suppress rows and/or columns in printing ...
301    
302             suppCols <- (d[2] * 2 > useW)             suppCols <- (d[2] * 2 > useW)
303             nc <- if(suppCols) (useW - (1 + 6)) %/% 2 else d[2]             nc <- if(suppCols) (useW - (1 + 6)) %/% 2 else d[2]
304             ##                          sp+ row.trailer             ##                          sp+ row.trailer
# Line 366  Line 372 
372  setMethod("diag", signature(x = "sparseMatrix"),  setMethod("diag", signature(x = "sparseMatrix"),
373            function(x, nrow, ncol = n) diag(as(x, "CsparseMatrix")))            function(x, nrow, ncol = n) diag(as(x, "CsparseMatrix")))
374    
375    setMethod("dim<-", signature(x = "sparseMatrix", value = "ANY"),
376              function(x, value) {
377                  if(!is.numeric(value) || length(value) != 2)
378                      stop("dim(.) value must be numeric of length 2")
379                  if(prod(dim(x)) != prod(value <- as.integer(value)))
380                      stop("dimensions don't match the number of cells")
381                  ## be careful to keep things sparse
382                  as(spV2M(as(x, "sparseVector"), nrow=value[1], ncol=value[2]),
383                     class(x))
384              })
385    
386    
387  ## .as.dgT.Fun  ## .as.dgT.Fun
388  setMethod("colSums",  signature(x = "sparseMatrix"), .as.dgT.Fun)  setMethod("colSums",  signature(x = "sparseMatrix"), .as.dgT.Fun)
389  setMethod("colMeans", signature(x = "sparseMatrix"), .as.dgT.Fun)  setMethod("colMeans", signature(x = "sparseMatrix"), .as.dgT.Fun)

Legend:
Removed from v.1844  
changed lines
  Added in v.1845

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