SCM

SCM Repository

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

Diff of /pkg/Matrix/R/ddenseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 954, Wed Sep 28 19:34:31 2005 UTC revision 1453, Sun Aug 27 16:16:35 2006 UTC
# Line 1  Line 1 
1  ### Define Methods that can be inherited for all subclasses  ### Define Methods that can be inherited for all subclasses
2    
3    ## This replaces many "d..Matrix" -> "dgeMatrix" ones
4    ## >> but << needs all sub(sub(sub)) classes of "ddenseMatrix" listed
5    ##   -----  in  ../src/Mutils.c
6    setAs("ddenseMatrix", "dgeMatrix",
7          function(from) .Call(dup_mMatrix_as_dgeMatrix, from))
8    
9    ## d(ouble) to l(ogical):
10    setAs("dgeMatrix", "lgeMatrix", d2l_Matrix)
11    setAs("dtrMatrix", "ltrMatrix", d2l_Matrix)
12    setAs("dtpMatrix", "ltpMatrix", d2l_Matrix)
13    setAs("dsyMatrix", "lsyMatrix", d2l_Matrix)
14    setAs("dspMatrix", "lspMatrix", d2l_Matrix)
15    
16    setMethod("as.numeric", signature(x = "ddenseMatrix"),
17              function(x, ...) as(x, "dgeMatrix")@x)
18    
19  ## -- see also ./Matrix.R  e.g., for a show() method  ## -- see also ./Matrix.R  e.g., for a show() method
20    
21  ## These methods are the 'fallback' methods for all dense numeric  ## These methods are the 'fallback' methods for all dense numeric
# Line 22  Line 38 
38  ## setMethod("t", signature(x = "ddenseMatrix"),  ## setMethod("t", signature(x = "ddenseMatrix"),
39  ##        function(x) callGeneric(as(x, "dgeMatrix")))  ##        function(x) callGeneric(as(x, "dgeMatrix")))
40    
41  setMethod("tcrossprod", signature(x = "ddenseMatrix"),  setMethod("tcrossprod", signature(x = "ddenseMatrix", y = "missing"),
42            function(x) callGeneric(as(x, "dgeMatrix")))            function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))
43    
44  setMethod("crossprod", signature(x = "ddenseMatrix", y = "missing"),  setMethod("crossprod", signature(x = "ddenseMatrix", y = "missing"),
45            function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))            function(x, y = NULL) callGeneric(as(x, "dgeMatrix")))
# Line 58  Line 74 
74            function(x, vectors, ...) callGeneric(as(x, "dgeMatrix"), vectors))            function(x, vectors, ...) callGeneric(as(x, "dgeMatrix"), vectors))
75    
76    
77  ### NAMESPACE must export this -- also only for R version 2.2.x:  ## Cheap version: work via "dgeMatrix" and use the group methods there:
78  if(paste(R.version$major, R.version$minor, sep=".") >= "2.2") {  ## FIXME(?): try to preserve "symmetric", "triangular", ...
79      ## for R 2.2.x (and later):  setMethod("Arith", ##  "+", "-", "*", "^", "%%", "%/%", "/"
80              signature(e1 = "ddenseMatrix", e2 = "ddenseMatrix"),
81              function(e1, e2) callGeneric(as(e1, "dgeMatrix"),
82                                           as(e2, "dgeMatrix")))
83    setMethod("Arith",
84              signature(e1 = "ddenseMatrix", e2 = "numeric"),
85              function(e1, e2) callGeneric(as(e1, "dgeMatrix"), e2))
86    setMethod("Arith",
87              signature(e1 = "numeric", e2 = "ddenseMatrix"),
88              function(e1, e2) callGeneric(e1, as(e2, "dgeMatrix")))
89    
90    setMethod("Math",
91              signature(x = "ddenseMatrix"),
92              function(x) callGeneric(as(x, "dgeMatrix")))
93    
94    
95    
96    ### for R 2.2.x (and later): -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
97    
98  ### cbind2  ### cbind2
99      setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),      setMethod("cbind2", signature(x = "ddenseMatrix", y = "numeric"),
# Line 162  Line 195 
195                    new("dgeMatrix", Dim = c(nrx + nry, nc), Dimnames = dn,                    new("dgeMatrix", Dim = c(nrx + nry, nc), Dimnames = dn,
196                        x = c(rbind2(as(x,"matrix"), as(y,"matrix"))))                        x = c(rbind2(as(x,"matrix"), as(y,"matrix"))))
197                })                })
198    ## NB: have extra tril(), triu() methods for symmetric ["dsy" and "dsp"] and
199  }## R-2.2.x ff  ##     for triangular ["dtr" and "dtp"]
200    setMethod("tril", "ddenseMatrix",
201              function(x, k = 0, ...) {
202                  k <- as.integer(k[1])
203                  dd <- dim(x); sqr <- dd[1] == dd[2]
204                  stopifnot(-dd[1] <= k, k <= dd[1]) # had k <= 0
205                  ## returns "lower triangular" if k <= 0 && sqr
206                  .Call(ddense_band, x, -dd[1], k)
207              })
208    
209    setMethod("triu", "ddenseMatrix",
210              function(x, k = 0, ...) {
211                  k <- as.integer(k[1])
212                  dd <- dim(x); sqr <- dd[1] == dd[2]
213                  stopifnot(-dd[1] <= k, k <= dd[1]) # had k >= 0
214                  ## returns "upper triangular" if k >= 0
215                  .Call(ddense_band, x, k, dd[2])
216              })
217    
218    setMethod("band", "ddenseMatrix",
219              function(x, k1, k2, ...) {
220                  k1 <- as.integer(k1[1])
221                  k2 <- as.integer(k2[1])
222                  dd <- dim(x); sqr <- dd[1] == dd[2]
223                  stopifnot(-dd[1] <= k1, k1 <= k2, k2 <= dd[1])
224                  r <- .Call(ddense_band, x, k1, k2)
225                  if (k1 < 0  &&  k1 == -k2  && isSymmetric(x)) ## symmetric
226                      as(r, paste(.M.kind(x), "syMatrix", sep=''))
227                  else
228                      r
229              })

Legend:
Removed from v.954  
changed lines
  Added in v.1453

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