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 642 - (view) (download)

1 : bates 597 #### Triangular Packed Matrices -- Coercion and Methods
2 :    
3 :     setAs("dtpMatrix", "dtrMatrix",
4 :     function(from) .Call("dtpMatrix_as_dtrMatrix", from) )
5 :    
6 :     setAs("dtpMatrix", "dgeMatrix",
7 :     function(from) as(as(from, "dtrMatrix"), "dgeMatrix"))
8 :    
9 :     setAs("dtpMatrix", "matrix",
10 :     function(from) as(as(from, "dtrMatrix"), "matrix"))
11 :    
12 : maechler 609
13 : bates 597 setMethod("%*%", signature(x = "dtpMatrix", y = "dgeMatrix"),
14 :     function(x, y) .Call("dtpMatrix_dgeMatrix_mm", x, y))
15 : maechler 609 setMethod("%*%", signature(x = "dgeMatrix", y = "dtpMatrix"),
16 : maechler 628 function(x, y) .Call("dgeMatrix_dtpMatrix_mm", x, y))
17 :     ## "matrix"
18 : bates 603 setMethod("%*%", signature(x = "dtpMatrix", y = "matrix"),
19 : maechler 628 function(x, y) .Call("dtpMatrix_matrix_mm", x, y))# result = "matrix"
20 :     setMethod("%*%", signature(x = "matrix", y = "dtpMatrix"),
21 :     function(x, y) callGeneric(as(x,"dgeMatrix"), y))# result: "dgeMatrix"
22 : bates 603
23 : maechler 628 ## "numeric" (same as "dgeMatrix")
24 :     setMethod("%*%", signature(x = "dtpMatrix", y = "numeric"), .M.n)
25 :     setMethod("%*%", signature(x = "numeric", y = "dtpMatrix"), .n.M)
26 :    
27 : bates 597 setMethod("determinant", signature(x = "dtpMatrix", logarithm = "missing"),
28 :     function(x, logarithm, ...) determinant(x, TRUE))
29 :    
30 :     setMethod("diag", signature(x = "dtpMatrix"),
31 : maechler 609 function(x = 1, nrow, ncol = n) .Call("dtpMatrix_getDiag", x),
32 : bates 597 valueClass = "numeric")
33 : maechler 609
34 : bates 597 setMethod("determinant", signature(x = "dtpMatrix", logarithm = "logical"),
35 :     function(x, logarithm, ...) {
36 :     dg <- diag(x)
37 :     if (logarithm) {
38 :     modulus <- sum(log(abs(dg)))
39 :     sgn <- prod(sign(dg))
40 :     } else {
41 :     modulus <- prod(dg)
42 :     sgn <- sign(modulus)
43 :     modulus <- abs(modulus)
44 :     }
45 :     attr(modulus, "logarithm") <- logarithm
46 :     val <- list(modulus = modulus, sign = sgn)
47 :     class(val) <- "det"
48 :     val
49 :     })
50 :    
51 :     setMethod("norm", signature(x = "dtpMatrix", type = "character"),
52 :     function(x, type, ...)
53 :     .Call("dtpMatrix_norm", x, type),
54 :     valueClass = "numeric")
55 :    
56 :     setMethod("norm", signature(x = "dtpMatrix", type = "missing"),
57 :     function(x, type, ...)
58 :     .Call("dtpMatrix_norm", x, "O"),
59 :     valueClass = "numeric")
60 :    
61 :     setMethod("rcond", signature(x = "dtpMatrix", type = "character"),
62 :     function(x, type, ...)
63 :     .Call("dtpMatrix_rcond", x, type),
64 :     valueClass = "numeric")
65 :    
66 :     setMethod("rcond", signature(x = "dtpMatrix", type = "missing"),
67 :     function(x, type, ...)
68 :     .Call("dtpMatrix_rcond", x, "O"),
69 :     valueClass = "numeric")
70 :    
71 :     setMethod("solve", signature(a = "dtpMatrix", b="missing"),
72 :     function(a, b, ...)
73 :     .Call("dtpMatrix_solve", a),
74 :     valueClass = "dtpMatrix")
75 :    
76 :     setMethod("solve", signature(a = "dtpMatrix", b="matrix"),
77 :     function(a, b, ...)
78 :     .Call("dtpMatrix_matrix_solve", a, b),
79 :     valueClass = "matrix")
80 :    
81 :     setMethod("t", signature(x = "dtpMatrix"),
82 :     function(x) as(t(as(x, "dtrMatrix")), "dtpMatrix"),
83 :     valueClass = "dtpMatrix")
84 : bates 642
85 :     setMethod("unpack", signature(x = "dtpMatrix"),
86 :     function(x, ...) as(x, "dtrMatrix"),
87 :     valueClass = "dtrMatrix")
88 : 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