SCM

SCM Repository

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

Annotation of /pkg/R/Rsparse.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1599 - (view) (download)
Original Path: pkg/R/dgRMatrix.R

1 : bates 677 #### Sparse Matrices in Compressed row-oriented format
2 : maechler 1599 #### --- "R"
3 : bates 677
4 :     ### contains = "dMatrix"
5 :    
6 :     setAs("dgRMatrix", "dgTMatrix",
7 : maechler 1280 function(from) .Call(compressed_to_dgTMatrix, from, FALSE))
8 : bates 677
9 : maechler 1329 ### FIXME: Activate the following with "little" change in ../src/dgCMatrix.c
10 :     ### ----- similar to compressed_to_dgTMatrix above ~~~~~~~~~~~~~~~~~~
11 :    
12 : bates 677 ##setAs("dgRMatrix", "matrix",
13 : maechler 1280 ## function(from) .Call(csc_to_matrix, from))
14 : maechler 1332 ## easy "cheap" alternative:
15 :     setAs("dgRMatrix", "matrix",
16 :     function(from) as(as(from, "dgTMatrix"), "matrix"))
17 : bates 677
18 :     ##setAs("dgRMatrix", "dgeMatrix",
19 : maechler 1280 ## function(from) .Call(csc_to_dgeMatrix, from))
20 : bates 677
21 :     ##setAs("matrix", "dgRMatrix",
22 :     ## function(from) {
23 :     ## storage.mode(from) <- "double"
24 : maechler 1280 ## .Call(matrix_to_csc, from)
25 : bates 677 ## })
26 :    
27 : maechler 1332
28 : bates 677 ##setMethod("diag", signature(x = "dgRMatrix"),
29 : maechler 1280 ## function(x = 1, nrow, ncol = n) .Call(csc_getDiag, x))
30 : bates 677
31 : maechler 1329 setAs("dgRMatrix", "dgCMatrix",
32 :     function(from) as(as(from, "dgTMatrix"), "dgCMatrix"))
33 :    
34 : maechler 1332 ## **VERY** cheap substitutes: work via dgC and t(.)
35 :     .to.dgR <- function(from) {
36 :     m <- as(t(from), "dgCMatrix")
37 :     new("dgRMatrix", Dim = dim(from), Dimnames = .M.DN(from),
38 :     p = m@p, j = m@i, x = m@x)
39 :     }
40 :    
41 :     setAs("matrix", "dgRMatrix", .to.dgR)
42 :     setAs("dgCMatrix", "dgRMatrix", .to.dgR)
43 :     setAs("dgTMatrix", "dgRMatrix", .to.dgR)
44 :    
45 :    
46 :    
47 :     ##setAs("dgRMatrix", "dgeMatrix",
48 :     ## function(from) .Call(csc_to_dgeMatrix, from))
49 :    
50 :     ##setAs("matrix", "dgRMatrix",
51 :     ## function(from) {
52 :     ## storage.mode(from) <- "double"
53 :     ## .Call(matrix_to_csc, from)
54 :     ## })
55 :    
56 :    
57 : maechler 1189 ## try to define for "Matrix" -- once and for all -- but that fails -- why? __ FIXME __
58 :     ## setMethod("dim", signature(x = "dgRMatrix"),
59 :     ## function(x) x@Dim, valueClass = "integer")
60 : bates 677
61 :     ##setMethod("t", signature(x = "dgRMatrix"),
62 : maechler 1280 ## function(x) .Call(csc_transpose, x),
63 : bates 677 ## valueClass = "dgRMatrix")
64 :    
65 :     setMethod("image", "dgRMatrix",
66 :     function(x, ...) {
67 : maechler 1189 x <- as(x, "dgTMatrix")
68 : bates 677 callGeneric()
69 :     })
70 : maechler 1349
71 :    
72 :     ## Want tril(), triu(), band() --- just as "indexing" ---
73 :     ## return a "close" class:
74 :     setMethod("tril", "RsparseMatrix",
75 :     function(x, k = 0, ...) as_Rsparse(tril(as_Csparse(x), k = k, ...)))
76 :     setMethod("triu", "RsparseMatrix",
77 :     function(x, k = 0, ...) as_Rsparse(triu(as_Csparse(x), k = k, ...)))
78 :     setMethod("band", "RsparseMatrix",
79 :     function(x, k1, k2, ...)
80 :     as_Rsparse(band(as_Csparse(x), k1 = k1, k2 = k2, ...)))

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