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