SCM

SCM Repository

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

Annotation of /pkg/R/ddenseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 908 - (view) (download)

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 :     setMethod("t", signature(x = "ddenseMatrix"),
22 :     function(x) callGeneric(as(x, "dgeMatrix")))
23 :    
24 :     setMethod("tcrossprod", signature(x = "ddenseMatrix"),
25 :     function(x) callGeneric(as(x, "dgeMatrix")))
26 :    
27 :     setMethod("crossprod", signature(x = "ddenseMatrix", y = "missing"),
28 :     function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))
29 :    
30 :     setMethod("diag", signature(x = "ddenseMatrix"),
31 :     function(x = 1, nrow, ncol = n) callGeneric(as(x, "dgeMatrix")))
32 :    
33 :     setMethod("solve", signature(a = "ddenseMatrix", b = "missing"),
34 :     function(a, b, ...) callGeneric(as(a, "dgeMatrix")))
35 :    
36 :     setMethod("solve", signature(a = "ddenseMatrix", b = "ANY"),
37 :     function(a, b, ...) callGeneric(as(a, "dgeMatrix"), b))
38 :    
39 :     setMethod("lu", signature(x = "ddenseMatrix"),
40 :     function(x, ...) callGeneric(as(x, "dgeMatrix")))
41 :    
42 : maechler 856 setMethod("determinant", signature(x = "ddenseMatrix", logarithm = "missing"),
43 : bates 686 function(x, logarithm, ...) callGeneric(as(x, "dgeMatrix")))
44 :    
45 : maechler 856 setMethod("determinant", signature(x = "ddenseMatrix", logarithm = "logical"),
46 : bates 686 function(x, logarithm, ...)
47 :     callGeneric(as(x, "dgeMatrix"), logarithm))
48 :    
49 :     setMethod("expm", signature(x = "ddenseMatrix"),
50 :     function(x) callGeneric(as(x, "dgeMatrix")))
51 :    
52 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "missing"),
53 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix")))
54 :    
55 :     setMethod("Schur", signature(x = "ddenseMatrix", vectors = "logical"),
56 :     function(x, vectors, ...) callGeneric(as(x, "dgeMatrix"), vectors))
57 :    
58 : maechler 792
59 : maechler 908 ### NAMESPACE must export this -- also only for R version 2.2.x:
60 :     if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {
61 :     ## for R 2.2.x (and later):
62 :    
63 :     setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),
64 :     function(x, y) {
65 :     d <- dim(x); nr <- d[1]; nc <- d[2]
66 :     y <- rep(y, length.out = nr)# 'silent procrustes'
67 :     ## beware of (packed) triangular, symmetric, ...
68 :     x <- as(x, "dgeMatrix")
69 :     x@x <- c(x@x, as.double(y))
70 :     x@Dim[2] <- nc + 1:1
71 :     if(is.character(dn <- x@Dimnames[[2]]))
72 :     x@Dimnames[[2]] <- c(dn, "")
73 :     x
74 :     })
75 :     ## the same, (x,y) <-> (y,x):
76 :     setMethod("cbind2", signature(x = "numeric", y = "ddenseMatrix"),
77 :     function(x, y) {
78 :     d <- dim(y); nr <- d[1]; nc <- d[2]
79 :     x <- rep(x, length.out = nr)
80 :     y <- as(y, "dgeMatrix")
81 :     y@x <- c(as.double(x), y@x)
82 :     y@Dim[2] <- nc + 1:1
83 :     if(is.character(dn <- y@Dimnames[[2]]))
84 :     y@Dimnames[[2]] <- c("", dn)
85 :     y
86 :     })
87 :    
88 :     setMethod("cbind2", signature(x = "ddenseMatrix", y = "matrix"),
89 :     function(x, y) callGeneric(x, as(y, "dgeMatrix")))
90 :     setMethod("cbind2", signature(x = "matrix", y = "ddenseMatrix"),
91 :     function(x, y) callGeneric(as(x, "dgeMatrix"), y))
92 :    
93 :     setMethod("cbind2", signature(x = "ddenseMatrix", y = "ddenseMatrix"),
94 :     function(x, y) {
95 :     nr <- rowCheck(x,y)
96 :     ncx <- x@Dim[2]
97 :     ncy <- y@Dim[2]
98 :     ## beware of (packed) triangular, symmetric, ...
99 :     hasDN <- !is.null(dnx <- dimnames(x)) |
100 :     !is.null(dny <- dimnames(y))
101 :     x <- as(x, "dgeMatrix")
102 :     y <- as(y, "dgeMatrix")
103 :     x@x <- c(x@x, y@x)
104 :     x@Dim[2] <- ncx + ncy
105 :     if(hasDN) {
106 :     ## R and S+ are different in which names they take
107 :     ## if they differ -- but there's no warning in any case
108 :     rn <- if(!is.null(dnx[[1]])) dnx[[1]] else dny[[1]]
109 :     cx <- dnx[[2]] ; cy <- dny[[2]]
110 :     cn <- if(is.null(cx) && is.null(cy)) NULL
111 :     else c(if(!is.null(cx)) cx else rep.int("", ncx),
112 :     if(!is.null(cy)) cy else rep.int("", ncy))
113 :     x@Dimnames <- list(rn, cn)
114 :     }
115 :     x
116 :     })
117 :    
118 :    
119 :     }## 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