SCM

SCM Repository

[matrix] Diff of /pkg/R/sparseMatrix.R
ViewVC logotype

Diff of /pkg/R/sparseMatrix.R

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

revision 867, Fri Aug 19 16:59:46 2005 UTC revision 868, Fri Aug 19 17:01:11 2005 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    ## An idea: Coercion between *VIRTUAL* classes
4    ## -- making sure that result is *actual*!
5    
6    ## setAs("denseMatrix", "sparseMatrix",
7    ##       function(from) {
8    ##       })
9    
10    ## setAs("dMatrix", "lMatrix",
11    ##       function(from) {
12    ##       })
13    
14    
15  ## For multiplication operations, sparseMatrix overrides other method  ## For multiplication operations, sparseMatrix overrides other method
16  ## selections.  Coerce a ddensematrix argument to a dgeMatrix.  ## selections.  Coerce a ddensematrix argument to a dgeMatrix.
17    
# Line 23  Line 35 
35        })        })
36    
37    
38  setMethod("[", signature(x = "dsparseMatrix",  ### Subsetting -- basic things (drop = "missing") are done in ./Matrix.R
                          i = "missing", j = "missing", drop = "ANY"), ## "x[]"  
           function (x, i, j, drop) x)  
39    
40    ## 1)  dsparse -> dgT
41  setMethod("[", signature(x = "dsparseMatrix", i = "numeric", j = "missing",  setMethod("[", signature(x = "dsparseMatrix", i = "numeric", j = "missing",
42                           drop = "logical"),                           drop = "logical"),
43            function (x, i, j, drop)            function (x, i, j, drop)
# Line 37  Line 48 
48            function (x, i, j, drop)            function (x, i, j, drop)
49            callGeneric(x = as(x, "dgTMatrix"), j=j, drop=drop))            callGeneric(x = as(x, "dgTMatrix"), j=j, drop=drop))
50    
 setMethod("[", signature(x = "dsparseMatrix", i = "numeric", j = "missing",  
                          drop = "missing"),  
           function(x,i,j, drop) callGeneric(x, i=i, drop= TRUE))  
   
 setMethod("[", signature(x = "dsparseMatrix", i = "missing", j = "numeric",  
                          drop = "missing"),  
           function(x,i,j, drop) callGeneric(x, j=j, drop= TRUE))  
   
51  setMethod("[", signature(x = "dsparseMatrix",  setMethod("[", signature(x = "dsparseMatrix",
52                           i = "numeric", j = "numeric", drop = "logical"),                           i = "numeric", j = "numeric", drop = "logical"),
53            function (x, i, j, drop)            function (x, i, j, drop)
54            callGeneric(x = as(x, "dgTMatrix"), i=i, j=j, drop=drop))            callGeneric(x = as(x, "dgTMatrix"), i=i, j=j, drop=drop))
55    
56  setMethod("[", signature(x = "dsparseMatrix",  ## 2)  lsparse -> lgT
57                           i = "numeric", j = "numeric", drop = "missing"),  setMethod("[", signature(x = "lsparseMatrix", i = "numeric", j = "missing",
58            function(x,i,j, drop) callGeneric(x, i=i, j=j, drop= TRUE))                           drop = "logical"),
59              function (x, i, j, drop)
60              callGeneric(x = as(x, "lgTMatrix"), i=i, drop=drop))
61    
62    setMethod("[", signature(x = "lsparseMatrix", i = "missing", j = "numeric",
63                             drop = "logical"),
64              function (x, i, j, drop)
65              callGeneric(x = as(x, "lgTMatrix"), j=j, drop=drop))
66    
67    setMethod("[", signature(x = "lsparseMatrix",
68                             i = "numeric", j = "numeric", drop = "logical"),
69              function (x, i, j, drop)
70              callGeneric(x = as(x, "lgTMatrix"), i=i, j=j, drop=drop))
71    
72    
73    
74    
75  ### --- show() method ---  ### --- show() method ---
76    
# Line 78  Line 96 
96          zero.print <- if(zero.print) "0" else " "          zero.print <- if(zero.print) "0" else " "
97      ## FIXME: show only "structural" zeros as 'zero.print', not all of them..      ## FIXME: show only "structural" zeros as 'zero.print', not all of them..
98      x[m == 0.] <- zero.print      x[m == 0.] <- zero.print
99        if(is(object,"lsparseMatrix"))
100            x[m] <- "|"
101      print(noquote(x))      print(noquote(x))
102      invisible(object)      invisible(object)
103  }  }

Legend:
Removed from v.867  
changed lines
  Added in v.868

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge