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 946 - (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 :     setMethod("expm", signature(x = "ddenseMatrix"),
51 :     function(x) callGeneric(as(x, "dgeMatrix")))
52 :    
53 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "missing"),
54 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix")))
55 :    
56 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "logical"),
57 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix"), vectors))
58 :    
59 : maechler 792
60 : maechler 908 ### NAMESPACE must export this -- also only for R version 2.2.x:
61 :     if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {
62 :     ## for R 2.2.x (and later):
63 :    
64 : maechler 925 ### cbind2
65 : maechler 908 setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),
66 : maechler 925 function(x, y) {
67 :     d <- dim(x); nr <- d[1]; nc <- d[2]
68 :     y <- rep(y, length.out = nr)# 'silent procrustes'
69 :     ## beware of (packed) triangular, symmetric, ...
70 :     x <- as(x, "dgeMatrix")
71 :     x@x <- c(x@x, as.double(y))
72 :     x@Dim[2] <- nc + 1:1
73 :     if(is.character(dn <- x@Dimnames[[2]]))
74 :     x@Dimnames[[2]] <- c(dn, "")
75 :     x
76 :     })
77 : maechler 908 ## the same, (x,y) <-> (y,x):
78 :     setMethod("cbind2", signature(x = "numeric", y = "ddenseMatrix"),
79 : maechler 925 function(x, y) {
80 :     d <- dim(y); nr <- d[1]; nc <- d[2]
81 :     x <- rep(x, length.out = nr)
82 :     y <- as(y, "dgeMatrix")
83 :     y@x <- c(as.double(x), y@x)
84 :     y@Dim[2] <- nc + 1:1
85 :     if(is.character(dn <- y@Dimnames[[2]]))
86 :     y@Dimnames[[2]] <- c("", dn)
87 :     y
88 :     })
89 : maechler 908
90 :     setMethod("cbind2", signature(x = "ddenseMatrix", y = "matrix"),
91 : maechler 925 function(x, y) callGeneric(x, as(y, "dgeMatrix")))
92 : maechler 908 setMethod("cbind2", signature(x = "matrix", y = "ddenseMatrix"),
93 : maechler 925 function(x, y) callGeneric(as(x, "dgeMatrix"), y))
94 : maechler 908
95 :     setMethod("cbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
96 : maechler 925 function(x, y) {
97 :     nr <- rowCheck(x,y)
98 :     ncx <- x@Dim[2]
99 :     ncy <- y@Dim[2]
100 :     ## beware of (packed) triangular, symmetric, ...
101 :     hasDN <- !is.null(dnx <- dimnames(x)) |
102 :     !is.null(dny <- dimnames(y))
103 :     x <- as(x, "dgeMatrix")
104 :     y <- as(y, "dgeMatrix")
105 :     x@x <- c(x@x, y@x)
106 :     x@Dim[2] <- ncx + ncy
107 :     if(hasDN) {
108 :     ## R and S+ are different in which names they take
109 :     ## if they differ -- but there's no warning in any case
110 :     rn <- if(!is.null(dnx[[1]])) dnx[[1]] else dny[[1]]
111 :     cx <- dnx[[2]] ; cy <- dny[[2]]
112 :     cn <- if(is.null(cx) && is.null(cy)) NULL
113 :     else c(if(!is.null(cx)) cx else rep.int("", ncx),
114 :     if(!is.null(cy)) cy else rep.int("", ncy))
115 :     x@Dimnames <- list(rn, cn)
116 :     }
117 :     x
118 :     })
119 : maechler 908
120 : maechler 925 ### rbind2 -- analogous to cbind2 --- more to do for @x though:
121 : maechler 908
122 : maechler 925 setMethod("rbind2", signature(x = "ddenseMatrix", y = "numeric"),
123 :     function(x, y) {
124 :     if(is.character(dn <- x@Dimnames[[1]])) dn <- c(dn, "")
125 :     new("dgeMatrix", Dim = x@Dim + 1:0,
126 :     Dimnames = list(dn, x@Dimnames[[2]]),
127 :     x = c(rbind2(as(x,"matrix"), y)))
128 :     })
129 :     ## the same, (x,y) <-> (y,x):
130 :     setMethod("rbind2", signature(x = "numeric", y = "ddenseMatrix"),
131 :     function(x, y) {
132 :     if(is.character(dn <- y@Dimnames[[1]])) dn <- c("", dn)
133 :     new("dgeMatrix", Dim = y@Dim + 1:0,
134 :     Dimnames = list(dn, y@Dimnames[[2]]),
135 :     x = c(rbind2(x, as(y,"matrix"))))
136 :     })
137 :    
138 :     setMethod("rbind2", signature(x = "ddenseMatrix", y = "matrix"),
139 :     function(x, y) callGeneric(x, as(y, "dgeMatrix")))
140 :     setMethod("rbind2", signature(x = "matrix", y = "ddenseMatrix"),
141 :     function(x, y) callGeneric(as(x, "dgeMatrix"), y))
142 :    
143 :     setMethod("rbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
144 :     function(x, y) {
145 :     nc <- colCheck(x,y)
146 :     nrx <- x@Dim[1]
147 :     nry <- y@Dim[1]
148 :     dn <-
149 :     if(!is.null(dnx <- dimnames(x)) |
150 :     !is.null(dny <- dimnames(y))) {
151 :     ## R and S+ are different in which names they take
152 :     ## if they differ -- but there's no warning in any case
153 :     list(if(is.null(rx <- dnx[[1]]) && is.null(ry <- dny[[1]]))
154 :     NULL else
155 :     c(if(!is.null(rx)) rx else rep.int("", nrx),
156 :     if(!is.null(ry)) ry else rep.int("", nry)),
157 :     if(!is.null(dnx[[2]])) dnx[[2]] else dny[[2]])
158 :    
159 :     } else list(NULL, NULL)
160 :     ## beware of (packed) triangular, symmetric, ...
161 :     new("dgeMatrix", Dim = c(nrx + nry, nc), Dimnames = dn,
162 :     x = c(rbind2(as(x,"matrix"), as(y,"matrix"))))
163 :     })
164 :    
165 : 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