SCM

SCM Repository

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

Diff of /pkg/R/lgTMatrix.R

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

revision 1547, Mon Sep 11 14:49:39 2006 UTC revision 1548, Mon Sep 11 22:13:07 2006 UTC
# Line 10  Line 10 
10  setAs("matrix", "lgTMatrix",  setAs("matrix", "lgTMatrix",
11        function(from) {        function(from) {
12            stopifnot(is.logical(from))            stopifnot(is.logical(from))
13            if(any(is.na(from)))            TorNA <- is.na(from) | from
14                warning("'NA's coerced to 'FALSE' in coercion to logical sparse")            ij <- which(TorNA, arr.ind = TRUE) - 1:1
           ij <- which(from, arr.ind = TRUE) - 1:1  
15            if(length(ij) == 0) ij <- matrix(ij, 0, 2)            if(length(ij) == 0) ij <- matrix(ij, 0, 2)
16            new("lgTMatrix",            new("lgTMatrix",
17                i = ij[,1],                i = ij[,1],
18                j = ij[,2],                j = ij[,2],
19                  x = from[TorNA],
20                Dim = as.integer(dim(from)),                Dim = as.integer(dim(from)),
21                Dimnames = .M.DN(from))                Dimnames = .M.DN(from))
22            })            })
# Line 26  Line 26 
26        ## more efficient than        ## more efficient than
27        ## as(as(as(sM, "lgCMatrix"), "dgCMatrix"), "dgTMatrix")        ## as(as(as(sM, "lgCMatrix"), "dgCMatrix"), "dgTMatrix")
28        new("dgTMatrix", i = from@i, j = from@j,        new("dgTMatrix", i = from@i, j = from@j,
29            x = rep.int(1, length(from@i)),            x = as.double(from@x),
30            ## cannot copy factors, but can we use them?            ## cannot copy factors, but can we use them?
31            Dim = from@Dim, Dimnames= from@Dimnames))            Dim = from@Dim, Dimnames= from@Dimnames))
32    
33  setMethod("t", signature(x = "lgTMatrix"),  setMethod("t", signature(x = "lgTMatrix"),
34            function(x) new("lgTMatrix", i = x@j, j = x@i,            function(x) new("lgTMatrix", i = x@j, j = x@i, x = x@x,
35                            Dim = x@Dim[2:1],                            Dim = x@Dim[2:1],
36                            Dimnames= x@Dimnames[2:1]),                            Dimnames= x@Dimnames[2:1]),
37            valueClass = "lgTMatrix")            valueClass = "lgTMatrix")

Legend:
Removed from v.1547  
changed lines
  Added in v.1548

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge