SCM

SCM Repository

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

Diff of /pkg/R/dgTMatrix.R

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

revision 686, Thu Mar 31 21:19:35 2005 UTC revision 687, Fri Apr 1 07:36:09 2005 UTC
# Line 7  Line 7 
7  setAs("dgTMatrix", "matrix",  setAs("dgTMatrix", "matrix",
8        function(from) .Call("dgTMatrix_to_matrix", from) )        function(from) .Call("dgTMatrix_to_matrix", from) )
9    
10    setAs("dgeMatrix", "dgTMatrix",
11          function(from) as(as(from, "dgCMatrix"), "dgTMatrix"))
12    
13    setMethod("[", signature(x = "dgTMatrix",
14                             i = "missing", j = "missing", drop = "ANY"),
15              function (x, i, j, ..., drop) x)
16    
17    setMethod("[", signature(x = "dgTMatrix", i = "numeric", j = "missing",
18                             drop = "logical"),
19              function (x, i, j, ..., drop) { ## select rows
20                  storage.mode(i) <- "integer"
21                  xi <- x@i + 1:1 # 1-indexing
22                  sel <- xi %in% i
23                  nd <- c(length(i), ncol(x))
24                  x <- new("dgTMatrix", Dim = nd,
25                           i = match(xi[sel], i) - 1:1,
26                           j = x@j[sel],
27                           x = x@x[sel])
28                  if (drop && any(nd == 1)) drop(as(x,"matrix")) else x
29              })
30    
31    
32    setMethod("[", signature(x = "dgTMatrix", i = "missing", j = "numeric",
33                             drop = "logical"),
34              function (x, i, j, ..., drop) { ## select columns
35                  storage.mode(j) <- "integer"
36                  xj <- x@j + 1:1 # 1-indexing
37                  sel <- xj %in% j
38                  nd <- c(nrow(x), length(j))
39                  x <- new("dgTMatrix", Dim = nd,
40                           i = x@i[sel],
41                           j = match(xj[sel], j) - 1:1,
42                           x = x@x[sel])
43                  if (drop && any(nd == 1)) drop(as(x,"matrix")) else x
44              })
45    
46    
47    ## How can we get at   A[ ij ]  where ij is (i,j) 2-column matrix?
48    ##  and                A[ LL ]  where LL is a logical *vector*
49    
50    setMethod("[", signature(x = "dgTMatrix", i = "numeric", j = "missing",
51                             drop = "missing"),
52              function(x,i,j, ..., drop)
53              callGeneric(x, i=i, drop = TRUE)# or rather 'FALSE' ?
54              )
55    setMethod("[", signature(x = "dgTMatrix", i = "missing", j = "numeric",
56                             drop = "missing"),
57              function(x,i,j, ..., drop)
58              callGeneric(x, j=j, drop = TRUE)# or rather 'FALSE' ?
59              )
60    
61    ## [.data.frame has : drop = if (missing(i)) TRUE else length(cols) == 1)
62    
63    setMethod("[", signature(x = "dgTMatrix",
64                             i = "numeric", j = "numeric", drop = "logical"),
65              function (x, i, j, ..., drop)
66          {
67              ## (i,j, drop) all specified
68              storage.mode(i) <- "integer"
69              storage.mode(j) <- "integer"
70              xi <- x@i + 1:1
71              xj <- x@j + 1:1
72              sel <- (xi %in% i) & (xj %in% j)
73              nd <- c(length(i), length(j))
74              x <- new("dgTMatrix", Dim = nd,
75                       i = match(xi[sel], i) - 1:1,
76                       j = match(xj[sel], j) - 1:1,
77                       x = x@x[sel])
78              if (drop && any(nd == 1)) drop(as(x,"matrix")) else x
79          })
80    
81    setMethod("[", signature(x = "dgTMatrix",
82                             i = "numeric", j = "numeric", drop = "missing"),
83              function(x,i,j, drop) callGeneric(x,i,j,drop= TRUE))
84    
85    
86  setMethod("crossprod", signature(x = "dgTMatrix", y = "missing"),  setMethod("crossprod", signature(x = "dgTMatrix", y = "missing"),
87            function(x, y = NULL)            function(x, y = NULL)
88            .Call("csc_crossprod", as(x, "dgCMatrix")))            .Call("csc_crossprod", as(x, "dgCMatrix")))

Legend:
Removed from v.686  
changed lines
  Added in v.687

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