# SCM Repository

[matrix] Diff of /pkg/R/SparseM-conv.R
 [matrix] / pkg / R / SparseM-conv.R

# Diff of /pkg/R/SparseM-conv.R

revision 1764, Mon Feb 5 08:14:19 2007 UTC revision 1765, Mon Feb 5 16:32:04 2007 UTC
# Line 16  Line 16
16        })        })
17
18

19  setAs("matrix.csc", "dgCMatrix",  setAs("matrix.csc", "dgCMatrix",
20        function(from) {        function(from) {
21            new("dgCMatrix",            new("dgCMatrix",
# Line 25  Line 24
24        })        })
25  setAs( "dgCMatrix", "matrix.csc",  setAs( "dgCMatrix", "matrix.csc",
26        function(from) {        function(from) {
27            new("dgCMatrix",            new("matrix.csc",
28                ra = from@x, ja = from@i + 1:1, ia = from@p + 1:1,                ra = from@x, ja = from@i + 1:1, ia = from@p + 1:1,
29                Dim = from@dimension)                dimension = from@Dim)
30        })        })
31
32  setAs("matrix.coo", "dgTMatrix",  setAs("matrix.coo", "dgTMatrix",
# Line 38  Line 37
37        })        })
38  setAs("dgTMatrix", "matrix.coo",  setAs("dgTMatrix", "matrix.coo",
39        function(from) {        function(from) {
40            new("dgTMatrix",            new("matrix.coo",
41                ra = from@x, ia = from@i + 1:1, ja = from@j + 1:1,                ra = from@x, ia = from@i + 1:1, ja = from@j + 1:1,
42                Dim = from@dimension)                dimension = from@Dim)
43        })        })
44
45  ### II.  Enable coercion to the ``favorite'' of each package;  ### II.  Enable coercion to the ``favorite'' of each package;
# Line 48  Line 47
47  ###      i.e.,  "dgCMatrix" and  "matrix.csr"  ###      i.e.,  "dgCMatrix" and  "matrix.csr"
48
49  setAs("dsparseMatrix", "matrix.csr",  setAs("dsparseMatrix", "matrix.csr",
50        function(from) as(as(from, "dgRMatrix"), "matrix.csr"))        function(from) as(as(as(from, "RsparseMatrix"), "dgRMatrix"), "matrix.csr"))
51
52  ##  ##
53  setAs("matrix.csr", "dgCMatrix",  setAs("matrix.csr", "dgCMatrix",
# Line 56  Line 55
55  setAs("matrix.coo", "dgCMatrix",  setAs("matrix.coo", "dgCMatrix",
56        function(from) as(as(from, "dgTMatrix"), "dgCMatrix"))        function(from) as(as(from, "dgTMatrix"), "dgCMatrix"))
57
58  ## Easy coercion: just always use as( <SparseM.mat>, "Matrix") :  ### also define the virtual coercions that we (should) advertize:
59    setAs("matrix.csr", "RsparseMatrix", function(from) as(from, "dgRMatrix"))
60  setAs("matrix.csr", "Matrix", function(from) as(from, "dgCMatrix")) # we favor 'dgC' so much ..  setAs("matrix.csc", "CsparseMatrix", function(from) as(from, "dgCMatrix"))
61  setAs("matrix.coo", "Matrix", function(from) as(from, "dgTMatrix"))  setAs("matrix.coo", "TsparseMatrix", function(from) as(from, "dgTMatrix"))
62  setAs("matrix.csc", "Matrix", function(from) as(from, "dgCMatrix"))  ## to "Csparse*" and "Tsparse*" should work for all sparse:
63    setAs("matrix.csr", "CsparseMatrix",
64          function(from) as(as(from, "dgRMatrix"), "CsparseMatrix"))
65    setAs("matrix.coo", "CsparseMatrix",
66          function(from) as(as(from, "dgTMatrix"), "CsparseMatrix"))
67    setAs("matrix.csc", "TsparseMatrix",
68          function(from) as(as(from, "dgCMatrix"), "TsparseMatrix"))
69    setAs("matrix.csr", "TsparseMatrix",
70          function(from) as(as(from, "dgRMatrix"), "TsparseMatrix"))
71    ## Also *from* (our favorite) Csparse should work to all 3 SparseM
72    setAs("CsparseMatrix", "matrix.csr",
73          function(from) as(as(from, "RsparseMatrix"), "matrix.csr"))
74    setAs("CsparseMatrix", "matrix.coo",
75          function(from) as(as(from, "TsparseMatrix"), "matrix.coo"))
76    setAs("CsparseMatrix", "matrix.csc",
77          function(from) as(as(from, "dgCMatrix"), "TsparseMatrix"))
78
79    ## Easy coercion: just always use as( <SparseM.mat>, "Matrix") :
80
81    setAs("matrix.csr", "Matrix", function(from) as(from, "CsparseMatrix")) # we favor!
82    setAs("matrix.coo", "Matrix", function(from) as(from, "TsparseMatrix"))
83    setAs("matrix.csc", "Matrix", function(from) as(from, "CsparseMatrix"))

Legend:
 Removed from v.1764 changed lines Added in v.1765