The R Project SVN R-packages

Rev

Rev 1322 | Rev 1746 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1322 Rev 1325
Line 13... Line 13...
13
          function(x, y = NULL) callGeneric(x, as(y, "dgeMatrix")))
13
          function(x, y = NULL) callGeneric(x, as(y, "dgeMatrix")))
14
 
14
 
15
setMethod("crossprod", signature(x = "ddenseMatrix", y = "sparseMatrix"),
15
setMethod("crossprod", signature(x = "ddenseMatrix", y = "sparseMatrix"),
16
          function(x, y = NULL) callGeneric(as(x, "dgeMatrix"), y))
16
          function(x, y = NULL) callGeneric(as(x, "dgeMatrix"), y))
17
 
17
 
-
 
18
 
-
 
19
 
-
 
20
setMethod("[", signature(x = "dsparseMatrix",
-
 
21
			 i = "missing", j = "missing", drop = "ANY"), ## "x[]"
-
 
22
	  function (x, i, j, drop) x)
-
 
23
 
-
 
24
setMethod("[", signature(x = "dsparseMatrix", i = "numeric", j = "missing",
-
 
25
			 drop = "logical"),
-
 
26
	  function (x, i, j, drop)
-
 
27
          callGeneric(x = as(x, "dgTMatrix"), i=i, drop=drop))
-
 
28
 
-
 
29
setMethod("[", signature(x = "dsparseMatrix", i = "missing", j = "numeric",
-
 
30
			 drop = "logical"),
-
 
31
	  function (x, i, j, drop)
-
 
32
          callGeneric(x = as(x, "dgTMatrix"), j=j, drop=drop))
-
 
33
 
-
 
34
setMethod("[", signature(x = "dsparseMatrix", i = "numeric", j = "missing",
-
 
35
			 drop = "missing"),
-
 
36
	  function(x,i,j, drop) callGeneric(x, i=i, drop= TRUE))
-
 
37
 
-
 
38
setMethod("[", signature(x = "dsparseMatrix", i = "missing", j = "numeric",
-
 
39
			 drop = "missing"),
-
 
40
	  function(x,i,j, drop) callGeneric(x, j=j, drop= TRUE))
-
 
41
 
-
 
42
setMethod("[", signature(x = "dsparseMatrix",
-
 
43
			 i = "numeric", j = "numeric", drop = "logical"),
-
 
44
	  function (x, i, j, drop)
-
 
45
          callGeneric(x = as(x, "dgTMatrix"), i=i, j=j, drop=drop))
-
 
46
 
-
 
47
setMethod("[", signature(x = "dsparseMatrix",
-
 
48
			 i = "numeric", j = "numeric", drop = "missing"),
-
 
49
	  function(x,i,j, drop) callGeneric(x, i=i, j=j, drop= TRUE))
-
 
50
 
-
 
51
### --- show() method ---
-
 
52
 
-
 
53
emptyColnames <- function(x)
-
 
54
{
-
 
55
    ## Useful for compact printing of (parts) of sparse matrices
-
 
56
    ## possibly  dimnames(x) "==" NULL :
-
 
57
    dimnames(x) <- list(dimnames(x)[[1]], rep("", dim(x)[2]))
-
 
58
    x
-
 
59
}
-
 
60
 
-
 
61
prSpMatrix <- function(object, zero.print = ".")
-
 
62
{
-
 
63
    stopifnot(is(object, "sparseMatrix"))
-
 
64
    m <- as(object, "matrix")
-
 
65
    x <- apply(m, 2, format)
-
 
66
    if(is.null(dim(x))) {# e.g. in  1 x 1 case
-
 
67
        dim(x) <- dim(m)
-
 
68
        dimnames(x) <- dimnames(m)
-
 
69
    }
-
 
70
    x <- emptyColnames(x)
-
 
71
    if(is.logical(zero.print))
-
 
72
	zero.print <- if(zero.print) "0" else " "
-
 
73
    ## FIXME: show only "structural" zeros as 'zero.print', not all of them..
-
 
74
    x[m == 0.] <- zero.print
-
 
75
    print(noquote(x))
-
 
76
    invisible(object)
-
 
77
}
-
 
78
 
-
 
79
setMethod("show", signature(object = "sparseMatrix"),
-
 
80
   function(object) {
-
 
81
       d <- dim(object)
-
 
82
       cl <- class(object)
-
 
83
       cat(sprintf('%d x %d sparse Matrix of class "%s"\n', d[1], d[2], cl))
-
 
84
 
-
 
85
       maxp <- getOption("max.print")
-
 
86
       if(prod(d) <= maxp)
-
 
87
	   prSpMatrix(object)
-
 
88
       else { ## d[1] > maxp / d[2] >= nr : -- this needs [,] working:
-
 
89
	   nr <- maxp %/% d[2]
-
 
90
	   n2 <- ceiling(nr / 2)
-
 
91
	   nR <- d[1] # nrow
-
 
92
	   prSpMatrix(object[seq(length = min(nR, max(1, n2))), drop = FALSE])
-
 
93
	   cat("\n ..........\n\n")
-
 
94
	   prSpMatrix(object[seq(to = nR, length = min(max(1, nr-n2), nR)),
-
 
95
                             drop = FALSE])
-
 
96
           invisible(object)
-
 
97
       }
-
 
98
   })