SCM

SCM Repository

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

Annotation of /pkg/R/lsparseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2005 - (view) (download)

1 : maechler 892 #### Superclass Methods for all sparse logical matrices
2 :    
3 : maechler 1767 if(FALSE) ## bug? in 'methods' - see ./nsparseMatrix.R :
4 : maechler 1376 setAs("CsparseMatrix", "lsparseMatrix",
5 : maechler 1548 function(from) as(.Call(Csparse_to_nz_pattern, from,
6 :     is(from, "triangularMatrix")), "lsparseMatrix"))
7 : maechler 1767 ## substitute:
8 :     setAs("CsparseMatrix", "lsparseMatrix",
9 :     function(from) {
10 :     cld <- getClassDef(class(from))
11 :     if(extends(cld, "lsparseMatrix"))
12 :     from
13 :     else if(extends(cld, "nsparseMatrix"))
14 :     as(from, "lsparseMatrix")
15 :     else
16 :     as(.Call(Csparse_to_nz_pattern, from,
17 :     extends(cld, "triangularMatrix")),
18 :     "lsparseMatrix")
19 :     })
20 : maechler 1376
21 : maechler 1767
22 : maechler 1548 setAs("lsparseMatrix", "matrix",
23 :     function(from) as(as(from, "ldenseMatrix"), "matrix"))
24 : maechler 1376
25 : maechler 1548
26 : maechler 892 ###------- Work via as(*, lgC) : ------------
27 :    
28 : maechler 925 ## For multiplication operations, sparseMatrix overrides other method
29 :     ## selections. Coerce a ddensematrix argument to a lsparseMatrix.
30 : maechler 892
31 : maechler 925 setMethod("%*%", signature(x = "lsparseMatrix", y = "ldenseMatrix"),
32 :     function(x, y) callGeneric(x, as(y, "lsparseMatrix")))
33 : maechler 892
34 : maechler 925 setMethod("%*%", signature(x = "ldenseMatrix", y = "lsparseMatrix"),
35 :     function(x, y) callGeneric(as(x, "lsparseMatrix"), y))
36 : maechler 892
37 : maechler 925 setMethod("crossprod", signature(x = "lsparseMatrix", y = "ldenseMatrix"),
38 :     function(x, y = NULL) callGeneric(x, as(y, "lsparseMatrix")))
39 :    
40 :     setMethod("crossprod", signature(x = "ldenseMatrix", y = "lsparseMatrix"),
41 :     function(x, y = NULL) callGeneric(as(x, "lsparseMatrix"), y))
42 :    
43 :     ## and coerce lsparse* to lgC*
44 :     setMethod("%*%", signature(x = "lsparseMatrix", y = "lsparseMatrix"),
45 :     function(x, y) callGeneric(as(x, "lgCMatrix"), as(y, "lgCMatrix")))
46 :    
47 :     setMethod("crossprod", signature(x = "lsparseMatrix", y = "lsparseMatrix"),
48 :     function(x, y = NULL)
49 :     callGeneric(as(x, "lgCMatrix"), as(y, "lgCMatrix")))
50 :    
51 : maechler 954
52 : maechler 1705 setMethod("all", signature(x = "lsparseMatrix"),
53 : maechler 2005 function(x, ..., na.rm = FALSE) {
54 :     d <- x@Dim
55 :     l.x <- length(x@x)
56 :     if(l.x == prod(d)) ## fully non-zero
57 :     all(x@x, ..., na.rm = na.rm)
58 :     else if(is(x, "symmetricMatrix") && l.x == choose(d[1]+1, 2)) {
59 :     if(.Generic %in% summGener1)
60 :     all(x@x, ..., na.rm = na.rm)
61 :     else all(as(x, "generalMatrix")@x, ..., na.rm = na.rm)
62 :     }
63 :     else FALSE ## has at least one structural 0
64 :     })
65 : maechler 1705
66 : maechler 2005 ## setMethod("any", ) ---> ./lMatrix.R

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