SCM

SCM Repository

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

Annotation of /pkg/R/dtpMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1463 - (view) (download)

1 : bates 597 #### Triangular Packed Matrices -- Coercion and Methods
2 :    
3 :     setAs("dtpMatrix", "dtrMatrix",
4 : maechler 1280 function(from) .Call(dtpMatrix_as_dtrMatrix, from))
5 : bates 597
6 : maechler 1447 if(FALSE) # now have faster "ddense" -> "dge"
7 : bates 597 setAs("dtpMatrix", "dgeMatrix",
8 :     function(from) as(as(from, "dtrMatrix"), "dgeMatrix"))
9 :    
10 : maechler 1174 setAs("dtpMatrix", "dtTMatrix",
11 :     ## FIXME this is NOT efficient:
12 :     function(from) {
13 :     x <- as(from, "TsparseMatrix")
14 :     if(is(x, "dtTMatrix"))
15 :     x
16 :     else
17 :     gt2tT(as(x, "dgTMatrix"), uplo = from@uplo, diag = from@diag)
18 :     })
19 :    
20 : bates 597 setAs("dtpMatrix", "matrix",
21 :     function(from) as(as(from, "dtrMatrix"), "matrix"))
22 : maechler 657 setAs("matrix", "dtpMatrix",
23 :     function(from) as(as(from, "dtrMatrix"), "dtpMatrix"))
24 : bates 597
25 : maechler 609
26 : bates 1463 setMethod("%*%", signature(x = "dtpMatrix", y = "ddenseMatrix"),
27 :     function(x, y) .Call(dtpMatrix_matrix_mm, x, y))
28 : maechler 609 setMethod("%*%", signature(x = "dgeMatrix", y = "dtpMatrix"),
29 : maechler 1280 function(x, y) .Call(dgeMatrix_dtpMatrix_mm, x, y))
30 : bates 1463 ## DB: I don't think this is needed any more
31 : maechler 657 ## %*% should always work for <fooMatrix> %*% <fooMatrix>
32 : bates 1463 ## setMethod("%*%", signature(x = "dtpMatrix", y = "dtpMatrix"),
33 :     ## function(x, y)
34 :     ## ## FIXME: this is cheap; could we optimize chosing the better of
35 :     ## ## callGeneric(x, as(y, "dgeMatrix")) and
36 :     ## ## callGeneric(as(x "dgeMatrix"), y)) depending on their 'uplo' ?
37 :     ## callGeneric(x, as(y, "dgeMatrix")))
38 : maechler 657
39 :     ## dtpMatrix <-> matrix : will be used by the "numeric" one
40 : bates 603 setMethod("%*%", signature(x = "dtpMatrix", y = "matrix"),
41 : bates 1463 function(x, y) .Call(dtpMatrix_matrix_mm, x, y))
42 : maechler 628 setMethod("%*%", signature(x = "matrix", y = "dtpMatrix"),
43 : maechler 657 function(x, y) callGeneric(as(x, "dgeMatrix"), y))
44 : bates 603
45 : maechler 657 ## dtpMatrix <-> numeric : the auxiliary functions are R version specific!
46 : bates 683 ##setMethod("%*%", signature(x = "dtpMatrix", y = "numeric"), .M.v)
47 :     ##setMethod("%*%", signature(x = "numeric", y = "dtpMatrix"), .v.M)
48 : maechler 628
49 : maechler 657
50 : bates 597 setMethod("determinant", signature(x = "dtpMatrix", logarithm = "missing"),
51 :     function(x, logarithm, ...) determinant(x, TRUE))
52 :    
53 :     setMethod("determinant", signature(x = "dtpMatrix", logarithm = "logical"),
54 :     function(x, logarithm, ...) {
55 :     dg <- diag(x)
56 :     if (logarithm) {
57 :     modulus <- sum(log(abs(dg)))
58 :     sgn <- prod(sign(dg))
59 :     } else {
60 :     modulus <- prod(dg)
61 :     sgn <- sign(modulus)
62 :     modulus <- abs(modulus)
63 :     }
64 :     attr(modulus, "logarithm") <- logarithm
65 :     val <- list(modulus = modulus, sign = sgn)
66 :     class(val) <- "det"
67 :     val
68 :     })
69 :    
70 : maechler 657 setMethod("diag", signature(x = "dtpMatrix"),
71 : maechler 1280 function(x = 1, nrow, ncol = n) .Call(dtpMatrix_getDiag, x),
72 : maechler 657 valueClass = "numeric")
73 :    
74 : bates 597 setMethod("norm", signature(x = "dtpMatrix", type = "character"),
75 :     function(x, type, ...)
76 : maechler 1280 .Call(dtpMatrix_norm, x, type),
77 : bates 597 valueClass = "numeric")
78 :    
79 :     setMethod("norm", signature(x = "dtpMatrix", type = "missing"),
80 :     function(x, type, ...)
81 : maechler 1280 .Call(dtpMatrix_norm, x, "O"),
82 : bates 597 valueClass = "numeric")
83 :    
84 :     setMethod("rcond", signature(x = "dtpMatrix", type = "character"),
85 :     function(x, type, ...)
86 : maechler 1280 .Call(dtpMatrix_rcond, x, type),
87 : bates 597 valueClass = "numeric")
88 :    
89 :     setMethod("rcond", signature(x = "dtpMatrix", type = "missing"),
90 :     function(x, type, ...)
91 : maechler 1280 .Call(dtpMatrix_rcond, x, "O"),
92 : bates 597 valueClass = "numeric")
93 :    
94 :     setMethod("solve", signature(a = "dtpMatrix", b="missing"),
95 : bates 1463 function(a, b, ...) .Call(dtpMatrix_solve, a),
96 : bates 597 valueClass = "dtpMatrix")
97 :    
98 : bates 1463 setMethod("solve", signature(a = "dtpMatrix", b="ddenseMatrix"),
99 :     function(a, b, ...) .Call(dtpMatrix_matrix_solve, a, b),
100 :     valueClass = "dgeMatrix")
101 :    
102 : bates 597 setMethod("solve", signature(a = "dtpMatrix", b="matrix"),
103 : bates 1463 function(a, b, ...) .Call(dtpMatrix_matrix_solve, a, b),
104 :     valueClass = "dgeMatrix")
105 : bates 597
106 :     setMethod("t", signature(x = "dtpMatrix"),
107 :     function(x) as(t(as(x, "dtrMatrix")), "dtpMatrix"),
108 :     valueClass = "dtpMatrix")
109 : bates 642
110 :     setMethod("unpack", signature(x = "dtpMatrix"),
111 :     function(x, ...) as(x, "dtrMatrix"),
112 :     valueClass = "dtrMatrix")
113 : bates 597 ###

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