# SCM Repository

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

# Diff of /pkg/R/dtCMatrix.R

revision 1506, Mon Sep 4 16:40:57 2006 UTC revision 1507, Mon Sep 4 18:41:34 2006 UTC
# Line 1  Line 1
1  ## can use the method for x = "CsparseMatrix" in ./Csparse.R  #### Triangular Sparse Matrices in compressed column-oriented format
## setMethod("t", signature(x = "dtCMatrix"),
##           function(x) {
##               tg <- .Call(csc_transpose, x)
##               new("dtCMatrix", Dim = tg@Dim, Dimnames = x@Dimnames[2:1],
##                   p = tg@p, i = tg@i, x = tg@x, diag = x@diag,
##                   uplo = ifelse(x@uplo == "U", "L", "U"))
##           }, valueClass = "dtCMatrix")
2
3  setAs("dtCMatrix", "ltCMatrix", # just drop 'x' slot:  setAs("dtCMatrix", "ltCMatrix", # just drop 'x' slot:
4        function(from) new("ltCMatrix", i = from@i, p = from@p,        function(from) new("ltCMatrix", i = from@i, p = from@p,
# Line 18  Line 11
11
12  setAs("dtCMatrix", "dgCMatrix",  setAs("dtCMatrix", "dgCMatrix",
13        function(from) {        function(from) {
14            if(from@diag == "U") { ## add diagonal of 1's            if (from@diag == "U")
15                ##FIXME: do this smartly - directly {in C or R}                from <- .Call(Csparse_diagU2N, from)
as(as(from, "dgTMatrix"), "dgCMatrix")
}
else
16                new("dgCMatrix",                new("dgCMatrix",
17                    i = from@i, p = from@p, x = from@x,                    i = from@i, p = from@p, x = from@x,
18                    Dim = from@Dim, Dimnames = from@Dimnames)                    Dim = from@Dim, Dimnames = from@Dimnames)
19        })        })
20
21    setAs("dtCMatrix", "dgTMatrix",
22          function(from) {
23              if (from@diag == "U") from <- .Call(Csparse_diagU2N, from)
24              ## ignore triangularity in conversion to TsparseMatrix
25              .Call(Csparse_to_Tsparse, from, FALSE)
26          })
27
28  setAs("dgCMatrix", "dtCMatrix", # to triangular:  setAs("dgCMatrix", "dtCMatrix", # to triangular:
29        function(from) as(as(as(from, "dgTMatrix"), "dtTMatrix"), "dtCMatrix"))        function(from) as(as(as(from, "dgTMatrix"), "dtTMatrix"), "dtCMatrix"))
30
setAs("dtCMatrix", "dgTMatrix",
function(from)
.Call(tsc_to_dgTMatrix, from))

31  setAs("dtCMatrix", "dgeMatrix",  setAs("dtCMatrix", "dgeMatrix",
32        function(from) as(as(from, "dgTMatrix"), "dgeMatrix"))        function(from) as(as(from, "dgTMatrix"), "dgeMatrix"))
33

Legend:
 Removed from v.1506 changed lines Added in v.1507