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 954 - (view) (download)
Original Path: pkg/R/ddenseMatrix.R

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

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