SCM

SCM Repository

[matrix] Annotation of /pkg/Matrix/R/ddenseMatrix.R
ViewVC logotype

Annotation of /pkg/Matrix/R/ddenseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1331 - (view) (download)
Original Path: pkg/R/ddenseMatrix.R

1 : bates 686 ### Define Methods that can be inherited for all subclasses
2 :    
3 : maechler 956 setAs("dgeMatrix", "lgeMatrix", d2l_Matrix)
4 :     setAs("dtrMatrix", "ltrMatrix", d2l_Matrix)
5 :     setAs("dtpMatrix", "ltpMatrix", d2l_Matrix)
6 :     setAs("dsyMatrix", "lsyMatrix", d2l_Matrix)
7 :     setAs("dspMatrix", "lspMatrix", d2l_Matrix)
8 :    
9 : maechler 792 ## -- see also ./Matrix.R e.g., for a show() method
10 :    
11 : bates 686 ## These methods are the 'fallback' methods for all dense numeric
12 : maechler 792 ## matrices in that they simply coerce the ddenseMatrix to a
13 :     ## dgeMatrix. Methods for special forms override these.
14 : bates 686
15 :     setMethod("norm", signature(x = "ddenseMatrix", type = "missing"),
16 :     function(x, type, ...) callGeneric(as(x, "dgeMatrix")))
17 :    
18 :     setMethod("norm", signature(x = "ddenseMatrix", type = "character"),
19 :     function(x, type, ...) callGeneric(as(x, "dgeMatrix"), type))
20 :    
21 :     setMethod("rcond", signature(x = "ddenseMatrix", type = "missing"),
22 :     function(x, type, ...) callGeneric(as(x, "dgeMatrix")))
23 :    
24 :     setMethod("rcond", signature(x = "ddenseMatrix", type = "character"),
25 :     function(x, type, ...) callGeneric(as(x, "dgeMatrix"), type))
26 :    
27 : maechler 946 ## Not really useful; now require *identical* class for result:
28 :     ## setMethod("t", signature(x = "ddenseMatrix"),
29 :     ## function(x) callGeneric(as(x, "dgeMatrix")))
30 : bates 686
31 : maechler 1087 setMethod("tcrossprod", signature(x = "ddenseMatrix", y = "missing"),
32 :     function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))
33 : bates 686
34 :     setMethod("crossprod", signature(x = "ddenseMatrix", y = "missing"),
35 :     function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))
36 :    
37 :     setMethod("diag", signature(x = "ddenseMatrix"),
38 :     function(x = 1, nrow, ncol = n) callGeneric(as(x, "dgeMatrix")))
39 :    
40 :     setMethod("solve", signature(a = "ddenseMatrix", b = "missing"),
41 :     function(a, b, ...) callGeneric(as(a, "dgeMatrix")))
42 :    
43 :     setMethod("solve", signature(a = "ddenseMatrix", b = "ANY"),
44 :     function(a, b, ...) callGeneric(as(a, "dgeMatrix"), b))
45 :    
46 :     setMethod("lu", signature(x = "ddenseMatrix"),
47 :     function(x, ...) callGeneric(as(x, "dgeMatrix")))
48 :    
49 : maechler 856 setMethod("determinant", signature(x = "ddenseMatrix", logarithm = "missing"),
50 : bates 686 function(x, logarithm, ...) callGeneric(as(x, "dgeMatrix")))
51 :    
52 : maechler 856 setMethod("determinant", signature(x = "ddenseMatrix", logarithm = "logical"),
53 : bates 686 function(x, logarithm, ...)
54 :     callGeneric(as(x, "dgeMatrix"), logarithm))
55 :    
56 : maechler 954 ## now done for "dMatrix":
57 :     ## setMethod("expm", signature(x = "ddenseMatrix"),
58 :     ## function(x) callGeneric(as(x, "dgeMatrix")))
59 : bates 686
60 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "missing"),
61 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix")))
62 :    
63 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "logical"),
64 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix"), vectors))
65 :    
66 : maechler 792
67 : maechler 1331 ## Cheap version: work via "dgeMatrix" and use the group methods there:
68 :     ## FIXME(?): try to preserve "symmetric", "triangular", ...
69 :     setMethod("Arith", ## "+", "-", "*", "^", "%%", "%/%", "/"
70 :     signature(e1 = "ddenseMatrix", e2 = "ddenseMatrix"),
71 :     function(e1, e2) callGeneric(as(e1, "dgeMatrix"),
72 :     as(e2, "dgeMatrix")))
73 :     setMethod("Arith",
74 :     signature(e1 = "ddenseMatrix", e2 = "numeric"),
75 :     function(e1, e2) callGeneric(as(e1, "dgeMatrix"), e2))
76 :     setMethod("Arith",
77 :     signature(e1 = "numeric", e2 = "ddenseMatrix"),
78 :     function(e1, e2) callGeneric(e1, as(e2, "dgeMatrix")))
79 : maechler 908
80 : maechler 1331 setMethod("Math",
81 :     signature(x = "ddenseMatrix"),
82 :     function(x) callGeneric(as(x, "dgeMatrix")))
83 :    
84 :    
85 :    
86 :     ### for R 2.2.x (and later): -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
87 :    
88 : maechler 925 ### cbind2
89 : maechler 1331 setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),
90 :     function(x, y) {
91 :     d <- dim(x); nr <- d[1]; nc <- d[2]
92 :     y <- rep(y, length.out = nr) # 'silent procrustes'
93 :     ## beware of (packed) triangular, symmetric, ...
94 :     x <- as(x, "dgeMatrix")
95 :     x@x <- c(x@x, as.double(y))
96 :     x@Dim[2] <- nc + 1:1
97 :     if(is.character(dn <- x@Dimnames[[2]]))
98 :     x@Dimnames[[2]] <- c(dn, "")
99 :     x
100 :     })
101 :     ## the same, (x,y) <-> (y,x):
102 :     setMethod("cbind2", signature(x = "numeric", y = "ddenseMatrix"),
103 :     function(x, y) {
104 :     d <- dim(y); nr <- d[1]; nc <- d[2]
105 :     x <- rep(x, length.out = nr)
106 :     y <- as(y, "dgeMatrix")
107 :     y@x <- c(as.double(x), y@x)
108 :     y@Dim[2] <- nc + 1:1
109 :     if(is.character(dn <- y@Dimnames[[2]]))
110 :     y@Dimnames[[2]] <- c("", dn)
111 :     y
112 :     })
113 : maechler 908
114 : maechler 1331 setMethod("cbind2", signature(x = "ddenseMatrix", y = "matrix"),
115 :     function(x, y) callGeneric(x, as(y, "dgeMatrix")))
116 :     setMethod("cbind2", signature(x = "matrix", y = "ddenseMatrix"),
117 :     function(x, y) callGeneric(as(x, "dgeMatrix"), y))
118 : maechler 908
119 : maechler 1331 setMethod("cbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
120 :     function(x, y) {
121 :     nr <- rowCheck(x,y)
122 :     ncx <- x@Dim[2]
123 :     ncy <- y@Dim[2]
124 :     ## beware of (packed) triangular, symmetric, ...
125 :     hasDN <- !is.null(dnx <- dimnames(x)) |
126 :     !is.null(dny <- dimnames(y))
127 :     x <- as(x, "dgeMatrix")
128 :     y <- as(y, "dgeMatrix")
129 :     x@x <- c(x@x, y@x)
130 :     x@Dim[2] <- ncx + ncy
131 :     if(hasDN) {
132 :     ## R and S+ are different in which names they take
133 :     ## if they differ -- but there's no warning in any case
134 :     rn <- if(!is.null(dnx[[1]])) dnx[[1]] else dny[[1]]
135 :     cx <- dnx[[2]] ; cy <- dny[[2]]
136 :     cn <- if(is.null(cx) && is.null(cy)) NULL
137 :     else c(if(!is.null(cx)) cx else rep.int("", ncx),
138 :     if(!is.null(cy)) cy else rep.int("", ncy))
139 :     x@Dimnames <- list(rn, cn)
140 :     }
141 :     x
142 :     })
143 : maechler 908
144 : maechler 925 ### rbind2 -- analogous to cbind2 --- more to do for @x though:
145 : maechler 908
146 : maechler 1331 setMethod("rbind2", signature(x = "ddenseMatrix", y = "numeric"),
147 :     function(x, y) {
148 :     if(is.character(dn <- x@Dimnames[[1]])) dn <- c(dn, "")
149 :     new("dgeMatrix", Dim = x@Dim + 1:0,
150 :     Dimnames = list(dn, x@Dimnames[[2]]),
151 :     x = c(rbind2(as(x,"matrix"), y)))
152 :     })
153 :     ## the same, (x,y) <-> (y,x):
154 :     setMethod("rbind2", signature(x = "numeric", y = "ddenseMatrix"),
155 :     function(x, y) {
156 :     if(is.character(dn <- y@Dimnames[[1]])) dn <- c("", dn)
157 :     new("dgeMatrix", Dim = y@Dim + 1:0,
158 :     Dimnames = list(dn, y@Dimnames[[2]]),
159 :     x = c(rbind2(x, as(y,"matrix"))))
160 :     })
161 : maechler 925
162 : maechler 1331 setMethod("rbind2", signature(x = "ddenseMatrix", y = "matrix"),
163 :     function(x, y) callGeneric(x, as(y, "dgeMatrix")))
164 :     setMethod("rbind2", signature(x = "matrix", y = "ddenseMatrix"),
165 :     function(x, y) callGeneric(as(x, "dgeMatrix"), y))
166 : maechler 925
167 : maechler 1331 setMethod("rbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
168 :     function(x, y) {
169 :     nc <- colCheck(x,y)
170 :     nrx <- x@Dim[1]
171 :     nry <- y@Dim[1]
172 :     dn <-
173 :     if(!is.null(dnx <- dimnames(x)) |
174 :     !is.null(dny <- dimnames(y))) {
175 :     ## R and S+ are different in which names they take
176 :     ## if they differ -- but there's no warning in any case
177 :     list(if(is.null(rx <- dnx[[1]]) && is.null(ry <- dny[[1]]))
178 :     NULL else
179 :     c(if(!is.null(rx)) rx else rep.int("", nrx),
180 :     if(!is.null(ry)) ry else rep.int("", nry)),
181 :     if(!is.null(dnx[[2]])) dnx[[2]] else dny[[2]])
182 : maechler 925
183 : maechler 1331 } else list(NULL, NULL)
184 :     ## beware of (packed) triangular, symmetric, ...
185 :     new("dgeMatrix", Dim = c(nrx + nry, nc), Dimnames = dn,
186 :     x = c(rbind2(as(x,"matrix"), as(y,"matrix"))))
187 :     })

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