SCM

SCM Repository

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

Annotation of /pkg/R/lsCMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1665 - (view) (download)

1 : bates 723 #### Logical Symmetric Sparse Matrices in Compressed column-oriented format
2 :    
3 :     ### contains = "lsparseMatrix"
4 :    
5 : maechler 946 setAs("lsCMatrix", "matrix",
6 :     function(from) as(as(from, "lgCMatrix"), "matrix"))
7 :    
8 :     setAs("lsCMatrix", "lgCMatrix",
9 : maechler 1375 function(from) .Call(Csparse_symmetric_to_general, from))
10 : maechler 946
11 : maechler 1665 ## for indexing
12 :     setAs("lsCMatrix", "lgTMatrix",
13 :     function(from) as(as(from, "lgCMatrix"), "lgTMatrix"))
14 :    
15 : maechler 1599 setAs("lgCMatrix", "lsCMatrix",
16 : maechler 1618 function(from) .Call(Csparse_general_to_symmetric, from, uplo = "U"))
17 :     ## now use it:
18 :     aslsC.by.lgC <- function(from) as(as(from, "lgCMatrix"), "lsCMatrix")
19 :     setAs("lgTMatrix", "lsCMatrix", aslsC.by.lgC) # <-> needed for Matrix()
20 :     setAs("matrix", "lsCMatrix", aslsC.by.lgC)
21 : maechler 1599
22 : bates 1366 ## Specific conversions, should they be necessary. Better to convert as
23 :     ## as(x, "TsparseMatrix") or as(x, "denseMatrix")
24 : maechler 946 setAs("lsCMatrix", "lsTMatrix",
25 : bates 1366 function(from) .Call(Csparse_to_Tsparse, from, FALSE))
26 : maechler 946
27 : bates 723 setAs("lsCMatrix", "dsCMatrix",
28 :     function(from) new("dsCMatrix", i = from@i, p = from@p,
29 : maechler 1571 x = as.double(from@x), uplo = from@uplo,
30 : bates 723 Dim = from@Dim, Dimnames = from@Dimnames))
31 : bates 729
32 : maechler 946 setAs("lsCMatrix", "dgTMatrix",
33 : maechler 1201 function(from) as(as(x, "dsCMatrix"), "dgTMatrix"))
34 : maechler 946
35 : maechler 1331 ## have rather tril() and triu() methods than
36 :     ## setAs("lsCMatrix", "ltCMatrix", ....)
37 :     setMethod("tril", "lsCMatrix",
38 :     function(x, k = 0, ...) {
39 :     if(x@uplo == "L" && k == 0)
40 :     ## same internal structure (speedup potential !?)
41 :     new("ltCMatrix", uplo = x@uplo, i = x@i, p = x@p,
42 :     Dim = x@Dim, Dimnames = x@Dimnames)
43 :     else tril(as(x, "lgCMatrix"), k = k, ...)
44 :     })
45 :     setMethod("triu", "lsCMatrix",
46 :     function(x, k = 0, ...) {
47 :     if(x@uplo == "U" && k == 0)
48 :     ## same internal structure (speedup potential !?)
49 :     new("ltCMatrix", uplo = x@uplo, i = x@i, p = x@p,
50 :     Dim = x@Dim, Dimnames = x@Dimnames)
51 :     else triu(as(x, "lgCMatrix"), k = k, ...)
52 :     })
53 :    
54 : maechler 1189 ## FIXME: generalize to "lsparseMatrix" or (class union) "symmetric sparse"
55 : bates 729 setMethod("image", "lsCMatrix",
56 :     function(x, ...) {
57 :     x <- as(as(x, "dsCMatrix"), "dgTMatrix")
58 :     callGeneric()
59 :     })
60 :    
61 :     setMethod("chol", signature(x = "lsCMatrix", pivot = "missing"),
62 : maechler 1571 function(x, pivot, ...) chol(as(x, "dgCMatrix"), pivot = FALSE))
63 :     ## .Call(lsCMatrix_chol, x, FALSE))
64 : bates 729
65 :     setMethod("chol", signature(x = "lsCMatrix", pivot = "logical"),
66 : maechler 1571 function(x, pivot, ...) chol(as(x, "dgCMatrix"), pivot = pivot))
67 :     ## .Call(lsCMatrix_chol, x, pivot))
68 : bates 729
69 : bates 1448 ## Use more general method from CsparseMatrix class
70 :     ## setMethod("t", signature(x = "lsCMatrix"),
71 :     ## function(x)
72 :     ## .Call(lsCMatrix_trans, x),
73 :     ## valueClass = "lsCMatrix")

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