SCM

SCM Repository

[matrix] Annotation of /pkg/R/dtCMatrix.R
ViewVC logotype

Annotation of /pkg/R/dtCMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1253 - (view) (download)

1 : bates 483 setMethod("t", signature(x = "dtCMatrix"),
2 : bates 1209 function(x) {
3 :     tg <- t(as(x, "dgCMatrix"))
4 :     new("dtCMatrix", Dim = tg@Dim, Dimnames = tg@Dimnames,
5 :     p = tg@p, i = tg@i, x = tg@x, diag = x@diag,
6 :     uplo = ifelse(x@uplo == "U", "L", "U"))
7 :     }, valueClass = "dtCMatrix")
8 : bates 70
9 : maechler 1202 setAs("dtCMatrix", "ltCMatrix", # just drop 'x' slot:
10 : maechler 956 function(from) new("ltCMatrix", i = from@i, p = from@p,
11 :     uplo = from@uplo, diag = from@diag,
12 : maechler 1202 ## FIXME?: use from@factors smartly
13 : maechler 956 Dim = from@Dim, Dimnames = from@Dimnames))
14 : bates 923
15 : maechler 1174 setAs("matrix", "dtCMatrix",
16 :     function(from) as(as(from, "dtTMatrix"), "dtCMatrix"))
17 :    
18 : maechler 959 setAs("dtCMatrix", "dgCMatrix",
19 :     function(from) {
20 :     if(from@diag == "U") { ## add diagonal of 1's
21 :     ##FIXME: do this smartly - directly {in C or R}
22 :     as(as(from, "dgTMatrix"), "dgCMatrix")
23 :     }
24 :     else
25 :     new("dgCMatrix",
26 :     i = from@i, p = from@p, x = from@x,
27 :     Dim = from@Dim, Dimnames = from@Dimnames)
28 :     })
29 :    
30 : maechler 1238 setAs("dgCMatrix", "dtCMatrix", # to triangular:
31 :     function(from) as(as(as(from, "dgTMatrix"), "dtTMatrix"), "dtCMatrix"))
32 :    
33 : bates 483 setAs("dtCMatrix", "dgTMatrix",
34 : bates 1037 function(from)
35 :     .Call("tsc_to_dgTMatrix", from, PACKAGE = "Matrix"))
36 : bates 70
37 : bates 483 setAs("dtCMatrix", "dgeMatrix",
38 : bates 477 function(from) as(as(from, "dgTMatrix"), "dgeMatrix"))
39 : maechler 1174
40 :     ## These are all needed because cholmod doesn't support triangular:
41 :     ## (see end of ./Csparse.R )
42 :     setAs("dtCMatrix", "dtTMatrix",
43 :     function(from) {# and this is not elegant:
44 :     x <- as(from, "dgTMatrix")
45 : maechler 1253 if (from@diag == "U") { ## drop diagonal entries '1':
46 :     i <- x@i; j <- x@j
47 :     nonD <- i != j
48 :     xx <- x@x[nonD] ; i <- i[nonD] ; j <- j[nonD]
49 :     } else {
50 :     xx <- x@x; i <- x@i; j <- x@j
51 :     }
52 :     new("dtTMatrix", x = xx, i = i, j = j, Dim = x@Dim,
53 :     Dimnames = x@Dimnames, uplo = from@uplo, diag = from@diag)
54 : maechler 1174 })
55 :    
56 :     setAs("dtCMatrix", "TsparseMatrix", function(from) as(from, "dtTMatrix"))
57 : bates 1251
58 : maechler 1174 setAs("dtCMatrix", "dtrMatrix",
59 :     function(from) as(as(from, "dtTMatrix"), "dtrMatrix"))
60 : bates 1251
61 : maechler 1253 ## using diagU2N() from ./Auxiliaries.R :
62 : bates 1251 setMethod("solve", signature(a = "dtCMatrix", b = "missing"),
63 :     function(a, b, ...) {
64 : maechler 1253 if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
65 :     .Call("dtCMatrix_solve", a, PACKAGE = "Matrix")
66 :     }, valueClass = "dtCMatrix")
67 : bates 1251
68 :     setMethod("solve", signature(a = "dtCMatrix", b = "dgeMatrix"),
69 :     function(a, b, ...) {
70 : maechler 1253 if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
71 :     .Call("dtCMatrix_matrix_solve", a, b, TRUE, PACKAGE = "Matrix")
72 :     }, valueClass = "dgeMatrix")
73 : bates 1251
74 :     setMethod("solve", signature(a = "dtCMatrix", b = "matrix"),
75 :     function(a, b, ...) {
76 : maechler 1253 if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
77 : bates 1251 storage.mode(b) <- "double"
78 :     .Call("dtCMatrix_matrix_solve", a, b, FALSE, PACKAGE = "Matrix")
79 :     }, valueClass = "dgeMatrix")
80 :    
81 :     setMethod("solve", signature(a = "dtCMatrix", b = "numeric"),
82 :     function(a, b, ...) {
83 : maechler 1253 if (a@diag == "U") a <- as(diagU2N(a), "dtCMatrix")
84 :     .Call("dtCMatrix_matrix_solve", a, as.matrix(as.double(b)),
85 :     FALSE, PACKAGE = "Matrix")
86 :     }, valueClass = "dgeMatrix")

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